-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
212 password change #254
212 password change #254
Changes from 10 commits
63a551b
fa8cb5d
83f273c
49a066d
04d138c
a57a4eb
d2cca0d
b6ad969
7794560
88df73f
28869e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
from django.forms import ModelForm | ||
from django import forms | ||
from django.contrib.auth.password_validation import validate_password | ||
from django.utils.translation import ugettext_lazy as _ | ||
from allauth.account.forms import LoginForm as BaseLoginForm | ||
from allauth.account.forms import SignupForm as BaseSignupForm | ||
from .models import User | ||
from .utils import key_state | ||
|
||
import requests | ||
|
||
|
||
class UpdateUserInfoForm(ModelForm): | ||
|
||
class Meta: | ||
model = User | ||
fields = [ | ||
|
@@ -21,16 +22,61 @@ class Meta: | |
"fingerprint", | ||
"server_signed", | ||
"timezone", | ||
"language", | ||
"language" | ||
] | ||
|
||
widgets = { | ||
'keyserver_url': forms.TextInput(attrs={'placeholder': _("https://example.com/key.asc")}), | ||
'public_key': forms.Textarea(attrs={'placeholder': _("-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: SKS 1.1.1\n<PGP KEY>\n-----END PGP PUBLIC KEY BLOCK-----")}) | ||
} | ||
|
||
current_password = forms.CharField(label=_('Current password'), | ||
required=False, | ||
widget=forms.PasswordInput) | ||
new_password1 = forms.CharField(label=_('New password'), | ||
required=False, | ||
widget=forms.PasswordInput) | ||
new_password2 = forms.CharField(label=_('New password confirmation'), | ||
required=False, | ||
widget=forms.PasswordInput) | ||
|
||
def __init__(self, *args, **kwargs): | ||
# Flag to let the save method know when to call set_password | ||
self.change_password = False | ||
self.pub_key = None | ||
return super().__init__(*args, **kwargs) | ||
return super(UpdateUserInfoForm, self).__init__(*args, **kwargs) | ||
|
||
def save(self, commit=True): | ||
new_password = self.cleaned_data.get('new_password2') | ||
if self.change_password: | ||
self.instance.set_password(new_password) | ||
return super(UpdateUserInfoForm, self).save(commit=commit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here super can also be changed to the new style |
||
|
||
def clean_current_password(self): | ||
""" | ||
Validates that the current_password field is correct. | ||
""" | ||
current_password = self.cleaned_data.get('current_password') | ||
if len(current_password) > 0: | ||
if not self.instance.check_password(current_password): | ||
self.add_error('current_password', | ||
_('Your current password was entered incorrectly.')) | ||
return current_password | ||
|
||
def clean_new_password2(self): | ||
""" | ||
Validates that both new password entries are equal. | ||
""" | ||
password1 = self.cleaned_data.get('new_password1') | ||
password2 = self.cleaned_data.get('new_password2') | ||
if password1 and password2: | ||
validate_password(password1, self.instance) | ||
if password1 != password2: | ||
self.add_error('new_password2', | ||
_("The two password fields didn't match.")) | ||
else: | ||
self.change_password = True | ||
return password2 | ||
|
||
def clean_public_key(self): | ||
# Validate the public key | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,33 +5,16 @@ $(document).ready(function(){ | |
$(".label-form-b label").addClass("smallmedium text-darkest"); | ||
$(".checkbox- label").addClass("smallmedium text-darkest"); | ||
|
||
$("#tab1").click(function(){ | ||
//slide up all the link lists | ||
$("#section1").show(); | ||
$("#section2").hide(); | ||
$("#section3").hide(); | ||
$("#tab1").addClass("active"); | ||
$("#tab2").removeClass("active"); | ||
$("#tab3").removeClass("active"); | ||
}); | ||
$("#tab2").click(function(){ | ||
//slide up all the link lists | ||
$("#section2").show(); | ||
$("#section1").hide(); | ||
$("#section3").hide(); | ||
$("#tab2").addClass("active"); | ||
$("#tab1").removeClass("active"); | ||
$("#tab3").removeClass("active"); | ||
}); | ||
$("#tab3").click(function(){ | ||
//slide up all the link lists | ||
$("#section3").show(); | ||
$("#section1").hide(); | ||
$("#section2").hide(); | ||
$("#tab3").addClass("active"); | ||
$("#tab1").removeClass("active"); | ||
$("#tab2").removeClass("active"); | ||
$(".sett__nav__item").click(function(evt) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason this event is not being added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested here on Firefox and it triggers the event just fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just tested again, with different browsers and it is working fine. Not sure what was the problem the other time. |
||
var tabId = evt.target.id; | ||
var index = $(evt.target).index() + 1; | ||
|
||
$(".sett__nav__item").removeClass("active"); | ||
$(tabId).addClass("active"); | ||
$(".section").hide(); | ||
$("#section" + index).show(); | ||
}); | ||
|
||
$('.radio_button').on('change', function() { | ||
if ($('.radio_button:checked').val() == "keyserver") { | ||
$("#keyserver_url").show(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ | |
<div class="col-xs-12 nav-st no-padding text-left"> | ||
<li id="tab1" class="sett__nav__item text-darkest active">{% trans "Profile" %}</li> | ||
<li id="tab2" class="sett__nav__item text-darkest">{% trans "Keys" %}</li> | ||
<li id="tab3" class="sett__nav__item text-darkest">{% trans "Experimental Features" %}</li> | ||
{% if not form.instance.has_github_login %} | ||
<li id="tab3" class="sett__nav__item text-darkest">{% trans "Password" %}</li> | ||
{%endif %} | ||
<li id="tab4" class="sett__nav__item text-darkest">{% trans "Experimental Features" %}</li> | ||
</div> | ||
</ul> | ||
|
||
|
@@ -65,6 +68,19 @@ | |
</div> | ||
</li> | ||
<li class="section" id="section3"> | ||
<div class="col-xxs-12 col-xs-12 col-md-12 start-xs"> | ||
<div class="form__block"> | ||
{{ form.current_password.errors }} {{ form.current_password.label_tag }} {{ form.current_password }} | ||
</div> | ||
<div class="form__block"> | ||
{{ form.new_password2.errors }} {{ form.new_password1.label_tag }} {{ form.new_password1 }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a typo, should be |
||
</div> | ||
<div class="form__block"> | ||
{{ form.new_password2.errors }} {{ form.new_password2.label_tag }} {{ form.new_password2 }} | ||
</div> | ||
</div> | ||
</li> | ||
<li class="section" id="section4"> | ||
<div class="col-xs-12 start-xs"> | ||
<span class="text-blue smalltext"> | ||
<p> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? This is a Python 3 project, there is no need to call super using the old "style".