图片 25

office永恒版要700值吗,教你怎么着激活新计算机上自带的免费office

By admin in 办公软件 on 2019年5月6日

问题:官方恒久版700多,只可以装在壹台Computer上,换系统后好迁移吗?盗版的word,wps难点太多了,想用正版的。

Django+xadmin构建在线教育平台(3),djangoxadmin

一、
先把计算机互连网连接上,然后随意展开二个word文件,会唤醒登入,依照第贰步提醒从操作

回答:

5、用户注册

 要害完成效益

  • 用户输入邮箱、密码和验证码,点注册按键
  • 假如输入的不正确,提醒错误音讯
  • 比如没有错,发送激活邮件,用户通过邮件激活后技艺登录
  • 尽管注册功用,未有激活的用户也不能登入

2、张开任性Office组件,要是已有微软账户请直接登入;未有微软帐号请创制账户,可通过邮箱或手机号注册。

京东有其它代理商的500上下就能够,不想每八个月激活可能忧郁激活的可能隐患(比方安全软件报警之类),值得出手,反正只要excel、word、ppt足矣,多出去的onenote也没几人用。该版本绑定邮箱,现在凭邮箱作为激活凭证,有事能够找贩卖代理大概直接找微软客服

五.壹.起来视图

users/views.py

class RegisterView(View):
    '''用户注册'''
    def get(self,request):
        return render(request,'register.html')

 用户以get格局,直接回到注册页面

图片 1

伍.2.路由统一策动

# MxOnline/urls.py

from users.views import RegisterView


    path('register/',RegisterView.as_view(),name = 'register'),

urls中。通过类的as_view方法,调用这些View类

3、选拔登陆,输入微软账户以激活Office。

5.3.模板修改

修改index.html

点 “注册 ”应该跳到用户注册页面

 <a style="color:white" class="fr registerbtn" href="/register/">注册</a>

 <a style="color:white" class="fr loginbtn" href="/login/">登录</a>

修改register.html中的静态文件地方

{% load staticfiles %}

<link rel="stylesheet" type="text/css" href="{%%20static%20'css/reset.css'%20%}">
    <link rel="stylesheet" type="text/css" href="{%%20static%20'css/login.css'%20%}">

.
.
.

<script src="{%%20static%20'js/jquery.min.js'%20%}" type="text/javascript"></script>
<script src="{%%20static%20'js/unslider.js'%20%}" type="text/javascript"></script>
<script src="{%%20static%20'js/validateDialog.js'%20%}"  type="text/javascript"></script>
<script src="{%%20static%20'js/login.js'%20%}"  type="text/javascript"></script>

测试一下从index界面点注册能否跳到register分界面

图片 2

图片 3

 5.4.验证码

 验证码库:django-simple-captcha,这其间有介绍这些第二方库的施用方法

 安装:

pip install  django-simple-captcha

Add captcha to the INSTALLED_APPS in your settings.py

INSTALLED_APPS = [
    'captcha',
]

Add an entry to your urls.py:

urlpatterns = [
    path('captcha/',include('captcha.urls')),
]

扭转到数据库

python manage.py makemigrations

python manage.py migrate

可以看来数据库多了一张表

图片 4

 

 在登记页面显示验证码

 定义大家的register form:

# users/forms.py

from captcha.fields import CaptchaField

class RegisterForm(forms.Form):
    '''注册验证表单'''    
    email = forms.EmailField(required=True)
    password = forms.CharField(required=True,min_length=5)
    # 验证码,字段里面可以自定义错误提示信息
    captcha = CaptchaField()

图片 5#
users/forms.py from django import forms from captcha.田野先生s import
CaptchaField class LoginForm(forms.Form): ”’登6验证表单”’ username =
forms.CharField(required=True) password =
forms.CharField(required=True,min_length=5) class
RegisterForm(forms.Form): ”’注册认证表单”’ email =
forms.EmailField(required=True) password =
forms.CharField(required=True,min_length=5) # 验证码 captcha =
CaptchaField(error_messages={‘invalid’:’验证码错误’}) forms.py

通过{{ register_form.captcha }}获取验证码

<div class="form-group marb8 captcha1 ">
     <label>验&nbsp;证&nbsp;码</label>
     {{ register_form.captcha }}
