User registration prevents using password as username.
Some users erroneously set their password as their username with the original layout, because the username field directly followed the password field. Users may be accustomed to the common occurrence of a password confirmation field directly following the password field. To fix the issue, I did the following: - Moved the existing username and real name form fields above the password field. - Added a validation in the create_account handler in common/djangoapps/student/views.py, which confirms that the password field does not match the username field. New tests created to check the added functionality.
This commit is contained in:
@@ -236,3 +236,39 @@ class TestPasswordPolicy(TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
obj = json.loads(response.content)
|
||||
self.assertTrue(obj['success'])
|
||||
|
||||
|
||||
class TestUsernamePasswordNonmatch(TestCase):
|
||||
"""
|
||||
Test that registration username and password fields differ
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestUsernamePasswordNonmatch, self).setUp()
|
||||
self.url = reverse('create_account')
|
||||
|
||||
self.url_params = {
|
||||
'username': 'username',
|
||||
'email': 'foo_bar@bar.com',
|
||||
'name': 'username',
|
||||
'terms_of_service': 'true',
|
||||
'honor_code': 'true',
|
||||
}
|
||||
|
||||
def test_with_username_password_match(self):
|
||||
self.url_params['username'] = "foobar"
|
||||
self.url_params['password'] = "foobar"
|
||||
response = self.client.post(self.url, self.url_params)
|
||||
self.assertEquals(response.status_code, 400)
|
||||
obj = json.loads(response.content)
|
||||
self.assertEqual(
|
||||
obj['value'],
|
||||
"Username and password fields cannot match",
|
||||
)
|
||||
|
||||
def test_with_username_password_nonmatch(self):
|
||||
self.url_params['username'] = "foobar"
|
||||
self.url_params['password'] = "nonmatch"
|
||||
response = self.client.post(self.url, self.url_params)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
obj = json.loads(response.content)
|
||||
self.assertTrue(obj['success'])
|
||||
|
||||
@@ -1275,6 +1275,14 @@ def create_account(request, post_override=None): # pylint: disable-msg=too-many
|
||||
extended_profile = {}
|
||||
extended_profile[field] = post_vars[field]
|
||||
|
||||
# Make sure that password and username fields do not match
|
||||
username = post_vars['username']
|
||||
password = post_vars['password']
|
||||
if username == password:
|
||||
js['value'] = _("Username and password fields cannot match")
|
||||
js['field'] = 'username'
|
||||
return JsonResponse(js, status=400)
|
||||
|
||||
# Ok, looks like everything is legit. Create the account.
|
||||
try:
|
||||
with transaction.commit_on_success():
|
||||
|
||||
Reference in New Issue
Block a user