Exemple #1
0
def set_password(request, token=None, event=None):
    if request.user.is_authenticated():
        return redirect('root', event=event)
    else:
        rt = get_object_or_404(RegisterToken, token=token)

        if rt.is_valid:
            if request.method == 'POST':
                form = ChangePasswordForm(request.POST, auto_id=True)
                if form.is_valid():
                    user = getattr(rt, 'user')

                    user.is_active = True
                    user.set_password(form.cleaned_data['new_password'])
                    user.save()

                    rt.delete()

                    messages.success(request, "User %s successfully had it's password changed. You can now log in." % user)

                    return redirect('root', event=event)
            else:

                form = ChangePasswordForm()

                messages.success(request, "Token accepted. Please insert your new password.")

            return render(request, 'auth/set_password.html', {'form': form, 'token': token, 'event': event})

        else:
            messages.error(request, "The token has expired. Please use the password recovery to get a new token.")
            return redirect('root', event=event)
Exemple #2
0
def set_password(request, token=None):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        rt = get_object_or_404(RegisterToken, token=token)

        if rt.is_valid:
            if request.method == 'POST':
                form = ChangePasswordForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
                if form.is_valid():
                    user = getattr(rt, 'user')

                    user.is_active = True
                    user.set_password(form.cleaned_data['new_password'])
                    user.save()

                    rt.delete()

                    messages.success(request, _(u'Successfully changed password for user {user}. You can now log in.').format(user=user))
                    return HttpResponseRedirect('/')
            else:
                form = ChangePasswordForm()
                messages.success(request, _(u'Please insert your new password.'))

            return render(request, 'auth/set_password.html', {'form': form, 'token': token})

        else:
            messages.error(request, _(u'The link has expired. Please use the password recovery to get a new one.'))
            return HttpResponseRedirect('/')
Exemple #3
0
def set_password(request, token=None):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        rt = get_object_or_404(RegisterToken, token=token)

        if rt.is_valid:
            if request.method == 'POST':
                form = ChangePasswordForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
                if form.is_valid():
                    user = getattr(rt, 'user')

                    user.is_active = True
                    user.set_password(form.cleaned_data['new_password'])
                    user.save()

                    rt.delete()

                    messages.success(request, _(u"User ") + unicode(user) + _(u" successfully had it's password changed. You can now log in."))

                    return HttpResponseRedirect('/')
            else:

                form = ChangePasswordForm()

                messages.success(request, _(u"Token accepted. Please insert your new password."))

            return render(request, 'auth/set_password.html', {'form': form, 'token': token})

        else:
            messages.error(request, _(u"The token has expired. Please use the password recovery to get a new token."))
            return HttpResponseRedirect('/')
Exemple #4
0
def set_password(request, token=None):
    log = logging.getLogger(__name__)
    if request.user.is_authenticated:
        return HttpResponseRedirect('/')
    else:
        rt = None
        try:
            rt = RegisterToken.objects.get(token=token)
        except RegisterToken.DoesNotExist:
            log.debug(
                '%s tried to set password with nonexisting/expired token %s' %
                (request.user, token))
            messages.error(
                request,
                'Denne lenken er utløpt. Bruk gjenopprett passord for å få tilsendt en ny lenke.'
            )
        if rt and rt.is_valid:
            if request.method == 'POST':
                form = ChangePasswordForm(request.POST, auto_id=True)
                if form.is_valid():
                    user = getattr(rt, 'user')

                    user.is_active = True
                    user.set_password(form.cleaned_data['new_password'])
                    user.save()

                    rt.delete()

                    messages.success(
                        request,
                        _('Passordgjenoppretting gjennomført for "%s". ' +
                          'Du kan nå logge inn.') % user.username)
                    log.info('User "%s" successfully recovered password.' %
                             request.user)
                    return HttpResponseRedirect('/')
                else:
                    messages.error(
                        request,
                        'Noe gikk galt med gjenoppretting av passord. Vennligst prøv igjen.'
                    )
                    log.debug(
                        'User %s failed to recover password with token %s. '
                        '[form.is_valid => False]' % (request.user, rt))
                    return HttpResponseRedirect('/')
            else:
                form = ChangePasswordForm()
                messages.success(
                    request,
                    _('Lenken er akseptert. Vennligst skriv inn ønsket passord.'
                      ))
            return render(request, 'auth/set_password.html', {
                'form': form,
                'token': token
            })
        log.debug('User %s failed to recover password with token %s.' %
                  (request.user, rt))
        messages.error(
            request,
            'Noe gikk galt med gjenoppretning av passord. Vennligst prøv igjen.'
        )
        return HttpResponseRedirect('/')