Пример #1
0
def password_reset_confirm(request, uidb36=None, token=None):
    """View that checks the hash in a password reset link and presents a
    form for entering a new password.

    Based on django.contrib.auth.views.

    """
    try:
        uid_int = base36_to_int(uidb36)
    except ValueError:
        raise Http404

    user = get_object_or_404(User, id=uid_int)
    context = {}

    if default_token_generator.check_token(user, token):
        context['validlink'] = True
        if request.method == 'POST':
            form = SetPasswordForm(user, request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('users.pw_reset_complete'))
        else:
            form = SetPasswordForm(None)
    else:
        context['validlink'] = False
        form = None
    context['form'] = form
    return jingo.render(request, 'users/pw_reset_confirm.html', context)
Пример #2
0
def password_reset_confirm(request, uidb36=None, token=None):
    """View that checks the hash in a password reset link and presents a
    form for entering a new password.

    Based on django.contrib.auth.views.

    """
    try:
        uid_int = base36_to_int(uidb36)
    except ValueError:
        raise Http404

    user = get_object_or_404(User, id=uid_int)
    context = {}

    if default_token_generator.check_token(user, token):
        context['validlink'] = True
        if request.method == 'POST':
            form = SetPasswordForm(user, request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('users.pw_reset_complete'))
        else:
            form = SetPasswordForm(None)
    else:
        context['validlink'] = False
        form = None
    context['form'] = form
    return jingo.render(request, 'users/pw_reset_confirm.html', context)
Пример #3
0
def password_reset_confirm(request, uidb36=None, token=None):
    """View that checks the hash in a password reset link and presents a
    form for entering a new password.
    
    It's used on both desktop (ajax) and mobile websites.
    """
    try:
        uid_int = base36_to_int(uidb36)
    except ValueError:
        raise Http404

    user = get_object_or_404(User, id=uid_int)
    context = {}

    # Display mobile or desktop version by sniffing user-agent
    mobile = is_mobile(request)

    if default_token_generator.check_token(user, token):
        context['validlink'] = True
        if request.method == 'POST':
            form = SetPasswordForm(user, request.POST)
            if form.is_valid():
                form.save()
                if mobile:
                    return HttpResponseRedirect(
                        reverse('users.mobile_pw_reset_complete'))
                else:
                    return {'status': 'success'}
            elif not mobile:
                return {
                    'status': 'error',
                    'errors': dict(form.errors.iteritems())
                }
        else:
            form = SetPasswordForm(None)
    else:
        context['validlink'] = False
        form = None
    context['form'] = form

    if mobile:
        return jingo.render(request, 'users/mobile/pw_reset_confirm.html',
                            context)
    else:
        context.update({
            'uidb36': uidb36,
            'token': token,
            'is_pwreset': True,
            'is_homepage': True,
            'stats': get_global_stats()
        })
        return jingo.render(request, 'desktop/home.html', context)
Пример #4
0
def password_reset_confirm(request, uidb36=None, token=None):
    """View that checks the hash in a password reset link and presents a
    form for entering a new password.
    
    It's used on both desktop (ajax) and mobile websites.
    """
    try:
        uid_int = base36_to_int(uidb36)
    except ValueError:
        raise Http404
    
    user = get_object_or_404(User, id=uid_int)
    context = {}
    
    # Display mobile or desktop version by sniffing user-agent
    mobile = is_mobile(request)

    if default_token_generator.check_token(user, token):
        context['validlink'] = True
        if request.method == 'POST':
            form = SetPasswordForm(user, request.POST)
            if form.is_valid():
                form.save()
                if mobile:
                    return HttpResponseRedirect(reverse('users.mobile_pw_reset_complete'))
                else:
                    return {'status': 'success'}
            elif not mobile:
                    return {'status': 'error',
                            'errors': dict(form.errors.iteritems())}
        else:
            form = SetPasswordForm(None)
    else:
        context['validlink'] = False
        form = None
    context['form'] = form

    if mobile:
        return jingo.render(request, 'users/mobile/pw_reset_confirm.html', context)
    else:
        context.update({'uidb36': uidb36,
                        'token': token,
                        'is_pwreset': True,
                        'is_homepage': True,
                        'stats': get_global_stats() })
        return jingo.render(request, 'desktop/home.html', context)
Пример #5
0
def handle_password_reset_confirm(request, uidb36, token):
    """Present set password form or perform actual password reset."""
    try:
        uid_int = base36_to_int(uidb36)
        user = User.objects.get(id=uid_int)
    except (ValueError, User.DoesNotExist):
        raise Http404

    if not auth.tokens.default_token_generator.check_token(user, token):
        raise Http404

    if request.method == 'POST':
        form = SetPasswordForm(user, request.POST)
        if form.is_valid():
            form.save()
        return form
    return SetPasswordForm(None)