Пример #1
0
 def post(self, request):
     forget_form = ForgetPwdForm()
     banners = Banner.objects.filter(type=3).order_by("index")
     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", "")
         active_code = request.POST.get("active_code", "")
         if pwd1 != pwd2:
             return render(
                 request, "password_reset.html", {
                     "email": email,
                     "active_code": active_code,
                     "msg": "两次输入密码不一致!"
                 })
         all_records = EmailVerifyRecord.objects.filter(
             code=active_code).last()
         if all_records.email != email:
             all_records.delete()
             return render(
                 request, 'forgetpwd.html', {
                     'forget_form': forget_form,
                     'msg': '发生未知错误,请再次发送邮件',
                     "banners": banners
                 })
         user = UserProfile.objects.filter(email=email).first()
         if user:
             user.set_password(pwd2)
             user.save()
         else:
             user_profile = UserProfile()
             user_profile.username = email
             user_profile.email = email
             user_profile.is_active = True
             user_profile.set_password(pwd2)
             user_profile.save()
         login_form = LoginForm()
         banners = Banner.objects.filter(type=3).order_by("index")
         all_records.delete()
         return render(request, "login.html", {
             'msg': '密码成功重置',
             'login_form': login_form,
             "banners": banners
         })
     else:
         email = request.POST.get("email", "")
         active_code = request.POST.get("active_code", "")
         return render(
             request, "password_reset.html", {
                 "email": email,
                 "active_code": active_code,
                 "modify_form": modify_form
             })
Пример #2
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     if modify_form.is_valid():
         password1 = request.POST.get('password1', '')
         password2 = request.POST.get('password2', '')
         if password1 != password2:
             return HttpResponse('{"status":"","msg":"密码不一致!"}',
                                 content_type='application/json')
         user = request.user
         user.password = make_password(password1)
         user.save()
         return HttpResponse('{"status":"success","msg":"修改成功!"}',
                             content_type='application/json')
     else:
         return HttpResponse(json.dumps(modify_form.errors),
                             content_type='application/json')
Пример #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(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 })
Пример #4
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')
Пример #5
0
 def post(self, request):
     modify_form = ModifyPwdForm(request.POST)
     email = request.POST.get('email', '')
     if modify_form.is_valid():
         password1 = request.POST.get('password1', '')
         password2 = request.POST.get('password2', '')
         if password1 != password2:
             return render(request, 'password_reset.html', {
                 'email': email,
                 'msg': '密码不一致!'
             })
         user = UserProfile.objects.get(email=email)
         user.password = make_password(password1)
         user.save()
         return render(request, 'login.html')
     else:
         return render(request, 'password_reset.html', {
             'email': email,
             'modify_form': modify_form
         })
Пример #6
0
    def post(self, request):
        modify_form = ModifyPwdForm(request.POST)
        res = dict()

        if modify_form.is_valid():
            pwd1 = request.POST.get('password1', '')
            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'
            res['msg'] = '密码修改成功'
        else:
            res = modify_form.errors

        return HttpResponse(json.dumps(res), content_type='application/json')
Пример #7
0
    def post(self, request):
        modifypwd_form = ModifyPwdForm(request.POST)
        print(333333)
        if modifypwd_form.is_valid():

            pwd1 = request.POST.get("pwd1", "")
            pwd2 = request.POST.get("pwd2", "")
            email = request.POST.get("email", "")
            if pwd1 != pwd2:
                messages.error(request, "密码不一致!")
                return render(request, "password_reset.html", {
                    "email": email,
                    "msg": "密码不一致!"
                })
            else:
                user = UserProfile.objects.get(email=email)
                user.password = make_password(pwd1)
                user.save()

                message = UserMessage()
                message.user = user
                message.messgae = "密码修改成功!"
                message.has_read = False
                message.save()

                EmailVerifyRecord.objects.filter(email=email).delete()
                messages.info(request, "密码修改成功!")
                return render(request, "login.html")

        else:
            email = request.POST.get("email", "")
            messages.error(request, "密码长度过短!")
            return render(request, "password_reset.html", {
                "email": email,
                "msg": "密码长度过短!"
            })