コード例 #1
0
def set_password(request):
    if request.user.has_usable_password():
        return HttpResponseRedirect(reverse('root'))
    if request.method == 'GET':
        return TemplateResponse(request, 'callback.html', {'form': SetPasswordForm(), 'email': request.user.email})
    else:
        form = SetPasswordForm(request.POST)
        if form.is_valid():
            user = request.user
            form.save(user)
            auth.login(request, user)
            messages.success(request, 'Password correctly set')
            return HttpResponseRedirect(reverse('root'))
        return TemplateResponse(request, 'callback.html', {'form': form, 'email': request.user.email})
コード例 #2
0
ファイル: views.py プロジェクト: yananda93/registration
def password_reset_confirm(request, uid, token):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    try:
        uid = force_text(urlsafe_base64_decode(uid))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        return TemplateResponse(request, 'password_reset_confirm.html',
                                {'validlink': False})

    if password_reset_token.check_token(user, token):
        if request.method == 'POST':
            form = SetPasswordForm(request.POST)
            if form.is_valid():
                form.save(user)
                return HttpResponseRedirect(reverse('password_reset_complete'))
        form = SetPasswordForm()
    else:
        return TemplateResponse(request, 'password_reset_confirm.html',
                                {'validlink': False})

    return TemplateResponse(request, 'password_reset_confirm.html', {
        'validlink': True,
        'form': form
    })
コード例 #3
0
def password_reset_confirm(request, uid, token):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    try:
        uid = force_text(urlsafe_base64_decode(uid))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False})

    if password_reset_token.check_token(user, token):
        if request.method == 'POST':
            form = SetPasswordForm(request.POST)
            if form.is_valid():
                form.save(user)
                return HttpResponseRedirect(reverse('password_reset_complete'))
        form = SetPasswordForm()
    else:
        return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False})

    return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': True, 'form': form})
コード例 #4
0
ファイル: views.py プロジェクト: Casassarnau/registration
def set_password(request):
    if request.user.has_usable_password():
        return HttpResponseRedirect(reverse('root'))
    if request.method == 'GET':
        return TemplateResponse(request, 'callback.html', {'form': SetPasswordForm(), 'email': request.user.email})
    else:
        form = SetPasswordForm(request.POST)
        if form.is_valid():
            user = request.user
            form.save(user)
            auth.login(request, user)
            messages.success(request, 'Password correctly set')
            return HttpResponseRedirect(reverse('root'))
        return TemplateResponse(request, 'callback.html', {'form': form, 'email': request.user.email})
コード例 #5
0
 def test_form_renders_password_inputs(self):
     form = SetPasswordForm('*****@*****.**')
     self.assertIn('placeholder="********"', form.as_p())
     self.assertIn('id="id_new_password1"', form.as_p())
     self.assertIn('id="id_new_password2"', form.as_p())