</div>

图片 6

图片 7

 

图片 8

 伍.5.完善注册的后台逻辑

class RegisterView(View):
    '''用户注册'''
    def get(self,request):
        register_form = RegisterForm()
        return render(request,'register.html',{'register_form':register_form})

    def post(self,request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            user_name = request.POST.get('email', None)
            # 如果用户已存在,则提示错误信息
            if UserProfile.objects.filter(email = user_name):
                return render(request, 'register.html', {'register_form':register_form,'msg': '用户已存在'})

            pass_word = request.POST.get('password', None)
            # 实例化一个user_profile对象
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            user_profile.is_active = False
            # 对保存到数据库的密码加密
            user_profile.password = make_password(pass_word)
            user_profile.save()
            send_register_eamil(user_name,'register')
            return render(request,'login.html')
        else:
            return render(request,'register.html',{'register_form':register_form})

图片 9#
users/views.py from django.shortcuts import render from
django.contrib.auth import authenticate,login from
django.contrib.auth.backends import ModelBackend from .models import
UserProfile,EmailVerifyRecord from django.db.models import Q from
django.views.generic.base import View from .forms import
LoginForm,RegisterForm from django.contrib.auth.hashers import
make_password from utils.email_send import send_register_eamil
#邮箱和用户名都能够登入 # 基础ModelBackend类,因为它有authenticate方法
class CustomBackend(ModelBackend): def authenticate(self, request,
username=None, password=None, **kwargs): try: #
不期望用户存在八个,get只好有一个。五个是get败北的1种原因
Q为利用并集查询 user =
UserProfile.objects.get(Q(username=username)|Q(email=username)) #
django的后新北密码加密:所以不能够password==password #
UserProfile继承的AbstractUser中有def check_password(self,
raw_password): if user.check_password(password): return user except
Exception as e: return None class LoginView(View): ”’用户登入”’ def
get(self,request): return render(request, ‘login.html’) def
post(self,request): # 实例化 login_form = LoginForm(request.POST) if
login_form.is_valid(): # 获取用户提交的用户名和密码 user_name =
request.POST.get(‘username’, None) pass_word =
request.POST.get(‘password’, None) # 成功再次回到user对象,退步None user =
authenticate(username=user_name, password=pass_word) #
要是还是不是null表达验证成功 if user is not None: if user.is_active: #
唯有登记激活技术登六 login(request, user) return render(request,
‘index.html’) else: return render(request, ‘login.html’, {‘msg’:
‘用户名或密码错误’, ‘login_form’: login_form}) #
唯有当用户名或密码不存在时,才回去错误消息到前端 else: return
render(request, ‘login.html’, {‘msg’:
‘用户名或密码错误’,’login_form’:login_form}) #
form.is_valid()已经看清非法了,所以这边无需再再次回到错误音信到前端了
else: return render(request,’login.html’,{‘login_form’:login_form}) #
激活用户 class ActiveUserView(View): def get(self, request,
active_code): # 查询邮箱验证记录是或不是存在 all_record =
EmailVerifyRecord.objects.filter(code = active_code) if all_record:
for record in all_record: # 获取到相应的信箱 email = record.email #
查找到邮箱对应的user user = UserProfile.objects.get(email=email)
user.is_active = True user.save() # 验证码不对的时候跳转到激活战败页面
else: return render(request,’active_fail.html’) #
激活成功跳转到登入页面 return render(request, “login.html”, ) class
RegisterView(View): ”’用户注册”’ def get(self,request): register_form
= RegisterForm() return
render(request,’register.html’,{‘register_form’:register_form}) def
post(self,request): register_form = RegisterForm(request.POST) if
register_form.is_valid(): user_name = request.POST.get(’email’, None)
# 借使用户已存在,则提醒错误音讯 if UserProfile.objects.filter(email =
user_name): return render(request, ‘register.html’,
{‘register_form’:register_form,’msg’: ‘用户已存在’}) pass_word =
request.POST.get(‘password’, None) # 实例化3个user_profile对象
user_profile = UserProfile() user_profile.username = user_name
user_profile.email = user_name user_profile.is_active = False #
对保留到数据库的密码加密 user_profile.password =
make_password(pass_word) user_profile.save()
send_register_eamil(user_name,’register’) return
render(request,’login.html’) else: return
render(request,’register.html’,{‘register_form’:register_form}) views.py所以代码

