Exemple #1
0
    def post(self, request):
        email = request.POST.get('email')
        print(email)
        data = request.POST

        # 2、验证表单数据
        modify_form = ModifyPwdForm(data)
        res = modify_form.is_valid()  # 验证成功返回True,验证失败返回False
        if res:
            password1 = modify_form.cleaned_data['password1']
            password2 = modify_form.cleaned_data['password2']

            if password1 == password2:
                try:
                    user = UserProfile.objects.get(username=email)
                except Exception as e:
                    return render(request, 'password_reset.html', {'modify_errors': {'error': '用户不存在'}, 'email': email})
                if user.check_password(password1) == True:
                    return render(request, 'password_reset.html',
                                  {'modify_errors': {'error': '新密码和旧密码重复'}, 'email': email})
                else:
                    user.set_password(password1)
                    user.save()
                    login(request, user)
                    response = redirect(reverse('index'))
                    response.set_cookie('username', email, constants.USERNAME_EXPIRE_TIME)
                    return response
            else:
                return render(request, 'password_reset.html', {'modify_errors': {'error': '修改密码失败'}})

        return render(request, 'password_reset.html', {'modify_form': modify_form})
Exemple #2
0
 def post(self, request):
     modify_psw_form = ModifyPwdForm(request.POST)
     if modify_psw_form.is_valid():
         new_psw = request.POST.get("new_psw", "")
         new_psw_confirm = request.POST.get("new_psw_confirm", "")
         active_code = request.POST.get("active_code", "")
         # 如果两次密码不相等,返回错误信息
         if new_psw != new_psw_confirm:
             return render(request, "password_reset.html", {
                 'active_code': active_code,
                 "msg": "两次输入的密码不一致"
             })
         # 新密码两次输入不一致,返回错误信息
         # 如果密码一致
         # 找到激活码对应的邮箱
         all_record = EmailVerifyRecord.objects.filter(code=active_code)
         for record in all_record:
             email = record.email
         user = UserProfile.objects.get(email=email)
         # 加密成密文
         user.password = make_password(new_psw)
         # save保存到数据库
         user.save()
         return render(request, "login.html", {"msg": "密码修改成功,请登录!"})
     # 验证失败说明密码位数不够。
     else:
         return render(request, 'password_reset.html',
                       {'modify_psw_form': modify_psw_form})
Exemple #3
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get("password1", '')
         pwd2 = request.POST.get("password2", '')
         email = request.POST.get("email", '')
         # 如果前后两次密码不相等,那么回填信息并返回错误提示
         if pwd1 != pwd2:
             return render(request, "password_reset.html", {
                 "email": email,
                 "msg": "对不起,前后密码不一致"
             })
         # 如果前后两次密码相等,那么进入我们的密码修改保存
         # 取出用户信息
         user = UserProfile.objects.get(email=email)
         # 随意取出一个密码并将其进行加密
         user.password = make_password(pwd1)
         # 将更新后的用户信息保存到数据库里面
         user.save()
         # 密码重置成功以后,跳转到登录页面
         return render(request, "login.html", {"msg": "恭喜您,您的密码修改成功,请登录"})
     else:
         email = request.POST.get("email", '')
         return render(request, "password_reset.html", {
             "email": email,
             "modify_form": modify_form
         })
Exemple #4
0
    def post(self, request):
        # 验证重置密码页面表单
        modifypwd_form = ModifyPwdForm(request.POST)
        if modifypwd_form.is_valid():
            pwd1 = request.POST.get('password1', '')
            pwd2 = request.POST.get('password2', '')
            email = request.POST.get('email', '')
            # 如果两次密码不一致,返回错误信息
            if pwd1 != pwd2:
                return render(request, 'password_reset.html', {
                    'msg': '两次密码不一致',
                    'email': email
                })
            # 密码一致
            user = UserProfile.objects.get(email=email)
            user.password = make_password(pwd1)
            user.save()

            return render(request, 'login.html', {'msg': '密码修改成功,请用新密码登录'})
        else:
            # 重置密码页面表单验证失败
            email = request.POST.get('email', '')
            return render(request, 'password_reset.html', {
                'email': email,
                'modifypwd_form': modifypwd_form
            })
