-
Notifications
You must be signed in to change notification settings - Fork 3
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
jianw4
committed
May 20, 2018
1 parent
8f24786
commit 15508fe
Showing
46 changed files
with
1,752 additions
and
202 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
'django.contrib.staticfiles', | ||
'video', | ||
'UserManage', | ||
'story', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 引入Django表单 | ||
from django import forms | ||
from UserManage.models import User | ||
|
||
|
||
# 重置密码form实现 | ||
class UpdatePwdForm(forms.Form): | ||
# 密码不能小于5位 | ||
password1 = forms.CharField(required=True, min_length=5) | ||
# 密码不能小于5位 | ||
password2 = forms.CharField(required=True, min_length=5) | ||
|
||
|
||
# 用于个人中心修改个人信息 | ||
class UserInfoForm(forms.ModelForm): | ||
|
||
class Meta: | ||
model = User | ||
fields = ['nickname','gender','address','mobile', 'email'] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""BabyEnglish URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/1.11/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.conf.urls import url, include | ||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) | ||
""" | ||
from django.conf.urls import url | ||
from UserManage.views import UpdatePwdView,UserInfoView | ||
from UserManage import views | ||
|
||
|
||
urlpatterns = [ | ||
|
||
#url(r'update/$', views.update), | ||
url('updatepwd/', UpdatePwdView.as_view(), name="updatepwd"), | ||
url('userinfo/', UserInfoView.as_view(), name="userinfo"), | ||
# 专用于发送验证码的 | ||
#url('sendemail_code/', SendEmailCodeView.as_view(), name="sendemail_code"), | ||
|
||
] |
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 |
---|---|---|
@@ -1,3 +1,135 @@ | ||
from django.shortcuts import render | ||
|
||
from django.shortcuts import render,redirect,render_to_response,HttpResponse | ||
# 基于类实现需要继承的view | ||
from django.views.generic.base import View | ||
from UserManage.forms import UpdatePwdForm | ||
from UserManage.models import User | ||
from utils.tools import * | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
import json | ||
from UserManage.forms import UserInfoForm | ||
# Create your views here. | ||
|
||
|
||
def login_required(func): | ||
"""要求登录的装饰器""" | ||
def _deco(request, *args, **kwargs): | ||
if not request.session.get('username'): | ||
return redirect('/login/') | ||
return func(request, *args, **kwargs) | ||
return _deco | ||
|
||
def login(request): | ||
"""登录界面""" | ||
# if request.session.get('username'): | ||
# return redirect('/') | ||
if request.method == 'GET': | ||
return render_to_response('login.html') | ||
else: | ||
username = request.POST.get('username') | ||
password = request.POST.get('password') | ||
user = User.objects.filter(username=username) | ||
if user: | ||
user = user[0] | ||
if md5_crypt(password) == user.password: | ||
request.session['username'] = username | ||
if user.is_admin: | ||
request.session['admin'] = 1 | ||
elif user.is_superuser: | ||
request.session['admin'] = 2 | ||
else: | ||
request.session['admin'] = 0 | ||
return redirect('/index/%s/' % username) | ||
else: | ||
error = '密码错误,请重新输入。' | ||
else: | ||
error = '用户不存在。' | ||
return render_to_response('login.html', {'error': error}) | ||
|
||
|
||
|
||
def logout(request): | ||
"""注销登录调用""" | ||
if request.session.get('username'): | ||
del request.session['username'] | ||
del request.session['admin'] | ||
return redirect('/login/') | ||
|
||
def register(request): | ||
if request.method == "POST": | ||
print("-------------------register handle--------") | ||
username = request.POST.get("username") | ||
passwd = request.POST.get("password") | ||
email = request.POST.get("email") | ||
nickname = request.POST.get("nickname") | ||
gender = request.POST.get("sex") | ||
mobile = request.POST.get("mobile") | ||
address = request.POST.get("address") | ||
|
||
city = request.POST.get("city") | ||
error_info = dict() | ||
|
||
if User.objects.filter(username= username): | ||
error_info['error'] = "用户名已经注册了" | ||
elif User.objects.filter(nickname=nickname): | ||
error_info['error'] = "昵称已被使用" | ||
elif User.objects.filter(email=email): | ||
error_info['error'] = "邮箱已被注册" | ||
else: | ||
User.objects.create(username=username, password=md5_crypt(passwd), nickname=nickname, email=email, gender=gender, city=city) | ||
return redirect("/login/") | ||
|
||
return render_to_response("register.html", error_info ) | ||
else: | ||
return render_to_response("register.html") | ||
|
||
|
||
|
||
class UpdatePwdView(View): | ||
|
||
def get(self, request): | ||
return render( request, "password_reset.html") | ||
|
||
def post(self, request): | ||
modiypwd_form = UpdatePwdForm(request.POST) | ||
if modiypwd_form.is_valid(): | ||
pwd1 = request.POST.get("password1", "") | ||
pwd2 = request.POST.get("password2", "") | ||
#active_code = request.POST.get("active_code", "") | ||
#print("active_code=%s" % active_code) | ||
email = request.POST.get("email", "") | ||
# 如果两次密码不相等,返回错误信息 | ||
if pwd1 != pwd2: | ||
return render( | ||
request, "password_reset.html", { "msg": "密码不一致"}) | ||
|
||
user = User.objects.get(username=request.session['username']) | ||
# 加密成密文 | ||
user.password = md5_crypt(pwd2) | ||
# save保存到数据库 | ||
user.save() | ||
return redirect("/login/") | ||
# 验证失败说明密码位数不够。 | ||
else: | ||
|
||
return render( | ||
request, "password_reset.html", { "modiypwd_form": modiypwd_form}) | ||
|
||
|
||
|
||
class UserInfoView(View): | ||
|
||
|
||
def get(self, request): | ||
user = User.objects.get(username=request.session['username']) | ||
return render(request, "user_info.html", {'user':user }) | ||
|
||
def post(self, request): | ||
# 不像用户咨询是一个新的。需要指明instance。不然无法修改,而是新增用户 | ||
user = User.objects.get(username=request.session['username']) | ||
user_info_form = UserInfoForm(request.POST, instance=user) | ||
|
||
if user_info_form.is_valid(): | ||
user_info_form.save() | ||
return render_to_response("user_info.html", {'user':user,'status':"修改成功"}) | ||
else: | ||
render_to_response("user_info.html", {'user': user, 'status':user_info_form.errors}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
|
||
.userdetail { | ||
display: none; | ||
position: absolute; | ||
right: 0; | ||
top: 38px; | ||
background: #fff; | ||
padding: 10px; | ||
z-index: 99; | ||
border: 1px solid #ccc; | ||
border-top: 0; | ||
} | ||
|
||
.userdetail dl { | ||
width: 300px; | ||
height: auto; | ||
overflow: hidden; | ||
} | ||
|
||
.userdetail dt { | ||
width: 80px; | ||
height: 80px; | ||
overflow: hidden; | ||
border-radius: 50%; | ||
float: left; | ||
} | ||
|
||
.userdetail dd { | ||
text-align: right; | ||
line-height: 20px; | ||
width: 190px; | ||
float: right; | ||
position: absolute; | ||
right: 10px; | ||
top: 30px; | ||
color: #333; | ||
height: auto; | ||
overflow: hidden; | ||
} | ||
|
||
.userdetail h2 { | ||
color: #717171; | ||
} | ||
|
||
.userdetail .btn { | ||
width: 100%; | ||
height: 30px; | ||
line-height: 30px; | ||
margin-top: 20px; | ||
clear: both; | ||
} | ||
|
||
.userdetail .btn a { | ||
display: block; | ||
height: 30px; | ||
line-height: 30px; | ||
text-align: center; | ||
background: #717171; | ||
color: #fff; | ||
} | ||
|
||
.userdetail .btn a:hover { | ||
background: #4FB137; | ||
} | ||
|
||
.userdetail .btn a.fl { | ||
width: 65%; | ||
float: left!important; | ||
} | ||
|
||
.userdetail .btn a.fr { | ||
width: 32%; | ||
float: right!important; | ||
} | ||
|
||
.personal { | ||
height: auto; | ||
float: right; | ||
position: relative; | ||
} | ||
|
||
} |
Oops, something went wrong.