Ejemplo n.º 1
0
def forgot(request):
    content = Content()
    content.title = "Forgot Password"
    content.header = "Forgot Password"
    content.body = "Enter your email address and you will receive an email with a link to reset your password"
    submit_value = "Submit"
    submit_action = reverse('users.views.forgot')

    if request.method == 'POST':
        form = ResetForm(request.POST)
        if form.is_valid():
            user = User.objects.filter(email=form.cleaned_data['email'])
            if user > 0:
                user = ProjectUser.objects.get(user=user[0])

                user.reset_string = sha.sha(str(random.random())).hexdigest()
                user.save()

                current_site = Site.objects.get_current()
                email_message = """
                    Click this link to reset your password,
                    http://""" + current_site.domain + reverse("users.views.reset", kwargs={'email':user.user.email, 'reset_string':user.reset_string})

            send_mail("Partybeat password reset", email_message, "*****@*****.**", [user.user.email], fail_silently=False)

            content.body = "An email with the reset link has been sent"
    else:
        form = ResetForm()

    return render_to_response('users/index.html', locals(), context_instance=RequestContext(request))
Ejemplo n.º 2
0
def reset(request, email, reset_string):
    content = Content()
    content.title = "Password Reset"
    content.header = "Password Reset"
    content.body = ""

    user = User.objects.filter(email=email)
    if user:
        user = ProjectUser.objects.get(user=user[0])

    if user and user.reset_string == reset_string:
        if request.method == 'POST':
            form = ResetPasswordForm(request.POST)
            if form.is_valid():
                user.user.set_password(form.cleaned_data["password"])
                user.reset_string = None
                user.user.save()
                user.save()
                success_message = 'Your password has been updated. Please try to <a href="%s">log in</a>' % (reverse('users.views.login'))
        else:
            content.body = "Please enter a new password"
            form = ResetPasswordForm()
        submit_value = "Submit"
        submit_action = reverse('users.views.reset', kwargs={'email':email, 'reset_string':reset_string})
    else:
        success_message = "The email address or reset key is incorrect. Please use the url provided in the password reset email"
    return render_to_response('users/index.html', locals(), context_instance=RequestContext(request))