[py][mx]django通过邮箱找回密码
忘记密码处理流程
注意: 这个文章里的找回密码页面截取有问题. 找回密码页应该是让输入邮箱

直接上代码
class ActiveView(View): # 主要功能是修改user_profile里的is_active字段为1
def get(self, request, active_code):
all_reocrds = EmailVerifyRecord.objects.filter(code=active_code)
if all_reocrds:
for record in all_reocrds:
email = record.email
user = UserProfile.objects.get(email=email)
user.is_active = True
user.save()
else: # 如果激活链接不存在,则返回激活失败
return render(request, "active_faild.html")
return render(request, 'login.html')
class ForgetPwdView(View):
def get(self, request):
forget_form = ForgetPwdForm() # 返回验证码form
return render(request, 'forget_pwd.html', {'forget_form': forget_form})
def post(self, request):
forget_form = ForgetPwdForm(request.POST)
if forget_form.is_valid(): # 验证email是否有效
email = request.POST.get('email', '')
if UserProfile.objects.get(email=email): # 判断用户是否存在,然后发邮件
send_register_email(email, "forget")
return HttpResponse("重置密码链接已发送到您的邮箱,请查收后点击重置.")
else:
return render(request, 'forget_pwd.html', {'msg': '用户不存在', 'forget_form': forget_form})
class ResetPwdView(View):
def get(self, request, active_code):
all_reocrds = EmailVerifyRecord.objects.filter(code=active_code)
if all_reocrds: # 如果链接有效
for record in all_reocrds:
email = record.email # 得到email, emailsendrecord表中有对应的
return render(request, 'reset_password.html', {'email': email}) # 将email带回, post到这个view: modify_pwd
else:
return HttpResponse("链接已失效...")
# ResetPwdView的post独立到ModifyPwdView里, 因为ResetPwdView post地址不好获取code
class ModifyPwdView(View):
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', '')#取出email,定位哪个用户
if pwd1 != pwd2: # 如果密码不一致, 则返回
return render(request, 'reset_password.html', {'msg': '密码不一致', 'email': email})
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, 'reset_password.html', {'email': email, 'modify_form': modify_form})
处理逻辑


[py][mx]django通过邮箱找回密码的更多相关文章
- AspNetCore-MVC实战系列(二)之通过绑定邮箱找回密码
AspNetCore - MVC实战系列目录 . 爱留图网站诞生 . AspNetCore - MVC实战系列(一)之Sqlserver表映射实体模型 . AspNetCore-MVC实战系列(二)之 ...
- spring mvc下实现通过邮箱找回密码功能
1功能分析 通过spring mvc框架实现通过邮箱找回密码. 2 实现分析 主要是借助某个邮箱的pop3/smtp服务实现的邮件代发功能. 3 源码分析 3.1首先在用户表对应的javabean中加 ...
- django项目中使用邮箱找回密码功能
本文使用qq邮箱,需要登录邮箱,在设置-账户里面开启SMTP服务,要记下授权码 前端html {#找回密码的表单#} <form action="" method=" ...
- [py][mx]django自定义认证类-实现邮箱作为用户名登录
创建自定义验证用户名密码类CustomBackend users/views.py from django.contrib.auth import authenticate, login from d ...
- Django 邮箱找回密码!!!!!!!!!!!!!!!!
1.大概流程. @首先在完善登陆页面,增加忘记密码的链接. @为了账户安全,需要对操作者进行验证,向邮箱发随机数验证! @在重置验证码页面,验证验证码是否匹配(验证成功跳转至更改密码也页面). @ 重 ...
- [py][mx]django项目-让系统用自定义的users表认证
项目开端 参考的是mxonline项目 先把这两项完成 1.app设计 2.app的models的设计 经过分析系统有四个模块 users - 用户管理 course - 课程管理 oranizati ...
- [py][mx]django注册-邮件激活
人生,学习,就是一段旅途, 说是放弃,其实是自信心作祟. 因为不同时间段状态,譬如晚上和早上刚来状态不一样.做相同事情容器失去自信而放弃. 坚持可以打破这个魔咒 还有就是有些问题得分割, 不要让压死牛 ...
- Java实现邮箱找回密码 --转载
通过邮件找回密码功能的实现 1.最近开发一个系统,有个需求就是,忘记密码后通过邮箱找回.现在的系统在注册的时候都会强制输入邮箱,其一目的就是 通过邮件绑定找回,可以进行密码找回.通过java发送邮件的 ...
- Java实现邮箱找回密码
通过邮件找回密码功能的实现 1.最近开发一个系统,有个需求就是,忘记密码后通过邮箱找回.现在的系统在注册的时候都会强制输入邮箱,其一目的就是 通过邮件绑定找回,可以进行密码找回.通过java发送邮件的 ...
随机推荐
- SeaJS之use函数
有了 define 等模块定义规范的实现,我们可以开发出很多模块.但光有一堆模块不管用,我们还得让它们能跑起来.在 SeaJS 里,要启动模块系统很简单: <script src=”path/t ...
- es6 - class的学习
http://es6.ruanyifeng.com/#docs/class:class Person { constructor{ //构造函数,里边放不被继承的私有属性和方法 this.proper ...
- router之switch
比较路由中有无switch的区别: 代码一: <Router history={history}> <Route exact path="/" component ...
- sencha touch 常见问题解答(26-50)
26.sencha touch在华为.红米等部分手机下hide事件失效,msgbox无法关闭怎么办 答:请看http://www.cnblogs.com/cjpx00008/p/3535557.htm ...
- s3cmd在配置后使用时提示ERROR: S3 error: 403 (InvalidAccessKeyId): The AWS Access Key Id you provided does not exist in our records.
自己新建的ceph环境,下载了s3cmd来做客户端,使用了s3cmd --configure配置后,在使用s3cmd ls可以查看到所有的bucket,但s3cmd ls s3://xxx 具体buc ...
- java代码中实现android背景选择的selector-StateListDrawable的应用
首先定义一个获得StateListDrawable对象的方法: private StateListDrawable addStateDrawable(Context context, int idNo ...
- ThreadLocal Java并发
ThreadLocal 文章来源:http://con.zhangjikai.com/ThreadLocal.html ThreadLocal 主要用来提供线程局部变量,也就是变量只对当前线程可见. ...
- 【转】JavaScript 事件顺序:冒泡和捕获
补充说明:这篇文章通俗易懂地讲解了冒泡和捕获原理,原文来自 ppk 大侠的 quirksmode 站点.感谢网友 hh54188 的翻译. 事件的发生顺序 这个问题的起源非常简单,假设你在一个元素中又 ...
- C++ Error: no appropriate default constructor available
我定义了一个结构体,然后初始化它,结果编译报错 no appropriate default constructor available 代码如下: struct matrixXvect_func { ...
- redis -clock_gettime问题
/home/wm/redis-/deps/jemalloc/src/nstime.c:: undefined reference to `clock_gettime' 这个错误 解决思路如下 .查找实 ...