-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Removal of optional sign next to New Password (#967)
* removal of optional sign next to New Password * Merge branch 'master' into independent_edit_account_fix * Re-arrangement of a few pieces of code * Merge branch 'independent_edit_account_fix' of https://github.com/ocadotechnology/codeforlife-portal into independent_edit_account_fix * Small syntax fix * Spacing and Cyclomatic complexity fix * More spacing fixes * Fixing functions * indentation fix * Indentation fix * Email verification fix * Name change fix * Merge branch 'master' into independent_edit_account_fix * Spacing Changes * Merge branch 'independent_edit_account_fix' of https://github.com/ocadotechnology/codeforlife-portal into independent_edit_account_fix * Revert "Spacing Changes" This reverts commit 634bb36. * Used FormView instead of VanillaView * Merge branch 'master' into independent_edit_account_fix * Spacing changes and getting rid of prints * Merge branch 'independent_edit_account_fix' of https://github.com/ocadotechnology/codeforlife-portal into independent_edit_account_fix * Spacing fix * Refactored get_form method * Similar blocks of code changed * Indentation fix * Form_Valid unrefactored * Merge branch 'master' into independent_edit_account_fix * typo fix * Merge branch 'master' into independent_edit_account_fix * Merge branch 'master' into independent_edit_account_fix * Add verification success url * Fix test issues * Refactored process form function * Restructured student views, added docstrings and constant * Refactor stuff * More refactoring * Even more refactoring * Makes methods private * Remove blank lines
- Loading branch information
1 parent
da59b85
commit e7661bf
Showing
15 changed files
with
453 additions
and
401 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,17 +34,17 @@ | |
# copyright notice and these terms. You must not misrepresent the origins of this | ||
# program; modified versions of the program must be marked as such and not | ||
# identified as the original program. | ||
from datetime import timedelta | ||
import re | ||
from datetime import timedelta | ||
|
||
from captcha.fields import ReCaptchaField | ||
from django import forms | ||
from django.contrib.auth import authenticate | ||
from django.contrib.auth.models import User | ||
from django.utils import timezone | ||
|
||
from portal.helpers.password import form_clean_password | ||
from portal.models import Student, Class, stripStudentName | ||
from portal.helpers.password import password_strength_test | ||
from captcha.fields import ReCaptchaField | ||
|
||
|
||
class StudentLoginForm(forms.Form): | ||
|
@@ -98,6 +98,28 @@ def check_for_errors(self, name, access_code, password): | |
|
||
|
||
class StudentEditAccountForm(forms.Form): | ||
password = forms.CharField( | ||
label="New password", required=True, widget=forms.PasswordInput | ||
) | ||
confirm_password = forms.CharField( | ||
label="Confirm new password", required=True, widget=forms.PasswordInput | ||
) | ||
current_password = forms.CharField( | ||
label="Current password", widget=forms.PasswordInput | ||
) | ||
|
||
def __init__(self, user, *args, **kwargs): | ||
self.user = user | ||
super(StudentEditAccountForm, self).__init__(*args, **kwargs) | ||
|
||
def clean_password(self): | ||
return form_clean_password(self, forms, "password") | ||
|
||
def clean(self): | ||
return clean_confirm_password(self) | ||
|
||
|
||
class IndependentStudentEditAccountForm(forms.Form): | ||
name = forms.CharField( | ||
label="Name", | ||
max_length=100, | ||
|
@@ -110,7 +132,7 @@ class StudentEditAccountForm(forms.Form): | |
widget=forms.EmailInput(attrs={"placeholder": "[email protected]"}), | ||
) | ||
password = forms.CharField( | ||
label="New password (optional)", required=False, widget=forms.PasswordInput | ||
label="New password", required=False, widget=forms.PasswordInput | ||
) | ||
confirm_password = forms.CharField( | ||
label="Confirm new password", required=False, widget=forms.PasswordInput | ||
|
@@ -121,7 +143,7 @@ class StudentEditAccountForm(forms.Form): | |
|
||
def __init__(self, user, *args, **kwargs): | ||
self.user = user | ||
super(StudentEditAccountForm, self).__init__(*args, **kwargs) | ||
super(IndependentStudentEditAccountForm, self).__init__(*args, **kwargs) | ||
|
||
def clean_name(self): | ||
name = self.cleaned_data.get("name", None) | ||
|
@@ -137,27 +159,18 @@ def clean_name(self): | |
return name | ||
|
||
def clean_password(self): | ||
password = self.cleaned_data.get("password", None) | ||
return form_clean_password(self, forms, "password") | ||
|
||
if password and not password_strength_test( | ||
password, length=8, upper=False, lower=False, numbers=False | ||
): | ||
raise forms.ValidationError( | ||
"Password not strong enough, consider using at least 8 characters, upper and lower case letters, and numbers" | ||
) | ||
def clean(self): | ||
return clean_confirm_password(self) | ||
|
||
return password | ||
|
||
def clean(self): | ||
def clean_confirm_password(self): | ||
password = self.cleaned_data.get("password", None) | ||
confirm_password = self.cleaned_data.get("confirm_password", None) | ||
current_password = self.cleaned_data.get("current_password", None) | ||
|
||
if ( | ||
password is not None | ||
and (password or confirm_password) | ||
and password != confirm_password | ||
): | ||
if are_password_and_confirm_password_different(password, confirm_password): | ||
raise forms.ValidationError("Your new passwords do not match") | ||
|
||
if current_password and not self.user.check_password(current_password): | ||
|
@@ -166,6 +179,10 @@ def clean(self): | |
return self.cleaned_data | ||
|
||
|
||
def are_password_and_confirm_password_different(password, confirm_password): | ||
return password is not None and password != confirm_password | ||
|
||
|
||
class IndependentStudentSignupForm(forms.Form): | ||
name = forms.CharField( | ||
label="Name", | ||
|
@@ -218,16 +235,7 @@ def clean_username(self): | |
return username | ||
|
||
def clean_password(self): | ||
password = self.cleaned_data.get("password", None) | ||
|
||
if password and not password_strength_test( | ||
password, length=8, upper=False, lower=False, numbers=False | ||
): | ||
raise forms.ValidationError( | ||
"Password not strong enough, consider using at least 8 characters, upper and lower case letters, and numbers" | ||
) | ||
|
||
return password | ||
return form_clean_password(self, forms, "password") | ||
|
||
def clean(self): | ||
password = self.cleaned_data.get("password", None) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.