Exemple #5
0
    def post(self, request):
        modiypwd_form = ModifyPwdForm(request.POST)

        if modiypwd_form.is_valid():
            pwd1 = request.POST.get("password1", "")
            pwd2 = request.POST.get("password2", "")
            active_code = request.POST.get("active_code", "")
            email = request.POST.get("email", "")
            # 如果两次密码不相等,返回错误信息
            if pwd1 != pwd2:
                return render(request, "password_reset.html", {"email": email, "msg": "密码不一致"})
            # 如果密码一致
            # 找到激活码对应的邮箱
            all_record = EmailVerifyRecord.objects.filter(code=active_code)
            for record in all_record:
                email = record.email
            user = UserProfile.objects.get(email=email)
            # 加密成密文
            user.password = make_password(pwd2)
            # save 保存到数据库
            user.save()
            return render(request, "login.html", {"msg": "密码修改成功,请登录"})
        # 验证失败说明密码位数不够
        else:
            email = request.POST.get("email", "")
            return render(
                request, "password_reset.html",
                {"email": email, "modiypwd_form": modiypwd_form}
            )
    def post(self, request):
        modify_form = ModifyPwdForm(request.POST)
        if modify_form.is_valid():
            pwd1 = request.POST.get('password1', '')
            pwd2 = request.POST.get('password2', '')
            email = request.POST.get('email', '')

            if pwd1 != pwd2:
                return render(request, 'password_reset.html', {
                    'email': email,
                    'msg': 'The two passwords are not the same'
                })

            user = UserProfile.objects.get(email=email)
            user.password = make_password(pwd2)
            user.save()

            return render(request, 'login.html')

        else:
            email = request.POST.get('email', '')
            return render(request, 'password_reset.html', {
                'email': email,
                "modify_form": modify_form
            })
Exemple #7
0
 def post(self, request):
     modiypwd_form = ModifyPwdForm(request.POST)
     if modiypwd_form.is_valid():
         pwd1 = request.POST.get("password1", "")
         pwd2 = request.POST.get("password2", "")
         email = request.POST.get("email", "")
         # 如果两次密码不相等,返回错误信息
         if pwd1 != pwd2:
             return render(request, "password_reset.html", {
                 "email": email,
                 "msg": "密码不一致"
             })
         # 如果密码一致
         user = UserProfile.objects.get(email=email)
         # 加密成密文
         user.password = make_password(pwd2)
         # save保存到数据库
         user.save()
         return render(request, "login.html", {"msg": "密码修改成功,请登录"})
     # 验证失败说明密码位数不够。
     else:
         email = request.POST.get("email", "")
         return render(request, "password_reset.html", {
             "email": email,
             "modiypwd_form": modiypwd_form
         })
Exemple #8
0
    def post(self, request):
        modify_form = ModifyPwdForm(request.POST)
        email = request.POST.get('email', '')
        active_code = request.POST.get('active_code', '')

        codes = EmailVerifyRecord.objects.get(code=active_code)
        if codes is None:
            return render(request, 'active_fail.html', {'msg': '修改密码连接已经失效!'})

        if modify_form.is_valid():
            pwd1 = request.POST.get('password1', '')
            pwd2 = request.POST.get('password2', '')
            if pwd1 != pwd2:
                return render(request, 'password_reset.html', {'email': email, 'active_code': active_code,
                                                               'msg': '密码不一致!'})
            user = UserProfile.objects.get(email=email)
            if user:
                user.password = make_password(pwd1)
                user.save()

                codes.delete()
                return render(request, 'login.html')
        else:
            return render(request, 'password_reset.html', {'email': email, 'active_code': active_code,
                                                           'modify_form': modify_form})
Exemple #9
0
    def post(self, request):
        modify_form = ModifyPwdForm(request.POST)
        if modify_form.is_valid():

            pwd1 = request.POST.get("password1", "")
            pwd2 = request.POST.get("password2", "")
            email = request.POST.get("email", "")
            # 判断前端获得到的密码1和密码2
            if pwd1 != pwd2:
                return render(request, "password_reset.html", {
                    "email": email,
                    "msg": "密码不一致"
                })

            # 把UserInfo的数据取到,然后把密码加密后修改密码并保存

            user = UserInfo.objects.get(email=email)
            user.password = make_password(pwd2)
            user.save()
            return render(request, 'reset_success.html')
            # return HttpResponseRedirect(reverse("login"))
        else:
            email = request.POST.get("email", "")
            return render(request, "password_reset.html", {
                "email": email,
                "modify_form": modify_form
            })
