def get(self, request, active_code): # 在user_emailverifyrecord表中根据code过滤查询所有结果记录; all_record = EmailVerifyRecord.objects.filter(code=active_code) # 实例化form类,并将request参数传入; active_form = ActiveForm(request.GET) # 如果不为空也就是有用户 if all_record: for record in all_record: # 获取到对应的邮箱 email = record.email # 查找到邮箱对应的user user = UserProfile.objects.get(email=email) # 将查找到的user设置为激活状态; user.is_active = True # 做好保存; user.save() # 激活成功后跳转到登录页面 return render( request, "login.html", ) # 验证码输错时:显示错误的提醒信息,并返回至注册页面; else: return render(request, "register.html", { "msg": "您的激活链接无效", "active_form": active_form })
def get(self, request, active_code): evr = EmailVerifyRecord.objects.get(code=active_code) active_form = ActiveForm(request.GET) if evr: email = evr.email return render(request, 'password_reset.html', {"email": email}) else: return render(request, 'forgetpwd.html', { "msg": "您的重置密码链接无效,请重新请求", "active_form": active_form })
def get(self, request, active_code): all_record = EmailVerifyRecord.objects.filter(code=active_code) # 如果不为空也就是有用户 active_form = ActiveForm(request.GET) if all_record: # 获取对应的邮箱 for record in all_record: email = record.email return render(request, 'password_reset.html', {'active_code': active_code}) else: return render(request, "forgetpwd.html", { "msg": "您的重置密码链接无效,请重新请求", "active_form": active_form })
def get(self, request, active_code): active_form = ActiveForm(request.POST) # 查询邮箱验证码表中 验证码是否存在 all_record = EmailVerifyRecord.objects.filter(code=active_code) if all_record: for record in all_record: email = record.email # 把邮箱传递给 密码重置页面 return render(request, 'password_reset.html', {'email': email}) else: # 邮箱验证码表中 验证码是否存在 return render(request, 'forgetpwd.html', { 'msg': '重置密码链接无效,请重新请求', 'active_form': active_form })
def get(self, request, active_code): active_form = ActiveForm(request.GET) all_record = EmailVerifyRecord.objects.filter(code=active_code) if all_record: for record in all_record: email = record.email user = UserProfile.objects.get(email=email) user.is_active = True user.save() return render(request, 'login.html') else: return render(request, "register.html", { "msg": "您的激活链接无效", "active_form": active_form })
def get(self, request, active_code): # 查询邮箱验证记录是否存在 all_record = EmailVerifyRecord.objects.filter(code=active_code) # 如果不为空也就是有用户 active_form = ActiveForm(request.GET) if all_record: for record in all_record: # 获取到对应的邮箱 email = record.email # 将 email 传回来 # 只传回 active_code return render(request, "password_reset.html", {"active_code": active_code}) # 自己瞎输的验证码 else: return render( request, "forgetpwd.html", { "msg": "您的重置密码链接无效,请重新请求", "active_form": active_form})
def get(self, request, active_code): # 查询邮箱验证记录是否存在 all_record = EmailVerifyRecord.objects.filter(code=active_code) # 如果不为空也就是有用户 active_form = ActiveForm(request.GET) if all_record: for record in all_record: # 获取到对应的邮箱 email = record.email # 查找到邮箱对应的 user user = UserProfile.objects.get(email=email) user.is_active = True user.save() # 激活成功跳转到登录页面 return render(request, "login.html", ) # 自己瞎输的验证码 else: return render( request, "register.html", { "msg": "您的激活链接无效", "active_form": active_form})
def get(self, request, active_code): # 查询邮箱验证码表中 验证码是否存在 all_record = EmailVerifyRecord.objects.filter(code=active_code) # active_form = ActiveForm(request.GET) # 如果存在记录 if all_record: for record in all_record: # 获取对应的邮箱 email = record.email # 查找有相对应的user user = UserProfile.objects.get(email=email) user.is_active = True user.save() # 激活成功。跳到登录页面 return render(request, 'login.html', {}) else: return render(request, 'register.html', { 'msg': '您的激活链接无效', 'active_from': active_form })
def get(self, request, active_code): # 查询邮箱验证记录是否存在 all_record = EmailVerifyRecord.objects.filter(code=active_code) # 创建一个form表单的实例; active_form = ActiveForm(request.GET) # 如果不为空,即有用户; if all_record: for record in all_record: # 获取到对应的邮箱 email = record.email # 将email回显至前端页面中; # return render(request, "password_reset.html", {"email": email}) # 完善之后,只传回active_code; return render(request, "password_reset.html", {"active_code": active_code}) # 验证码输入错误; else: return render(request, "forgetpwd.html", { "msg": "链接无效,请重新请求", "active_form": active_form })
def get(self, request, active_code): # 查询邮箱验证记录是否存在 all_record = EmailVerifyRecord.objects.filter(code=active_code) # 激活form负责给激活跳转进来的人加验证码 active_form = ActiveForm(request.GET) # 如果不为空也就是有用户 if all_record: for record in all_record: # 获取到对应的邮箱 email = record.email # 查找到邮箱对应的user user = UserProfile.objects.get(email=email) user.is_active = True user.save() # 写入欢迎注册消息 user_message = UserMessage() user_message.user = user.id user_message.message = "欢迎注册玉汝于成网站!!" user_message.save() # 激活成功跳转到登录页面 return render(request, "login.html", ) # 自己瞎输的验证码 else: return render(request, "register.html", {"msg": "您的激活链接无效", "active_form": active_form})
def get(self, request): # 给忘记密码页面加上验证码 active_form = ActiveForm(request.POST) return render(request, "forgetpwd.html", {"active_form": active_form})
def get(self, request): active_form = ActiveForm(request.POST) return render(request, 'forgetpwd.html', {'active_form': active_form})