说明:

  • 若果是get请求,直接再次回到注册页面给用户
  • 假诺若post请求,先生成3个表单实例,并获得用户提交的具备音信(request.POST)
  • is_valid()方法,验证用户的交由新闻是或不是法定
  • 假如官方,获取用户提交的email和password
  • 实例化一个user_profile对象,把用户拉长到数据库
  • 私下认可增加的用户是激活状态(is_active=一表示True),在那边我们修改默许的情事(改为is_active
    = False),唯有用户去邮箱激活之后才改为True
  • 对密码加密,然后保留,发送邮箱,username是用户注册的信箱,‘register’申明是挂号
  • 登记成功跳转到登6分界面

四、选取你的国家/地区和语言,并单击”下一步”。Windows与Office的言语建议保持1致。

5.陆.发送激活邮件

在Python中已经嵌入了3个smtp邮件发送模块,Django在此基础上开始展览了归纳地包裹,让我们在Django意况中得以更便利越来越灵敏的殡葬邮件。

抱有的功用都在django.core.mail中。

第二settings里面设置

# settings.py

EMAIL_HOST = "smtp.qq.com"  # SMTP服务器主机
EMAIL_PORT = 25             # 端口
EMAIL_HOST_USER = "[email protected]"       # 邮箱地址
EMAIL_HOST_PASSWORD = "dwjybikexxxxxxxx"    # 密码
EMAIL_USE_TLS= True
EMAIL_FROM = "[email protected]"            # 邮箱地址

说明:

   EMAIL_HOST = “smtp.qq.com”

   EMAIL_HOST_PASSWORD = “dwjybikexxxxxxxx”

要想用qq邮箱作为服务器发送邮件,必须先开启SMTP,方法如下:

一)登入邮箱,找到“设置”–>>“用户”

图片 10

二)往下拉找到SMTP服务,点拉开,然后点“生成授权码”

图片 11

三)能够阅览授权码,“EMAIL_HOST_PASSWOLacrosseD”里面填写的正是下不熟悉成的授权码,而不是你的信箱密码

 图片 12

在apps目录新建package utils,然后新建3个email_send.py文件

图片 13

# apps/utils/email_send.py

from random import Random
from django.core.mail import send_mail

from users.models import EmailVerifyRecord
from MxOnline.settings import EMAIL_FROM

# 生成随机字符串
def random_str(random_length=8):
    str = ''
    # 生成字符串的可选字符串
    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
    length = len(chars) - 1
    random = Random()
    for i in range(random_length):
        str += chars[random.randint(0, length)]
    return str

# 发送注册邮件
def send_register_eamil(email, send_type="register"):
    # 发送之前先保存到数据库,到时候查询链接是否存在
    # 实例化一个EmailVerifyRecord对象
    email_record = EmailVerifyRecord()
    # 生成随机的code放入链接
    code = random_str(16)
    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type

    email_record.save()

    # 定义邮件内容:
    email_title = ""
    email_body = ""

    if send_type == "register":
        email_title = "NBA注册激活链接"
        email_body = "请点击下面的链接激活你的账号: http://127.0.0.1:8000/active/{0}".format(code)

        # 使用Django内置函数完成邮件发送。四个参数:主题,邮件内容,发件人邮箱地址,收件人(是一个字符串列表)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        # 如果发送成功
        if send_status:
            pass

 官方文书档案:

def send_mail(subject, message, from_email, recipient_list,
              fail_silently=False, auth_user=None, auth_password=None,
              connection=None, html_message=None):

前方多个参数必要求,前面包车型客车参数可感到空

出殡电子邮件的最简易方法是使用 django.core.mail.send_mail()

