Esempio n. 1
0
 def test_unknown_email(self):
     data = {'email': '*****@*****.**',}
     form = ForgotPasswordForm(data)
     self.assertTrue(form.is_bound)
     self.assertFalse(form.is_valid())
     self.assertEqual([_(u'This email isn\'t registered'),],
         form['email'].errors)
Esempio n. 2
0
def forgot_password(request):
    msg = None
    success = None

    if request.method == 'POST':
        form = ForgotPasswordForm(request.POST)

        if form.is_valid():
            mail = form.cleaned_data['email']
            u = User.objects.filter(email=mail)

            if u:
                u = u[0]
                subject = 'Forgot Password (EDC IITR)'
                html_content = 'Hi <strong>%s,</strong><br />. Your account password is %s <br />Regards,<br/>Team EDC' % (u.name, u.password)
                from_email = '*****@*****.**'
                email = EmailMessage(subject, html_content, from_email, [mail])
                email.content_subtype = "html"  # Main content is now text/html
                email.send()
                msg = 'Your password has been emailed to you'
                success = 1
            else:
                msg = 'This Email ID has not been registered'
                success = 0
    else:
        form = ForgotPasswordForm()

    return render_to_response('users/forgot_password.html', {'name': 'Edit', 'list': menu, 'form': form, 'msg': msg, 'success': success}, context_instance=RequestContext(request))
Esempio n. 3
0
    def post(self, request):
        redirect_to = reverse('login')
        form = ForgotPasswordForm(request.POST)
        if form.is_valid():
            email = request.POST.get('email')
            if not UserProfile.objects.filter(email=email):
                return render(request, 'forgetpwd.html', {'msg': '此邮箱未注册'})
            print(email)

            code = request.POST.get('verification_code')
            print(code)
            identify_code = User_ex.objects.filter(valid_code=code)
            print(identify_code)
            if identify_code:
                for identify_codes in identify_code:
                    if identify_codes.email != email:
                        return render(request, 'forgetpwd.html',
                                      {'msg': '验证码不正确'})
            else:
                return render(request, 'forgetpwd.html', {'msg': '验证码不正确'})

            new_password = request.POST.get('new_password')
            print("新密码为" + new_password)
            user = UserProfile.objects.get(email=email)
            user.set_password(new_password)
            user.save()
            print("修改密码成功")

            return redirect(redirect_to)
            # return render(request, 'send_success.html')
        return render(request, "login.html")
Esempio n. 4
0
def forgot(request):
  form = ForgotPasswordForm()
  if request.method == 'POST':
    form = ForgotPasswordForm(request.POST)
    if form.is_valid():
      form.send_instructions()
      util.set_flash(request, "success_users_forgot")
      return redirect(reverse("success"))

  c = template.RequestContext(request, locals())
  return render_to_response('users_forgot.html', c)
Esempio n. 5
0
    def post(self, email, token):
        form = ForgotPasswordForm()
        if not form.validate_on_submit():
            return self.get()

        user = User.get_by(email=email)
        if user.restore_token != token:
            abort(403)

        user.set_password(form.password.data)
        user.restore_token = None
        user.save()
        login_user(user)
        return redirect(url_for('users.profile'))
Esempio n. 6
0
def view_forgot_password(request, forgot_password_template):
    if request.method == 'GET':
        form = ForgotPasswordForm()
        return response(request, forgot_password_template, {'form':form})
    form = ForgotPasswordForm(post_data(request))
    if not form.is_valid():
        return response(request, forgot_password_template, {'form':form})
    email = form.cleaned_data.get('email')
    try:
        from django.contrib.auth.models import get_hexdigest
        hash_key = get_hexdigest('md5', '', email)
        forgot_password_emailer(email, hash_key)
        from users.messages import SENT_FORGOT_PASSWORD_EMAIL_SUCCESSFULLY
        messages.success(request, SENT_FORGOT_PASSWORD_EMAIL_SUCCESSFULLY)
    except:
        from users.messages import CONTACTING_FAILED
        messages.error(request, CONTACTING_FAILED)
    return HttpResponseRedirect(redirect_to='/')
Esempio n. 7
0
 def test_reset_password(self):
     data = {'email': self.user.email}
     form = ForgotPasswordForm(data)
     self.assertTrue(form.is_bound)
     self.assertTrue(form.is_valid())
Esempio n. 8
0
 def get(self, request):
     forget_form = ForgotPasswordForm()
     return render(request, "forgetpwd.html", {"forget_form": forget_form})
Esempio n. 9
0
 def get(self):
     form = ForgotPasswordForm()
     return render_template('users/forgot_password.html', form=form)