Exemple #10
0
    def post(self, request):
        # 1、获取前端传递的表单数据
        data = request.POST
        # 2、验证表单数据
        modify_form = ModifyPwdForm(data)
        res = modify_form.is_valid()  # 验证成功返回True,验证失败返回False

        if res:
            modify_data = modify_form.cleaned_data
            password1 = modify_data.get('password1')
            password2 = modify_data.get('password2')
            email = data.get('email')
            if password1 == password2:
                try:
                    user = UserProfile.objects.get(email=email)
                except:
                    return http.HttpResponseBadRequest('无此用户')
                else:
                    user.set_password(password2)
                    user.save()
                    return redirect('/login/')
            else:
                return http.HttpResponseBadRequest('两次输入的密码不同')
        else:
            return render(request, 'forgetpwd.html',
                          {'forget_form': modify_form})
Exemple #11
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get("password1", "")
         pwd2 = request.POST.get("password2", "")
         if pwd1 != pwd2:
             return JsonResponse({"status": "fail", "msg": "密码不一致"})
         user = request.user
         user.password = make_password(pwd2)
         user.save()
         return JsonResponse({"status": "success", "msg": "密码修改成功"})
     else:
         return JsonResponse({"status": "fail", "msg": "填写错误"})
Exemple #12
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get('password1', '')
         pwd2 = request.POST.get('password2', '')
         if pwd1 != pwd2:
             return JsonResponse({'status': 'fail', 'msg': '两次密码不一致'})
         user = request.user
         user.password = make_password(pwd1)
         user.save()
         return JsonResponse({'status': 'success', 'msg': '密码修改成功'})
     else:
         return JsonResponse(dict(modify_form.errors.items()), safe=False)
Exemple #13
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get('password1', '')
         pwd2 = request.POST.get('password2', '')
         if pwd1 != pwd2:
             return HttpResponse('{"status":"fail", "msg":"密码不一致"}', content_type='application/json')
         user = request.user     # 匹配用户
         user.password = make_password(pwd2)  # 对密码进行加密
         user.save()
         return HttpResponse('{"status":"success"}', content_type='application/json')
     else:
         return HttpResponse(json.dumps(modify_form.errors), content_type='application/json')
Exemple #14
0
 def post(self, request):
     UpPwdForm = ModifyPwdForm(request.POST)
     if UpPwdForm.is_valid():
         pwd1 = request.POST.get('password1', '')
         pwd2 = request.POST.get('password2', '')
         if pwd1 != pwd2:
             return JsonResponse({"status": "fail", "msg": "密码不一致"})
         user = request.user
         user.password = make_password(pwd1)
         user.save()
         return JsonResponse({"status": "success"})
     else:
         return JsonResponse(UpPwdForm.errors)
Exemple #15
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get("password1", "")
         pwd2 = request.POST.get("password2", "")
         suc_dic = {'status': "success"}
         fail_dic = {'status': "fail", "msg": u"密码不一致"}
         if pwd1 != pwd2:
             return HttpResponse(json.dumps(fail_dic), content_type="application/json")
         user = request.user
         user.password = make_password(pwd1)
         user.save()
         return HttpResponse(json.dumps(suc_dic), content_type="application/json")
     else:
         return HttpResponse(json.dumps(modify_form.errors))
Exemple #16
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get("password1", "")
         pwd2 = request.POST.get("password2", "")
         email = request.POST.get("email", "")
         if pwd1 != pwd2:
             return render(request, "password_reset.html", {"email": email, "msg":u"密码不一致"})
         user = UserProfile.objects.get(email=email)
         user.password = make_password(pwd1)
         user.save()
         return render(request, "login.html")
     else:
         email = request.POST.get("email", "")
         return render(request, "password_reset.html", {"email": email, "modify_form": modify_form})
