Beispiel #1
0
    def test_credentials_change(self):
        """changedcredentials module allows for credentials change"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'pass123')

        credentials_token = changedcredentials.cache_new_credentials(
            test_user, '*****@*****.**', 'newpass123')

        new_credentials = changedcredentials.get_new_credentials(
            test_user, credentials_token)

        self.assertEqual(new_credentials['email'], '*****@*****.**')
        self.assertEqual(new_credentials['password'], 'newpass123')
Beispiel #2
0
def confirm_email_password_change(request, token):
    new_credentials = get_new_credentials(request.user, token)
    if not new_credentials:
        messages.error(request, _("Confirmation link is invalid."))
    else:
        changes_made = []
        if new_credentials['email']:
            request.user.set_email(new_credentials['email'])
            changes_made.extend(['email', 'email_hash'])
        if new_credentials['password']:
            request.user.password = new_credentials['password']
            update_session_auth_hash(request, request.user)
            changes_made.append('password')

        try:
            request.user.save(update_fields=changes_made)
            message = _("Changes in e-mail and password have been saved.")
            messages.success(request, message)
        except IntegrityError:
            messages.error(request, _("Confirmation link is invalid."))
    return redirect('misago:usercp_change_email_password')