modify login register and forgetpws

This commit is contained in:
wrmswindmill 2018-07-17 08:51:03 +08:00
parent f48b3ec682
commit 8d879c8389
6 changed files with 101 additions and 112 deletions

View File

@ -13,7 +13,7 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
import sys
import os
DOMAIN_URL="http://localhost:8000"
DOMAIN_URL="http://120.132.101.149:8000"
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -60,15 +60,19 @@ INSTALLED_APPS = [
# 验证码
'captcha',
# 微信登陆
'allauth.socialaccount.providers.weixin',
#'allauth.socialaccount.providers.weixin',
# 微博登陆
'allauth.socialaccount.providers.weibo',
#'allauth.socialaccount.providers.weibo',
# github登陆
'allauth.socialaccount.providers.github',
#'allauth.socialaccount.providers.github',
# debug_toolbar
'debug_toolbar',
#'debug_toolbar',
# 扩展插件
'django_extensions',
#'django_extensions',
# # package:django-users
# 'django.contrib.sites',
# 'users',
]

View File

@ -15,8 +15,8 @@ class RegisterForm(forms.Form): # 注册
class ForgetPwdForm(forms.Form): #忘记密码
email = forms.CharField(required=True)
captcha = CaptchaField(error_messages={"invalid": u"验证码错误"})
password = forms.CharField(required=True, min_length=5)
class UserInfoForm(forms.Form):
class Meta:
model = User

View File

@ -84,7 +84,7 @@ class RegisterView(View):
from .tasks import send_type_email
send_type_email(user_name,'register')
# send_type_email.delay(user_name, 'register')
return render(request, 'users/login.html')
return render(request, 'users/email_send_success.html')
else:
return render(request, 'users/register.html', {'register_form': register_form})
@ -209,20 +209,43 @@ class LogoutView(View):
logout(request)
return HttpResponseRedirect(reverse('index'))
class Send_ForgetPwd_Email_View(View):
#获得当前的邮件名
from .tasks import send_type_email
# send_type_email(email, 'forget')
pass
class ForgetPwdView(View):
def get(self, request):
forget_form = ForgetPwdForm()
return render(request, 'users/forget_pwd.html',{'forget_form':forget_form})
def get(self, request):
email = request.POST.get("email",'')
return render(request, 'users/forget_pwd.html',{'email':email})
# FIXME
def post(self, request):
forget_form = ForgetPwdForm(request.POST)
forget_form = ForgetPwdForm(request.POST)
if forget_form.is_valid():
email = request.POST.get('email', '')
from .tasks import send_type_email
send_type_email(email, 'forget')
return render(request, 'users/email_send_success.html')
print(email)
try:
user = User.objects.get(email=email)
pwd1 = request.POST.get('password', '')
print(pwd1)
pwd2 = request.POST.get('password2', '')
print(pwd2)
if pwd1 != pwd2:
return render(request, 'users/forget_pwd.html', {
'email': email,
'msg': '密码不一样'
})
else:
user.password = make_password(pwd1)
user.save()
print(1111)
return render(request, 'users/modifypwd_success.html')
except:
return render(request, 'users/forget_pwd.html', {
'email': email,
'msg': '邮箱未注册'
})
else:
return render(request, 'users/', {'forget_form': forget_form})
return render(request, 'users/forget_pwd.html', {'forget_form': forget_form})

View File