subjectmessagefrom_emailrecipient_list参数是不可缺少的。

  • subject:二个字符串。
  • message:2个字符串。
  • from_email:1个字符串。
  • recipient_list:字符串列表,每一个字符串都以电子邮件地址。每一种成员都recipient_list将要电子邮件的“收件人:”字段中看出其余收件人。
  • fail_silently:一个布尔值。假使是的话Falsesend_mail会提出三个smtplib.SMTPException。有关smtplib或许的不等列表,请参阅文书档案,全体这个分化都以。的子类 SMTPException
  • auth_user:用于向SMTP服务器举行身份验证的可选择户名。假如未有提供,Django将使用该EMAIL_HOST_USER安装的值 。
  • auth_password:用于验证SMTP服务器的可选密码。假诺未有提供,Django将使用该EMAIL_HOST_PASSWORD安装的值 。
  • connection:用于发送邮件的可选电子邮件后端。借使未钦命,将选择私下认可后端的实例。有关 愈多详细新闻,请参阅电子邮件后端的文书档案。
  • html_message:如果html_message被提供,所获得的电子邮件将是三个 多一些/取代电子邮件message用作 文本/无格式内容类型和html_message用作 text
    / html的内容类型。

再次回到值将是打响传送音讯的多少(能够是01因为它只可以发送一条音讯)。

 5.7.激活用户

依据邮箱找到呼应的用户,然后设置is_active = True来实现

# 激活用户
class ActiveUserView(View):
    def get(self, request, active_code):
        # 查询邮箱验证记录是否存在
        all_record = EmailVerifyRecord.objects.filter(code = active_code)

        if all_record:
            for record in all_record:
                # 获取到对应的邮箱
                email = record.email
                # 查找到邮箱对应的user
                user = UserProfile.objects.get(email=email)
                user.is_active = True
                user.save()
         # 验证码不对的时候跳转到激活失败页面
        else:
            return render(request,'active_fail.html')
        # 激活成功跳转到登录页面
        return render(request, "login.html", )

 在templates目录下创设 active_fail.html,代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p style="color: red;">链接失效</p>
</body>
</html>

 

激活邮箱的邮件如下:

图片 14

 

修改login视图

增添一个剖断,用户注册的后,等激活才具登录

图片 15

图片 16#
users/views.py from django.shortcuts import render from
django.contrib.auth import authenticate,login from
django.contrib.auth.backends import ModelBackend from .models import
UserProfile,EmailVerifyRecord from django.db.models import Q from
django.views.generic.base import View from .forms import
LoginForm,RegisterForm from django.contrib.auth.hashers import
make_password from utils.email_send import send_register_eamil
#邮箱和用户名都能够登入 # 基础ModelBackend类,因为它有authenticate方法
class CustomBackend(ModelBackend): def authenticate(self, request,
username=None, password=None, **kwargs): try: #
不愿意用户存在七个,get只好有贰个。八个是get战败的1种原因
Q为运用并集查询 user =
UserProfile.objects.get(Q(username=username)|Q(email=username)) #
django的后台北密码加密:所以不能够password==password #
UserProfile继承的AbstractUser中有def check_password(self,
raw_password): if user.check_password(password): return user except
Exception as e: return None class LoginView(View): ”’用户登6”’ def
get(self,request): return render(request, ‘login.html’) def
post(self,request): # 实例化 login_form = LoginForm(request.POST) if
login_form.is_valid(): # 获取用户提交的用户名和密码 user_name =
request.POST.get(‘username’, None) pass_word =
request.POST.get(‘password’, None) # 成功重返user对象,战败None user =
authenticate(username=user_name, password=pass_word) #
假使不是null表明验证成功 if user is not None: if user.is_active: #
唯有登记激活工夫登入 login(request, user) return render(request,
‘index.html’) else: return render(request, ‘login.html’, {‘msg’:
‘用户名或密码错误’, ‘login_form’: login_form}) #
唯有当用户名或密码不存在时,才回去错误消息到前端 else: return
render(request, ‘login.html’, {‘msg’:
‘用户名或密码错误’,’login_form’:login_form}) #
form.is_valid()已经看清非法了,所以那边不须要再再次回到错误音信到前端了
else: return render(request,’login.html’,{‘login_form’:login_form}) #
激活用户的view class ActiveUserView(View): def get(self, request,
active_code): # 查询邮箱验证记录是还是不是存在 all_record =
EmailVerifyRecord.objects.filter(code = active_code) 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”: “您的激活链接无效”}) class
RegisterView(View): ”’用户注册”’ def get(self,request): register_form
= RegisterForm() return
render(request,’register.html’,{‘register_form’:register_form}) def
post(self,request): register_form = RegisterForm(request.POST) if
register_form.is_valid(): user_name = request.POST.get(’email’, None)
pass_word = request.POST.get(‘password’, None) #
实例化3个user_profile对象 user_profile = UserProfile()
user_profile.username = user_name user_profile.email = user_name
user_profile.is_active = False # 对封存到数据库的密码加密
user_profile.password = make_password(pass_word) user_profile.save()
send_register_eamil(user_name,’register’) return
render(request,’login.html’) else: return
render(request,’register.html’,{‘register_form’:register_form}) views.py