Exemple #17
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get('password1', '')
         pwd2 = request.POST.get('password2', '')
         email = request.POST.get('email', '')
         if pwd1 != pwd2:
             return render(request, "password_reset.html", {'email': email, "msg": "密码不一致"})
         user = UserProfile.objects.get(email=email)     # 匹配用户
         user.password = make_password(pwd2)  # 对密码进行加密
         user.save()
         return render(request, "login.html")
     else:
         email = request.POST.get('email', '')
         return render(request, "password_reset.html", {'email': email, "modify_form": modify_form})
Exemple #18
0
    def post(self, request):
        modify_form = ModifyPwdForm(request.POST)
        # 我把两次密码是否相同验证放在clean方法内了
        if modify_form.is_valid():
            password = modify_form.cleaned_data.get("password")
            user = request.user
            user.password = make_password(password)
            user.save()

            return HttpResponse('{"status":"success"}',
                                content_type='application/json')
        else:
            # 两次密码不一致会在这里返回的
            return HttpResponse(json.dumps(modify_form.errors),
                                content_type='application/json')
Exemple #19
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get("password1", "")
         pwd2 = request.POST.get("password2", "")
         if pwd1 != pwd2:
             return HttpResponse("{'status':'fail','msg':'密码不一致'}",
                                 content_type='application/json')
         user = request.user
         user.password = make_password(pwd2)
         user.save()
         return HttpResponse("{'status':'success'}",
                             content_type='application/json')
     else:
         return HttpResponse(json.dumps(modify_form.errors),
                             content_type='application/json')
Exemple #20
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get('password1', '')
         pwd2 = request.POST.get('password2', '')
         email = request.POST.get('email', '')
         if pwd1 != pwd2:
             return render(request, 'password_reset.html', {'msg': '密码不一致'})
         users = UserProfile.objects.filter(email=email)
         for user in users:
             if user:
                 user.password = make_password(pwd1)
                 user.save()
         return render(request, 'login.html')
     else:
         return render(request, 'password_reset.html', locals())
Exemple #21
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get('password1')
         pwd2 = request.POST.get('password2')
         email = request.POST.get('email')
         if pwd1 != pwd2:
             return render(request, 'password_reset.html', {'msg': '密码输入不一致,请重新输入'})
         else:
             user = UserProfile.objects.get(email=email)
             user.password = make_password(pwd2)
             user.save()
             return render(request, 'login.html')
     else:
         email = request.POST.get('email')
         return render(request, 'password_reset.html', {'email': email})
Exemple #22
0
 def post(self, request):
     modifpwd_form = ModifyPwdForm(request.POST)
     if modifpwd_form.is_valid():
         # 验证密码是否一致
         password1 = request.POST.get('password1', '')
         password2 = request.POST.get('password2', '')
         if password1 != password2:
             return HttpResponse('{"status":"fail", "msg":"密码不一致",}',
                                 content_type='application/json')
         user = request.user
         user.password = make_password(password2)
         user.save()
         return HttpResponse('{"status":"success",}',
                             content_type='application/json')
     else:
         return HttpResponse('{"status":"fail", "msg":"密码输入有误"}',
                             content_type='application/json')
Exemple #23
0
    def post(self, request):
        modify_form = ModifyPwdForm(request.POST)
        if modify_form.is_valid():
            pwd1 = request.POST.get("new_password", "")
            pwd2 = request.POST.get("confirm_password", "")
            if pwd1 != pwd2:
                return HttpResponse('{"status":"fail","msg":"{error}'.format(
                    modify_form.errors),
                                    content_type='application/json')
            user = request.user
            user.password = make_password(pwd2)
            user.save()

            return HttpResponse('{"status":"success"}',
                                content_type='application/json')
        else:
            return HttpResponse(json.dumps(modify_form.errors),
                                content_type='application/json')