@ -1,103 +1,55 @@
{% extends 'shared/base.html' %}
{% load staticfiles %}
{% block title %}
登陆
Register
{% endblock %}
{% block custom_css %}
<link rel="stylesheet" type="text/css" href="{% static 'css/register.css' %}">
{% endblock %}
{% block content %}
<div class="successbox dialogbox" id="jsSuccessTips">
<h1>成功提交</h1>
<div class="close jsCloseDialog"><img src="{% static 'image/dig_close.png' %}"/></div>
<div class="cont">
<h2>您的需求提交成功!</h2>
<p></p>
</div>
</div>
<div class="resetpassbox dialogbox" id="jsSetNewPwd">
<h1>重新设置密码</h1>
<div class="close jsCloseDialog"><img src="{% static 'image/dig_close.png' %}"/></div>
<p class="green">请输入新密码</p>
<form id="jsSetNewPwdForm">
<div class="box">
<span class="word2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<input type="password" name="password" id="jsResetPwd" placeholder="请输入新密码"/>
</div>
<div class="box">
<span class="word2">&nbsp;&nbsp;&nbsp;</span>
<input type="password" name="password2" id="jsResetPwd2" placeholder="请再次输入新密码"/>
</div>
<div class="box">
<span class="word2">&nbsp;&nbsp;&nbsp;&nbsp;</span>
<input type="text" name="code" id="jsResetCode" placeholder="请输入手机验证码"/>
</div>
<div class="error btns" id="jsSetNewPwdTips"></div>
<div class="button">
<input type="hidden" name="mobile" id="jsInpResetMobil" />
<input id="jsSetNewPwdBtn" type="button" value="提交" />
</div>
<input type='hidden' name='csrfmiddlewaretoken' value='mymQDzHWl2REXIfPMg2mJaLqDfaS1sD5' />
</form>
</div>
<div class="bg" id="dialogBg"></div>
<header>
<div class="c-box fff-box">
<div class="wp header-box">
<p class="fl hd-tips">慕学网,在线学习平台!</p>
<ul class="fr hd-bar">
<li>服务电话:<span>33333333</span></li>
<li><a href="login.html">[登录]</a></li>
<li class="active"><a href="/forgetpwd/">[忘记密码]</a></li>
</ul>
</div>
</div>
</header>
<section>
<div class="c-box bg-box">
<div class="login-box clearfix">
<div class="hd-login clearfix">
<a class="index-logo" href="/"></a>
<h1>忘记密码</h1>
<a class="index-font" href="{% url 'index' %}">回到首页</a>
<div class="new_register_con">
<div class="new_login_txt fl new_register_left">
<h3>欢迎加入CodePedia代码社区</h3>
<p>在这里,您将通过阅读最新最好的源代码学习代码到规范,同时为代码注释大数据贡献自己的一份力量。</p>
</div>
<div class="fl slide">
<div class="imgslide">
<ul class="imgs">
<li><a href=""><img width="483" height="472" src="{% static 'images/57a801860001c34b12000460.jpg' %}" /></a></li>
<li><a href=""><img width="483" height="472" src="{% static 'images/57a801860001c34b12000460.jpg' %}" /></a></li>
<li><a href=""><img width="483" height="472" src="{% static 'images/57a801860001c34b12000460.jpg' %}" /></a></li>
</ul>
<div class="new_login_box fr mr45 mt50 ">
<h2 class="new_login_h2">
修改密码
<div id="cl"></div>
</h2>
<div class="new_login_form">
<form id="forgetpwd_form" method="post" action="{% url 'users:forgetpwd' %}" autocomplete="off">
<ul>
<li class="new_register_li form-group {% if register_form.errors.email %}errorput{% endif %}">
<input type="text" class="new_register_input" id="id_email" name="email" value="{{ forgetpwd_form.email.value }}" placeholder="请输入您的邮箱地址">
</li>
<li class="new_register_li form-group {% if register_form.errors.password %} errorput{% endif %}">
<input type="password" class="new_register_input" id="id_password" name="password" placeholder="请输入6-20位非中文字符密码" />
</li>
<li class="new_register_li form-group {% if register_form.errors.password %} errorput{% endif %}">
<input type="password" class="new_register_input" id="id_password" name="password2" placeholder="请再次输入密码" />
</li>
</ul>
<div class="error btns" id="jsEmailTips">
{% for key,error in register_form.errors.items %}
{{ key }}{{ error }}
{% endfor %}
{{ msg }}
</div>
<div class="auto-box marb8"></div>
<input class="btn btn-green new_login_submit" id="jsEmailRegBtn" type="submit" value="提交" />
{% csrf_token %}
</form>
</div>
<div class="unslider-arrow prev"></div>
<div class="unslider-arrow next"></div>
</div>
<div class="fl form-box">
<h2>忘记密码</h2>
<form id="jsFindPwdForm" method="post" action="{% url 'users:forgetpwd' %}" autocomplete="off">
<input type='hidden' name='csrfmiddlewaretoken' value='mymQDzHWl2REXIfPMg2mJaLqDfaS1sD5' />
<div class="form-group marb20 {% if forget_form.errors.email %} errorput{% endif %}">
<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<input type="text" id="account" name="email" value="{{ forget_form.email.value }}" placeholder="邮箱" />
</div>
<div class="form-group captcha1 marb38 {% if forget_form.errors.captcha %} errorput{% endif %} ">
<label>&nbsp;&nbsp;</label>
{{ forget_form.captcha }}
</div>
<div class="error btns" id="jsForgetTips">{% for key, error in forget_form.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>
{% csrf_token %}
</form>
</div>
</div>
</div>
</section>
<input id="isLogin" type="hidden" value="False"/>
{% endblock %}
{% block custom_js %}
<script src="{% static 'js/jquery.min.js' %}" type="text/javascript"></script>
<script src="{% static 'js/unslider.js' %}" type="text/javascript"></script>
<script src="{% static 'js/validateDialog.js' %}" type="text/javascript"></script>
<script src="{% static 'js/login.js' %}" type="text/javascript"></script>
<script src="{% static 'js/users-common.js' %}"></script>
{% endblock %}

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>修改密码成功</p>
</body>
</html>

View File

@ -24,7 +24,7 @@
<ul>
<li class="new_register_li form-group {% if register_form.errors.email %}errorput{% endif %}">
<input type="text" class="new_register_input" id="id_email" name="email" value="{{ register_form.email.value }}" placeholder="请输入您的邮箱地址">
<input type="text" class="new_register_input" id="id_email" name="email" placeholder="请输入您的邮箱地址">
</li>
<li class="new_register_li form-group {% if register_form.errors.password %} errorput{% endif %}">