Example #1
0
File: users.py Project: fk-lx/mygpo
def restore_password(request):

    if request.method == 'GET':
        form = RestorePasswordForm()
        return render(request, 'restore_password.html', {
            'form': form,
        })


    form = RestorePasswordForm(request.POST)
    if not form.is_valid():
        return HttpResponseRedirect('/login/')

    user = get_user(form.cleaned_data['username'], form.cleaned_data['email'], is_active=None)

    if not user:
        messages.error(request, _('User does not exist.'))

        return render(request, 'password_reset_failed.html')

    site = RequestSite(request)
    pwd = "".join(random.sample(string.letters+string.digits, 8))
    subject = _('Reset password for your account on %s') % site
    message = _('Here is your new password for your account %(username)s on %(site)s: %(password)s') % {'username': user.username, 'site': site, 'password': pwd}
    user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
    _set_password(user, pwd)
    return render(request, 'password_reset.html')
Example #2
0
def restore_password(request):

    if request.method == "GET":
        form = RestorePasswordForm()
        return render(request, "restore_password.html", {"form": form})

    form = RestorePasswordForm(request.POST)
    if not form.is_valid():
        return HttpResponseRedirect("/login/")

    try:
        user = UserProxy.objects.all().by_username_or_email(form.cleaned_data["username"], form.cleaned_data["email"])

    except UserProxy.DoesNotExist:
        messages.error(request, _("User does not exist."))
        return render(request, "password_reset_failed.html")

    if not user.is_active:
        send_activation_email(user, request)
        messages.error(request, _("Please activate your account first. " "We have just re-sent your activation email"))
        return HttpResponseRedirect(reverse("login"))

    site = RequestSite(request)
    pwd = random_token(length=16)
    user.set_password(pwd)
    user.save()
    subject = render_to_string("reset-pwd-subj.txt", {"site": site}).strip()
    message = render_to_string("reset-pwd-msg.txt", {"username": user.username, "site": site, "password": pwd})
    user.email_user(subject, message)
    return render(request, "password_reset.html")
Example #3
0
def restore_password(request):

    if request.method == 'GET':
        form = RestorePasswordForm()
        return render(request, 'restore_password.html', {
            'form': form,
        })


    form = RestorePasswordForm(request.POST)
    if not form.is_valid():
        return HttpResponseRedirect('/login/')

    try:
        user = UserProxy.objects.all().by_username_or_email(
                form.cleaned_data['username'],
                form.cleaned_data['email']
            )

    except UserProxy.DoesNotExist:
        messages.error(request, _('User does not exist.'))
        return render(request, 'password_reset_failed.html')

    if not user.is_active:
        send_activation_email(user, request)
        messages.error(request, _('Please activate your account first. '
            'We have just re-sent your activation email'))
        return HttpResponseRedirect(reverse('login'))

    site = RequestSite(request)
    pwd = random_token(length=16)
    user.set_password(pwd)
    user.save()
    subject = render_to_string('reset-pwd-subj.txt', {'site': site}).strip()
    message = render_to_string('reset-pwd-msg.txt', {
        'username': user.username,
        'site': site,
        'password': pwd,
    })
    user.email_user(subject, message)
    return render(request, 'password_reset.html')
Example #4
0
def restore_password(request):

    if request.method == 'GET':
        form = RestorePasswordForm()
        return render(request, 'restore_password.html', {
            'form': form,
        })


    form = RestorePasswordForm(request.POST)
    if not form.is_valid():
        return HttpResponseRedirect('/login/')

    try:
        user = UserProxy.objects.all().by_username_or_email(
                form.cleaned_data['username'],
                form.cleaned_data['email']
            )

    except UserProxy.DoesNotExist:
        messages.error(request, _('User does not exist.'))
        return render(request, 'password_reset_failed.html')

    if not user.is_active:
        send_activation_email(user, request)
        messages.error(request, _('Please activate your account first. '
            'We have just re-sent your activation email'))
        return HttpResponseRedirect(reverse('login'))

    site = RequestSite(request)
    pwd = random_token(length=16)
    user.set_password(pwd)
    user.save()
    subject = render_to_string('reset-pwd-subj.txt', {'site': site}).strip()
    message = render_to_string('reset-pwd-msg.txt', {
        'username': user.username,
        'site': site,
        'password': pwd,
    })
    user.email_user(subject, message)
    return render(request, 'password_reset.html')
Example #5
0
def restore_password(request):

    if request.method == "GET":
        form = RestorePasswordForm()
        return render(request, "restore_password.html", {"form": form})

    form = RestorePasswordForm(request.POST)
    if not form.is_valid():
        return HttpResponseRedirect("/login/")

    try:
        user = UserProxy.objects.all().by_username_or_email(
            form.cleaned_data["username"], form.cleaned_data["email"])

    except UserProxy.DoesNotExist:
        messages.error(request, _("User does not exist."))
        return render(request, "password_reset_failed.html")

    if not user.is_active:
        send_activation_email(user, request)
        messages.error(
            request,
            _("Please activate your account first. "
              "We have just re-sent your activation email"),
        )
        return HttpResponseRedirect(reverse("login"))

    site = RequestSite(request)
    pwd = random_token(length=16)
    user.set_password(pwd)
    user.save()
    subject = render_to_string("reset-pwd-subj.txt", {"site": site}).strip()
    message = render_to_string("reset-pwd-msg.txt", {
        "username": user.username,
        "site": site,
        "password": pwd
    })
    user.email_user(subject, message)
    return render(request, "password_reset.html")