修改register.html

 <form id="email_register_form" method="post" action="{% url 'register' %}" autocomplete="off">
                        <input type='hidden' name='csrfmiddlewaretoken' value='gTZljXgnpvxn0fKZ1XkWrM1PrCGSjiCZ' />
                        <div class="form-group marb20 {% if login_form.errors.email %}errorput{% endif %}">
                            <label>邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱</label>
                            <input  type="text" id="id_email" name="email" value="{{ register_form.email.value }}" placeholder="请输入您的邮箱地址" />
                        </div>
                        <div class="form-group marb8 {% if login_form.errors.password %}errorput{% endif %}">
                            <label>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码</label>
                            <input type="password" id="id_password" name="password"  value="{{ register_form.password.value }}" placeholder="请输入6-20位非中文字符密码" />
                        </div>
                        <div class="form-group marb8 captcha1 {% if login_form.errors.captchal %}errorput{% endif %}">
                            <label>验&nbsp;证&nbsp;码</label>
                            {{ register_form.captcha }}
                        </div>
                        <div class="error btns" id="jsEmailTips">
                            {% for key,error in register_form.errors.items %}
                                {{ error }}
                            {% endfor %}
                            {{ msg }}
                        </div>
                        <div class="auto-box marb8">
                        </div>
                        <input class="btn btn-green" id="jsEmailRegBtn" type="submit" value="注册并登录" />
                    <input type='hidden' name='csrfmiddlewaretoken' value='5I2SlleZJOMUX9QbwYLUIAOshdrdpRcy' />
                    {% csrf_token %}
                    </form>

 修改的地方表明:

  • value=”{{ register_form.email.value }}

  • value=”{{ register_form.password.value }} 注册的用户毫无再手动输入3次邮箱和密码了

  • {% if login_form.errors.email %}errorput{% endif %}

  • {% if login_form.errors.password %}errorput{% endif %}

  • {% if login_form.errors.captchal %}errorput{% endif %} 提醒错误消息并展现红框框

  • {{ register_form.captcha }} 展现验证码

增多邮件激活的url

# MxOnline/urls.py

import xadmin

from django.urls import path,include,re_path

from django.views.generic import TemplateView
from users.views import LoginView,RegisterView,ActiveUserView


urlpatterns = [
    path('xadmin/', xadmin.site.urls),
    path('', TemplateView.as_view(template_name='index.html'),name='index'),
    path('login/',LoginView.as_view(),name = 'login'),
    path('register/',RegisterView.as_view(),name = 'register'),
    path('captcha/',include('captcha.urls')),
    re_path('active/(?P<active_code>.*)/',ActiveUserView.as_view(),name='user_active'),
]

图片 17

 

伍、激活进程中,不一致账户状态或操作情景不一致在此步骤提醒的分界面会有所差别,新注册MSA或未绑定自便Office产品的MSA,激活时提示账户已更新,Office即被激活。

陆、找回密码

注重必要贯彻的功用:

  • 用户点“忘记密码”,跳到找回密码页面
  • 在forgetpwd页面,输入邮箱和验证码成功后,发送邮件提示
  • 透过点击邮件链接,可以重新设置密码
  • 两回密码输的正确精确后,密码更新成功,跳到登入分界面

图片 18

陆.1.路由规划

from users.views import ForgetPwdView

urlpatterns = [
    path('forget/',ForgetPwdView.as_view(),name='forget_pwd'),
]

陆.二.从头视图函数

先是也亟需个表单

forms.py

class ForgetPwdForm(forms.Form):
    '''忘记密码'''
    email = forms.EmailField(required=True)
    captcha = CaptchaField(error_messages={'invalid': '验证码错误'})