Exemple #24
0
def edit_pass(request):
    if request.method == 'POST':
        modify_form = ModifyPwdForm(request.POST)
        if modify_form.is_valid():
            pwd = request.POST.get('pwd', '')
            email = request.POST.get('email', '')
            user = User.objects.get(email=email)
            if user:
                user.password = make_password(pwd)
                user.save()
                return render(request, 'users/login.html')
            else:
                pass
        else:
            email = request.POST.get('email', '')
            return render(request, 'users/edit_pass.html', {'email': email, 'modify_form': modify_form,
                                                            'msg': '密码不符合要求!'})
    return render(request, 'users/edit_pass.html')
Exemple #25
0
    def post(self, request):
        modifypwd_form = ModifyPwdForm(request.POST)
        if modifypwd_form.is_valid():
            password = request.POST.get("password", "")
            password2 = request.POST.get("password2", "")
            email = request.POST.get("email", "")
            if password == password2:
                user_profile = UserProfile.objects.get(email=email)
                user_profile.password = make_password(password)
                user_profile.save()
                return render(request, "login.html")

            else:
                return render(request, 'password_reset.html', {"email": email, "msg":u'密码不一致'})

        else:
            email = request.POST.get("email", "")
            return render(request, 'password_reset.html', {"email": email, "modifypwd_form":modifypwd_form})
Exemple #26
0
    def post(self, request):
        modify_form = ModifyPwdForm(request.POST)
        if modify_form.is_valid():
            pw1 = request.POST.get('password1', '')
            pw2 = request.POST.get('password1', '')
            if pw1 != pw2:
                return HttpResponse('{"status": "fail", "msg":"密码不一致"}',
                                    content_type='application/json')
            user = request.user
            user.password = pw1
            user.save()
            return HttpResponse('{"status": "success"}',
                                content_type='application/json')
            # return render(request, "login.html", {})

        else:
            return HttpResponse(json.dumps(modify_form.errors),
                                content_type='application/json')
Exemple #27
0
    def post(self, request):
        res = {}
        modify_form = ModifyPwdForm(request.POST)
        if modify_form.is_valid():
            pwd1 = request.POST.get("password", "")
            pwd2 = request.POST.get("password2", "")

            if pwd1 != pwd2:
                res['status'] = 'fail'
                res['msg'] = '密码不一致'
                return HttpResponse(json.dumps(res), content_type='application/json')
            user = request.user
            user.password = make_password(pwd2)
            user.save()
            res['status'] = 'success'

        else:
            res = modify_form.errors
        return HttpResponse(json.dumps(res), content_type='application/json')
Exemple #28
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get("password1", "")
         pwd2 = request.POST.get("password2", "")
         # 如果两次密码不相等,返回错误信息
         if pwd1 != pwd2:
             return HttpResponse('{"status":"fail", "msg":"密码不一致"}', content_type='application/json')
         # 如果密码一致
         user = request.user
         # 加密成密文
         user.password = make_password(pwd2)
         # save 保存到数据库
         user.save()
         return HttpResponse('{"status":"success"}', content_type='application/json')
     # 验证失败说明密码位数不够
     else:
         # 通过 json 的 dumps 方法把字典转换为 json 字符串
         return HttpResponse(json.dumps(modify_form.errors), content_type='application/json')
Exemple #29
0
    def post(request):
        modify_form = ModifyPwdForm(request.POST)
        email = request.POST.get('email')
        if modify_form.is_valid():
            pwd1 = request.POST.get('password1')
            pwd2 = request.POST.get('password2')
            if pwd1 != pwd2:
                return render(request, 'password_reset.html', {
                    'email': email,
                    'msg': '密码不一致'
                })
            user = UserProfile.objects.get(email=email)
            user.password = make_password(password=pwd1)
            user.save()
            return redirect('/login/')

        return render(request, 'password_reset.html', {
            'email': email,
            'modify_form': modify_form
        })
Exemple #30
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         pwd1 = request.POST.get('password1')
         pwd2 = request.POST.get('password2')
         email = request.POST.get('email')
         if pwd1 != pwd2:
             return render(request, 'password_reset.html', {
                 'modify_form': modify_form,
                 'msg': '两次密码不一致'
             })
         user = UserProfile.objects.get(email=email)
         user.password = make_password(pwd1)
         user.save()
         return render(request, 'login.html')
     else:
         email = request.POST.get("email", "")
         return render(request, "password_reset.html", {
             "email": email,
             "modify_form": modify_form
         })