diff --git a/pandora/user/models.py b/pandora/user/models.py index f8a5d152..2e20b272 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -16,7 +16,7 @@ from itemlist.models import List, Position class UserProfile(models.Model): - reset_token = models.TextField(blank=True, null=True, unique=True) + reset_code = models.TextField(blank=True, null=True, unique=True) user = models.ForeignKey(User, unique=True, related_name='profile') level = models.IntegerField(default=1) diff --git a/pandora/user/templates/password_reset_email.txt b/pandora/user/templates/password_reset_email.txt index 84d11c66..d0d748b0 100644 --- a/pandora/user/templates/password_reset_email.txt +++ b/pandora/user/templates/password_reset_email.txt @@ -1,6 +1,6 @@ -To reset your password, please use the following token: +To reset your password, please use the following code: -{{token}} +{{code}} If you do not want to reset your password, no further action is required. diff --git a/pandora/user/views.py b/pandora/user/views.py index f002147e..4e0b0218 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -191,15 +191,16 @@ actions.register(signup, cache=False) def resetPassword(request): ''' param data { - token: reset token + username: username, password: new password + code: reset code } return { status: {'code': int, 'text': string} data: { errors: { - token: 'Invalid token' + code: 'Invalid Code' } user { } @@ -207,7 +208,7 @@ def resetPassword(request): } ''' data = json.loads(request.POST['data']) - if 'token' in data and 'password' in data: + if 'code' in data and 'password' in data: if not data['password']: response = json_response({ 'errors': { @@ -215,13 +216,13 @@ def resetPassword(request): } }) else: - qs = models.UserProfile.objects.filter(reset_token=data['token']) + qs = models.UserProfile.objects.filter(reset_code=data['code']) if qs.count() == 1: user = qs[0].user user.set_password(data['password']) user.save() user_profile = user.get_profile() - user_profile.reset_token = None + user_profile.reset_code = None user_profile.save() user = authenticate(username=user.username, password=data['password']) login(request, user) @@ -233,7 +234,7 @@ def resetPassword(request): else: response = json_response({ 'errors': { - 'token': 'Invalid token' + 'code': 'Invalid code' } }) @@ -275,17 +276,17 @@ def requestToken(request): user = None if user: while True: - token = ox.to26(random.randint(32768, 1048575)) - if models.UserProfile.objects.filter(reset_token=token).count() == 0: + code = ox.to26(random.randint(32768, 1048575)) + if models.UserProfile.objects.filter(reset_code=code).count() == 0: break user_profile = user.get_profile() - user_profile.reset_token = token + user_profile.reset_code = code user_profile.save() template = loader.get_template('password_reset_email.txt') context = RequestContext(request, { 'url': request.build_absolute_uri("/"), - 'token': token, + 'code': code, 'sitename': settings.SITENAME, }) message = template.render(context) diff --git a/static/js/pandora/autovalidate.js b/static/js/pandora/autovalidate.js index b7c35bb6..2a8ec29d 100644 --- a/static/js/pandora/autovalidate.js +++ b/static/js/pandora/autovalidate.js @@ -27,7 +27,7 @@ pandora.autovalidateListname = function(value, blur, callback) { while (value.indexOf(v) > -1) { value = value.replace(new RegExp(v, 'g'), v[0] + (v[0] == '\\' ? v[1] : '')); } - }) + }); callback(value); }; @@ -44,7 +44,7 @@ pandora.autovalidateUsername = function(value, blur, callback) { while (value.indexOf(v) > -1) { value = value.replace(new RegExp(v, 'g'), v[0]); } - }) + }); callback(value); }; diff --git a/static/js/pandora/ui/account.js b/static/js/pandora/ui/account.js index 39b01847..d71b9ab1 100644 --- a/static/js/pandora/ui/account.js +++ b/static/js/pandora/ui/account.js @@ -71,10 +71,11 @@ pandora.ui.accountDialogOptions = function(action, value) { }); } } + return { buttons: Ox.merge(buttons[action].map(function(type) { return button(type); - }), [{}, button('cancel'), button('submit')]), + }), [button('cancel'), button('submit')]), content: Ox.Element() .append( $('') @@ -162,11 +163,11 @@ pandora.ui.accountForm = function(action, value) { pandora.api.resetPassword(data, function(result) { if (!result.data.errors) { pandora.$ui.accountDialog.close(); - pandora.login(result.data); + pandora.signin(result.data); } else { callback([{id: 'code', message: 'Incorrect code'}]); } - }) + }); } } }).bindEvent({