视图函数

class ForgetPwdView(View):
    '''找回密码'''
    def get(self,request):
        forget_form = ForgetPwdForm()
        return render(request,'forgetpwd.html',{'forget_form':forget_form})

 

get格局,直接重临忘记密码的表单

6.3.模板修改

修改login.html中的url

<a class="fr" href="{%%20url%20'forget_pwd'%20%}">忘记密码?</a>

把forgetpwd.html拷贝到templates文件下

修改静态文件路线

来得验证码

 <div class="form-group captcha1 marb38">
     <label>验&nbsp;证&nbsp;码</label>
     {{ forget_pwd.captcha }}
 </div>

图片 19

 

陆.4.增加发送找回密码邮件

修改utils/email_send.py

发送类型为“forget”

    if send_type == "forget":
        email_title = "NBA找回密码链接"
        email_body = "请点击下面的链接找回你的密码: http://127.0.0.1:8000/reset/{0}".format(code)

        # 使用Django内置函数完成邮件发送。四个参数:主题,邮件内容,从哪里发,接受者list
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        # 如果发送成功
        if send_status:
            pass

图片 20#
apps/utils/email_send.py from random import Random from
django.core.mail import send_mail from users.models import
EmailVerifyRecord from MxOnline.settings import EMAIL_FROM #
生成自由字符串 def random_str(random_length=8): str = ” #
生成字符串的可选字符串 chars =
‘AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQq翼虎rSsTtUuVvWwXxYyZz0123456789’ length
= len(chars) – 壹 random = Random() for i in range(random_length): str
+= chars[random.randint(0, length)] return str # 发送注册邮件 def
send_register_eamil(email, send_type=”register”): #
发送以前先保存到数据库,到时候查询链接是或不是存在 #
实例化贰个EmailVerifyRecord对象 email_record = EmailVerifyRecord() #
生成自由的code放入链接 code = random_str(16) email_record.code = code
email_record.email = email email_record.send_type = send_type
email_record.save() # 定义邮件内容: email_title = “” email_body = “”
if send_type == “register”: email_title = “National Basketball Association注册激活链接”
email_body = “请点击上面包车型地铁链接激活你的账号:
) #
使用Django内置函数完结邮件发送。几个参数:主题,邮件内容,从哪里发,接受者list
send_status = send_mail(email_title, email_body, EMAIL_FROM,
[email]) # 假若发送成功 if send_status: pass if send_type ==
“forget”: email_title = “美国篮球专门的工作联赛找回密码链接” email_body =
“请点击上边包车型客车链接找回你的密码:
) #
使用Django内置函数完结邮件发送。多个参数:核心,邮件内容,从哪个地方发,接受者list
send_status = send_mail(email_title, email_body, EMAIL_FROM,
[email]) # 借使发送成功 if send_status: pass email_send.py

陆.5.完美找回密码的views

class ForgetPwdView(View):
    '''找回密码'''
    def get(self,request):
        forget_form = ForgetPwdForm()
        return render(request,'forgetpwd.html',{'forget_form':forget_form})

    def post(self,request):
        forget_form = ForgetPwdForm(request.POST)
        if forget_form.is_valid():
            email = request.POST.get('email',None)
            send_register_eamil(email,'forget')
            return render(request, 'send_success.html')
        else:
            return render(request,'forgetpwd.html',{'forget_form':forget_form})

用户提交邮箱后,提示成功发送邮件

新建templates/send_success.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p>邮件已发送,请注意查收</p>
</body>
</html>

修改forgetpwd.html

 <form id="jsFindPwdForm" method="post" action="{%%20url%20'forget_pwd'%20%}" autocomplete="off">
                    <input type='hidden' name='csrfmiddlewaretoken' value='mymQDzHWl2REXIfPMg2mJaLqDfaS1sD5'/>
                    <div class="form-group marb20 {% if forget_from.errors.email %}errorput{% endif %}">
                        <label>帐&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
                        <input type="text" id="account" name="email" value="{{ forget_from.email.value }}"
                               placeholder="邮箱"/>
                    </div>
                    <div class="form-group captcha1 marb38 {% if forget_from.errors.captchal %}errorput{% endif %}">
                        <label>验&nbsp;证&nbsp;码</label>
                        {{ forget_form.captcha }}
                    </div>
                    <div class="error btns" id="jsForgetTips">
                        {% for key,error in forget_from.errors.items %}
                            {{ error }}
                        {% endfor %}
                        {{ msg }}
                    </div>
                    <input type="hidden" name="sms_type" value="1">
                    <input class="btn btn-green" id="jsFindPwdBtn" type="submit" value="提交"/>
                    <p class="form-p" style="bottom:40px;">您还可以<a href="login.html"> [直接登录]</a></p>
                    <input type='hidden' name='csrfmiddlewaretoken' value='5I2SlleZJOMUX9QbwYLUIAOshdrdpRcy'/>
                    {% csrf_token %}
                </form>

