-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9470492
commit a336ed8
Showing
33 changed files
with
384 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from django.core.exceptions import ValidationError | ||
from django import forms | ||
from django.forms import fields | ||
from django.forms import widgets | ||
from django.core.validators import RegexValidator | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class RegisterForm(forms.Form): | ||
username = fields.CharField( | ||
required=True, | ||
widget=widgets.TextInput(attrs={'class': "form-control",'placeholder': '用户名为8-12个字符'}), | ||
min_length=6, | ||
max_length=12, | ||
strip=True, | ||
error_messages={'required': '标题不能为空', | ||
'min_length': '用户名最少为6个字符', | ||
'max_length': '用户名最不超过为20个字符'}, | ||
) | ||
email = fields.EmailField( | ||
required=True, | ||
widget=widgets.TextInput(attrs={'class': "form-control",'placeholder': '请输入邮箱'}), | ||
#strip=True, | ||
error_messages={'required': '邮箱不能为空', | ||
'invalid':'请输入正确的邮箱格式'} | ||
) | ||
pwd = fields.CharField( | ||
widget=widgets.PasswordInput(attrs={'class': "form-control",'placeholder': '请输入密码,必须包含数字,字母,特殊字符'},render_value=True), | ||
required=True, | ||
min_length=6, | ||
max_length=12, | ||
strip=True, | ||
validators=[ | ||
# 下面的正则内容一目了然,我就不注释了 | ||
RegexValidator(r'((?=.*\d))^.{6,12}$', '必须包含数字'), | ||
RegexValidator(r'((?=.*[a-zA-Z]))^.{6,12}$', '必须包含字母'), | ||
RegexValidator(r'((?=.*[^a-zA-Z0-9]))^.{6,12}$', '必须包含特殊字符'), | ||
RegexValidator(r'^.(\S){6,10}$', '密码不能包含空白字符'), | ||
], #用于对密码的正则验证 | ||
error_messages={'required': '密码不能为空!', | ||
'min_length': '密码最少为6个字符', | ||
'max_length': '密码最多不超过为12个字符!',}, | ||
) | ||
pwd_again = fields.CharField( | ||
#render_value会对于PasswordInput,错误是否清空密码输入框内容,默认为清除,我改为不清楚 | ||
widget=widgets.PasswordInput(attrs={'class': "form-control",'placeholder': '请再次输入密码!'},render_value=True), | ||
required=True, | ||
strip=True, | ||
error_messages={'required': '请再次输入密码!',} | ||
|
||
) | ||
|
||
def clean_username(self): | ||
# 对username的扩展验证,查找用户是否已经存在 | ||
username = self.cleaned_data.get('username') | ||
users = User.objects.filter(username=username).count() | ||
if users: | ||
raise ValidationError('用户已经存在!') | ||
return username | ||
|
||
def clean_email(self): | ||
# 对email的扩展验证,查找用户是否已经存在 | ||
email = self.cleaned_data.get('email') | ||
email_count = User.objects.filter(email=email).count() #从数据库中查找是否用户已经存在 | ||
if email_count: | ||
raise ValidationError('该邮箱已经注册!') | ||
return email | ||
|
||
def _clean_new_password2(self): #查看两次密码是否一致 | ||
password1 = self.cleaned_data.get('pwd') | ||
password2 = self.cleaned_data.get('pwd_again') | ||
if password1 and password2: | ||
if password1 != password2: | ||
# self.error_dict['pwd_again'] = '两次密码不匹配' | ||
raise ValidationError('两次密码不匹配!') | ||
|
||
def clean(self): | ||
#是基于form对象的验证,字段全部验证通过会调用clean函数进行验证 | ||
self._clean_new_password2() #简单的调用而已 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{% extends 'base.html' %} | ||
{% load timetonow %} | ||
|
||
{% block header %} | ||
<title> 物志 › 登录 </title> | ||
{% endblock %} | ||
|
||
{% block banner %} | ||
<div style="height:30px"> | ||
<p></p> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="card"> | ||
<form class="form-inline " method="post" action="" novalidate>{% csrf_token %} | ||
<a href="/">物志</a> › 登录 | ||
<hr> | ||
<p style="text-align:center"> | ||
<label style="width:100px;text-align:right" for="username">用户名:</label> | ||
<input type="text" name="username" value="gothack" class="form-control" placeholder="请输入用户名" maxlength="12" minlength="6" required="" id="id_username"> | ||
</p> | ||
|
||
<p style="text-align:center"> | ||
<label style="width:100px;text-align:right" for="password">密码:</label> | ||
<input type="password" name="password" class="form-control" placeholder="请输入密码" maxlength="12" minlength="6" required="" id="id_password"> | ||
</p> | ||
|
||
<p style="text-align:center"> | ||
<label style="width:100px;text-align:right"></label> | ||
<img style="display:inline-block;" id="check_code_img" src="/utils/check_code/" onclick="refresh_check_code(this)"></p> | ||
<p style="text-align:center"> | ||
<label style="width:100px;text-align:right" for="check_code">验证码:</label> | ||
<input type="text" class="form-control" name="check_code" id="check_code" placeholder="请输入验证码"> | ||
</p> | ||
|
||
<p style="text-align:center"> | ||
<label style="width:100px;text-align:right"><input type="checkbox" value="1" name="auto_login"></label> | ||
一个月内自动登陆 | ||
<span class="pull-right"><a href="#">忘记密码?</a></span> | ||
</p> | ||
<p style="text-align:center"> | ||
<button class="btn btn-primary" type="submit" >登录</button> | ||
</p> | ||
</form> | ||
</div> | ||
|
||
|
||
{% if errors %} | ||
{% for error in errors %} | ||
<script type="text/javascript"> | ||
$.notify({ | ||
message: '{{ error|escape }}', | ||
},{ | ||
type: 'warning', | ||
delay: 5000, | ||
timer: 1000, | ||
animate: { | ||
enter: 'animated flipInY', | ||
exit: 'animated flipOutX' | ||
}, | ||
},); | ||
</script> | ||
{% endfor %} | ||
{% endif %} | ||
|
||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class UtilsConfig(AppConfig): | ||
name = 'utils' |
Oops, something went wrong.