No require password if register via social auth
This commit is contained in:
parent
9fd93a3b53
commit
2ff1ed0f54
8 changed files with 410 additions and 353 deletions
|
@ -61,6 +61,7 @@ from judge.views import (
|
||||||
course,
|
course,
|
||||||
email,
|
email,
|
||||||
)
|
)
|
||||||
|
from judge import authentication
|
||||||
|
|
||||||
from judge.views.test_formatter import test_formatter
|
from judge.views.test_formatter import test_formatter
|
||||||
|
|
||||||
|
@ -139,9 +140,7 @@ register_patterns = [
|
||||||
url(r"^logout/$", user.UserLogoutView.as_view(), name="auth_logout"),
|
url(r"^logout/$", user.UserLogoutView.as_view(), name="auth_logout"),
|
||||||
url(
|
url(
|
||||||
r"^password/change/$",
|
r"^password/change/$",
|
||||||
auth_views.PasswordChangeView.as_view(
|
authentication.CustomPasswordChangeView.as_view(),
|
||||||
template_name="registration/password_change_form.html",
|
|
||||||
),
|
|
||||||
name="password_change",
|
name="password_change",
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
from django.contrib.auth.backends import ModelBackend
|
from django.contrib.auth.backends import ModelBackend
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.contrib.auth.forms import PasswordChangeForm
|
||||||
|
from django.contrib.auth.views import PasswordChangeView
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
|
|
||||||
class CustomModelBackend(ModelBackend):
|
class CustomModelBackend(ModelBackend):
|
||||||
|
@ -13,3 +16,32 @@ class CustomModelBackend(ModelBackend):
|
||||||
|
|
||||||
if user and user.check_password(password):
|
if user and user.check_password(password):
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
class CustomPasswordChangeForm(PasswordChangeForm):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(CustomPasswordChangeForm, self).__init__(*args, **kwargs)
|
||||||
|
if not self.user.has_usable_password():
|
||||||
|
self.fields.pop("old_password")
|
||||||
|
|
||||||
|
def clean_old_password(self):
|
||||||
|
if "old_password" not in self.cleaned_data:
|
||||||
|
return
|
||||||
|
return super(CustomPasswordChangeForm, self).clean_old_password()
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super(CustomPasswordChangeForm, self).clean()
|
||||||
|
if "old_password" not in self.cleaned_data and not self.errors:
|
||||||
|
cleaned_data["old_password"] = ""
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
|
class CustomPasswordChangeView(PasswordChangeView):
|
||||||
|
form_class = CustomPasswordChangeForm
|
||||||
|
success_url = reverse_lazy("password_change_done")
|
||||||
|
template_name = "registration/password_change_form.html"
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super(CustomPasswordChangeView, self).get_form_kwargs()
|
||||||
|
kwargs["user"] = self.request.user
|
||||||
|
return kwargs
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.db import transaction
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
from reversion import revisions
|
from reversion import revisions
|
||||||
from social_core.backends.github import GithubOAuth2
|
from social_core.backends.github import GithubOAuth2
|
||||||
|
@ -65,13 +66,13 @@ class UsernameForm(forms.Form):
|
||||||
max_length=30,
|
max_length=30,
|
||||||
label="Username",
|
label="Username",
|
||||||
error_messages={
|
error_messages={
|
||||||
"invalid": "A username must contain letters, numbers, or underscores"
|
"invalid": _("A username must contain letters, numbers, or underscores")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def clean_username(self):
|
def clean_username(self):
|
||||||
if User.objects.filter(username=self.cleaned_data["username"]).exists():
|
if User.objects.filter(username=self.cleaned_data["username"]).exists():
|
||||||
raise forms.ValidationError("Sorry, the username is taken.")
|
raise forms.ValidationError(_("Sorry, the username is taken."))
|
||||||
return self.cleaned_data["username"]
|
return self.cleaned_data["username"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ def choose_username(backend, user, username=None, *args, **kwargs):
|
||||||
request,
|
request,
|
||||||
"registration/username_select.html",
|
"registration/username_select.html",
|
||||||
{
|
{
|
||||||
"title": "Choose a username",
|
"title": _("Choose a username"),
|
||||||
"form": form,
|
"form": form,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -118,7 +119,7 @@ def make_profile(backend, user, response, is_new=False, *args, **kwargs):
|
||||||
backend.strategy.request,
|
backend.strategy.request,
|
||||||
"registration/profile_creation.html",
|
"registration/profile_creation.html",
|
||||||
{
|
{
|
||||||
"title": "Create your profile",
|
"title": _("Create your profile"),
|
||||||
"form": form,
|
"form": form,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,9 +39,6 @@ msgstr "Đăng ký tên"
|
||||||
msgid "Report"
|
msgid "Report"
|
||||||
msgstr "Báo cáo tiêu cực"
|
msgstr "Báo cáo tiêu cực"
|
||||||
|
|
||||||
msgid "Bug Report"
|
|
||||||
msgstr "Báo cáo lỗi"
|
|
||||||
|
|
||||||
msgid "2sat"
|
msgid "2sat"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -597,6 +594,9 @@ msgstr ""
|
||||||
msgid "z-function"
|
msgid "z-function"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#~ msgid "Bug Report"
|
||||||
|
#~ msgstr "Báo cáo lỗi"
|
||||||
|
|
||||||
#~ msgid "Insert Image"
|
#~ msgid "Insert Image"
|
||||||
#~ msgstr "Chèn hình ảnh"
|
#~ msgstr "Chèn hình ảnh"
|
||||||
|
|
||||||
|
|
|
@ -417,6 +417,11 @@ function onWindowReady() {
|
||||||
$(this).hide().css({ width: 0});
|
$(this).hide().css({ width: 0});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.errorlist').each(function() {
|
||||||
|
var errorList = $(this);
|
||||||
|
errorList.nextAll('input, select, textarea').first().after(errorList);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
|
@ -611,6 +611,7 @@ ul.errorlist {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
color: red;
|
color: red;
|
||||||
|
margin-bottom: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.registration-form {
|
.registration-form {
|
||||||
|
|
|
@ -30,11 +30,13 @@
|
||||||
{% block js_media %}{{ form.media.js }}{% endblock %}
|
{% block js_media %}{{ form.media.js }}{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<div id="center-float" class="registration-form">
|
||||||
<form action="" method="post" class="form-area">
|
<form action="" method="post" class="form-area">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<table border="0" style="text-align:left">{{ form.as_table() }}</table>
|
<table border="0" style="text-align:left">{{ form.as_table() }}</table>
|
||||||
<input type="submit" style="float:right;" value="{{ _('Continue >') }}">
|
<input type="submit" style="float:right;" value="{{ _('Continue >') }}">
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="map-wrap">
|
<div class="map-wrap">
|
||||||
<div class="map-inset">
|
<div class="map-inset">
|
||||||
|
|
Loading…
Reference in a new issue