测试一下,输入邮箱和验证码看能还是不能接受邮件

图片 21

 

陆.6.复位密码

(一)重新初始化密码激活邮箱的url

 re_path('reset/(?P<active_code>.*)/', ResetView.as_view(), name='reset_pwd'),

(2)写复位密码(get格局)后台逻辑

class ResetView(View):
    def get(self, request, active_code):
        all_records = EmailVerifyRecord.objects.filter(code=active_code)
        if all_records:
            for record in all_records:
                email = record.email
                return render(request, "password_reset.html", {"email":email})
        else:
            return render(request, "active_fail.html")
        return render(request, "login.html")

(三)创设修改密码的form表单

class ModifyPwdForm(forms.Form):
    '''重置密码'''
    password1 = forms.CharField(required=True, min_length=5)
    password2 = forms.CharField(required=True, min_length=5)

(4)修改密码的url

下面十分是激活邮箱的url,有active_code参数,只可以写get方式的逻辑。

此间不可不独立新建一个修改密码的url,因为借使以post格局提交的话,post提交的地方跟get格局(url中要求active_code参数)的地点不相同等,action=”{%
url ‘modify_pwd’ %}

path('modify_pwd/', ModifyPwdView.as_view(), name='modify_pwd'),

(伍)修改密码的后台逻辑

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", "")
            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 })

(6)修改password_reset.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <title>密码修改</title>
    <link rel="stylesheet" type="text/css" href="/static/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/static/css/animate.css">
    <link rel="stylesheet" type="text/css" href="/static/css/style.css">

<body>
<div class="wp">
    <div class="resetpassword" id="resetPwdForm">
        <h1>修改密码</h1>
        <p>已经通过验证,请设置新密码</p>
        <form id="reset_password_form" action="{% url 'modify_pwd' %}" method="post">
            <ul>
                <li class="{% if modify_form.errors.password1 %}errorput{% endif %}">
                    新 密 码 :
                    <input type="password" name="password1" id="pwd" placeholder="6-20位非中文字符">
                    <i></i>
                </li>
                <input type="hidden" name="email" value="{{ email }}">
                <li class="{% if modify_form.errors.password2 %}errorput{% endif %}">
                    确定密码:
                    <input type="password" name="password2" id="repwd" placeholder="6-20位非中文字符">
                    <i></i>
                </li>
                <div class="error btns" id="jsPasswdResetTips">
                    {% for key,error in modify_form.errors.items %}{{ key }}:{{ error }}{% endfor %}{{ msg }}</div>
                <li class="button">
                    <input type="submit" value="提交">
                </li>
            </ul>
            {% csrf_token %}
        </form>
    </div>
    <div class="resetpassword" id="reset_password_tips" style="display:none;">
        <h1>修改密码成功,请重新登录</h1>
        <img class="fl" src="/static/images/check2.png">
        <p class="successword">已经成功修改密码,请重新登录</p>
    </div>
</div>
</body>
</html>

看一下百分之百工艺流程有没不平日

先是在login界面点“忘记密码”,跳到forget页面

 图片 22

 

 图片 23

然后填上要找回密码的邮箱和验证码,提交后会收到邮件

图片 24

点击链接,跳到修改密码页面

图片 25

修改密码后,跳转到login页面

 

             Django+xadmin创设在线教育平台(二)               
  Django+xadmin创设在线教育平台(一)

 

伍、用户注册 主要达成效益 用户输入邮箱、密码和验证码,点注册按键假诺输入的不科学…

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 澳门新葡亰官网app 版权所有