python学习
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,render_template
|
||||
from flask import Blueprint
|
||||
from common.libs.Helper import ops_render
|
||||
|
||||
route_account = Blueprint( 'account_page',__name__ )
|
||||
|
||||
@route_account.route( "/index" )
|
||||
def index():
|
||||
return render_template( "account/index.html" )
|
||||
return ops_render( "account/index.html" )
|
||||
|
||||
@route_account.route( "/info" )
|
||||
def info():
|
||||
return render_template( "account/info.html" )
|
||||
return ops_render( "account/info.html" )
|
||||
|
||||
@route_account.route( "/set" )
|
||||
def set():
|
||||
return render_template( "account/set.html" )
|
||||
return ops_render( "account/set.html" )
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,render_template
|
||||
from flask import Blueprint
|
||||
from common.libs.Helper import ops_render
|
||||
|
||||
route_finance = Blueprint( 'finance_page',__name__ )
|
||||
|
||||
@route_finance.route( "/index" )
|
||||
def index():
|
||||
return render_template( "finance/index.html" )
|
||||
return ops_render( "finance/index.html" )
|
||||
|
||||
@route_finance.route( "/pay-info" )
|
||||
def payInfo():
|
||||
return render_template( "finance/pay_info.html" )
|
||||
return ops_render( "finance/pay_info.html" )
|
||||
|
||||
@route_finance.route( "/account" )
|
||||
def account():
|
||||
return render_template( "finance/account.html" )
|
||||
return ops_render( "finance/account.html" )
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,render_template
|
||||
from flask import Blueprint
|
||||
from common.libs.Helper import ops_render
|
||||
|
||||
route_food = Blueprint( 'food_page',__name__ )
|
||||
|
||||
@route_food.route( "/index" )
|
||||
def index():
|
||||
return render_template( "food/index.html" )
|
||||
return ops_render( "food/index.html" )
|
||||
|
||||
@route_food.route( "/info" )
|
||||
def info():
|
||||
return render_template( "food/info.html" )
|
||||
return ops_render( "food/info.html" )
|
||||
|
||||
|
||||
@route_food.route( "/set" )
|
||||
def set():
|
||||
return render_template( "food/set.html" )
|
||||
return ops_render( "food/set.html" )
|
||||
|
||||
|
||||
@route_food.route( "/cat" )
|
||||
def cat():
|
||||
return render_template( "food/cat.html" )
|
||||
return ops_render( "food/cat.html" )
|
||||
|
||||
@route_food.route( "/cat-set" )
|
||||
def catSet():
|
||||
return render_template( "food/cat_set.html" )
|
||||
return ops_render( "food/cat_set.html" )
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,render_template
|
||||
|
||||
from flask import Blueprint
|
||||
from common.libs.Helper import ops_render
|
||||
route_index = Blueprint( 'index_page',__name__ )
|
||||
|
||||
@route_index.route("/")
|
||||
def index():
|
||||
return render_template( "index/index.html" )
|
||||
return ops_render( "index/index.html" )
|
||||
@@ -1,21 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,render_template
|
||||
|
||||
from flask import Blueprint
|
||||
from common.libs.Helper import ops_render
|
||||
route_member = Blueprint( 'member_page',__name__ )
|
||||
|
||||
@route_member.route( "/index" )
|
||||
def index():
|
||||
return render_template( "member/index.html" )
|
||||
return ops_render( "member/index.html" )
|
||||
|
||||
@route_member.route( "/info" )
|
||||
def info():
|
||||
return render_template( "member/info.html" )
|
||||
return ops_render( "member/info.html" )
|
||||
|
||||
@route_member.route( "/set" )
|
||||
def set():
|
||||
return render_template( "member/set.html" )
|
||||
return ops_render( "member/set.html" )
|
||||
|
||||
|
||||
@route_member.route( "/comment" )
|
||||
def comment():
|
||||
return render_template( "member/comment.html" )
|
||||
return ops_render( "member/comment.html" )
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,render_template
|
||||
|
||||
from flask import Blueprint
|
||||
from common.libs.Helper import ops_render
|
||||
route_stat = Blueprint( 'stat_page',__name__ )
|
||||
|
||||
@route_stat.route( "/index" )
|
||||
def index():
|
||||
return render_template( "stat/index.html" )
|
||||
return ops_render( "stat/index.html" )
|
||||
|
||||
@route_stat.route( "/food" )
|
||||
def food():
|
||||
return render_template( "stat/food.html" )
|
||||
return ops_render( "stat/food.html" )
|
||||
|
||||
@route_stat.route( "/member" )
|
||||
def memebr():
|
||||
return render_template( "stat/member.html" )
|
||||
return ops_render( "stat/member.html" )
|
||||
|
||||
@route_stat.route( "/share" )
|
||||
def share():
|
||||
return render_template( "stat/share.html" )
|
||||
return ops_render( "stat/share.html" )
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint, render_template, request,jsonify,make_response,redirect
|
||||
from flask import Blueprint, request,jsonify,make_response,redirect,g
|
||||
from common.models.User import User
|
||||
from common.libs.user.UserService import UserService
|
||||
from common.libs.Helper import (ops_render)
|
||||
from application import app,db
|
||||
import json
|
||||
from common.libs.UrlManager import UrlManager
|
||||
@@ -13,7 +14,7 @@ route_user = Blueprint('user_page', __name__)
|
||||
@route_user.route("/login")
|
||||
def login():
|
||||
if request.method == "GET":
|
||||
return render_template("user/login.html")
|
||||
return ops_render("user/login.html")
|
||||
resp = {'code': 200, 'msg': '登录成功', 'data': {}}
|
||||
req = request.values
|
||||
login_name = req['login_name'] if 'login_name' in req else ''
|
||||
@@ -45,14 +46,81 @@ def login():
|
||||
return response
|
||||
|
||||
|
||||
@route_user.route("/edit")
|
||||
@route_user.route("/edit",methods=["GET", "POST"])
|
||||
def edit():
|
||||
return render_template("user/edit.html")
|
||||
# if request.method == "GET":
|
||||
# return ops_render("user/edit.html")
|
||||
|
||||
if request.method == "GET":
|
||||
return ops_render("user/edit.html", {'current': 'edit'})
|
||||
|
||||
resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
|
||||
req = request.values
|
||||
nickname = req['nickname'] if 'nickname' in req else ''
|
||||
email = req['email'] if 'email' in req else ''
|
||||
|
||||
if nickname is None or len(nickname) < 1:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入符合规范的姓名~~"
|
||||
return jsonify(resp)
|
||||
|
||||
if email is None or len(email) < 1:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入符合规范的邮箱~~"
|
||||
return jsonify(resp)
|
||||
|
||||
user_info = g.current_user
|
||||
user_info.nickname = nickname
|
||||
user_info.email = email
|
||||
|
||||
db.session.add(user_info)
|
||||
db.session.commit()
|
||||
return jsonify(resp)
|
||||
|
||||
|
||||
@route_user.route("/reset-pwd")
|
||||
@route_user.route("/reset-pwd",methods=["GET", "POST"])
|
||||
def resetPwd():
|
||||
return render_template("user/reset_pwd.html")
|
||||
if request.method == "GET":
|
||||
return ops_render("user/reset_pwd.html", {'current': 'reset-pwd'})
|
||||
|
||||
resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
|
||||
req = request.values
|
||||
|
||||
old_password = req['old_password'] if 'old_password' in req else ''
|
||||
new_password = req['new_password'] if 'new_password' in req else ''
|
||||
|
||||
if old_password is None or len(old_password) < 6:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入符合规范的原密码~~"
|
||||
return jsonify(resp)
|
||||
|
||||
if new_password is None or len(new_password) < 6:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入符合规范的新密码~~"
|
||||
return jsonify(resp)
|
||||
|
||||
if old_password == new_password:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请重新输入一个吧,新密码和原密码不能相同哦~~"
|
||||
return jsonify(resp)
|
||||
|
||||
user_info = g.current_user
|
||||
|
||||
# if user_info.uid == 1:
|
||||
# resp['code'] = -1
|
||||
# resp['msg'] = "该用户是演示账号,不准修改密码和登录用户名~~"
|
||||
# return jsonify(resp)
|
||||
|
||||
user_info.login_pwd = UserService.genePwd(new_password, user_info.login_salt)
|
||||
|
||||
db.session.add(user_info)
|
||||
db.session.commit()
|
||||
|
||||
response = make_response(json.dumps(resp))
|
||||
response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' % (
|
||||
UserService.geneAuthCode(user_info), user_info.uid), 60 * 60 * 24 * 120) # 保存120天
|
||||
return response
|
||||
|
||||
|
||||
@route_user.route("/logout")
|
||||
def logout():
|
||||
|
||||
@@ -19,6 +19,9 @@ def before_request():
|
||||
return
|
||||
|
||||
user_info = check_login()
|
||||
g.current_user=None
|
||||
if user_info:
|
||||
g.current_user=user_info
|
||||
|
||||
pattern = re.compile('%s' % "|".join(ignore_urls))
|
||||
if pattern.match(path):
|
||||
|
||||
61
web/static/js/user/edit.js
Normal file
61
web/static/js/user/edit.js
Normal file
@@ -0,0 +1,61 @@
|
||||
;
|
||||
var user_edit_ops = {
|
||||
init:function(){
|
||||
this.eventBind();
|
||||
},
|
||||
eventBind:function(){
|
||||
$(".user_edit_wrap .save").click(function(){
|
||||
var btn_target = $(this);
|
||||
if( btn_target.hasClass("disabled") ){
|
||||
common_ops.alert("正在处理!!请不要重复提交~~");
|
||||
return;
|
||||
}
|
||||
|
||||
var nickname_target = $(".user_edit_wrap input[name=nickname]");
|
||||
var nickname = nickname_target.val();
|
||||
|
||||
var email_target = $(".user_edit_wrap input[name=email]");
|
||||
var email = email_target.val();
|
||||
|
||||
if( !nickname || nickname.length < 2 ){
|
||||
common_ops.tip( "请输入符合规范的姓名~~",nickname_target );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !email || email.length < 2 ){
|
||||
common_ops.tip( "请输入符合规范的邮箱~~",nickname_target );
|
||||
return false;
|
||||
}
|
||||
|
||||
btn_target.addClass("disabled");
|
||||
|
||||
var data = {
|
||||
nickname: nickname,
|
||||
email: email
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url:common_ops.buildUrl( "/user/edit" ),
|
||||
type:'POST',
|
||||
data:data,
|
||||
dataType:'json',
|
||||
success:function( res ){
|
||||
btn_target.removeClass("disabled");
|
||||
var callback = null;
|
||||
if( res.code == 200 ){
|
||||
callback = function(){
|
||||
window.location.href = window.location.href;
|
||||
}
|
||||
}
|
||||
common_ops.alert( res.msg,callback );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready( function(){
|
||||
user_edit_ops.init();
|
||||
} );
|
||||
59
web/static/js/user/reset_pwd.js
Normal file
59
web/static/js/user/reset_pwd.js
Normal file
@@ -0,0 +1,59 @@
|
||||
;
|
||||
var mod_pwd_ops = {
|
||||
init:function(){
|
||||
this.eventBind();
|
||||
},
|
||||
eventBind:function(){
|
||||
$("#save").click(function(){
|
||||
var btn_target = $(this);
|
||||
if( btn_target.hasClass("disabled") ){
|
||||
common_ops.alert("正在处理!!请不要重复提交~~");
|
||||
return;
|
||||
}
|
||||
|
||||
var old_password = $("#old_password").val();
|
||||
var new_password = $("#new_password").val();
|
||||
|
||||
|
||||
if( !old_password ){
|
||||
common_ops.alert( "请输入原密码~~" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !new_password || new_password.length < 6 ){
|
||||
common_ops.alert( "请输入不少于6位的新密码~~" );
|
||||
return false;
|
||||
}
|
||||
|
||||
btn_target.addClass("disabled");
|
||||
|
||||
var data = {
|
||||
old_password: old_password,
|
||||
new_password: new_password
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url:common_ops.buildUrl( "/user/reset-pwd" ),
|
||||
type:'POST',
|
||||
data:data,
|
||||
dataType:'json',
|
||||
success:function( res ){
|
||||
btn_target.removeClass("disabled");
|
||||
var callback = null;
|
||||
if( res.code == 200 ){
|
||||
callback = function(){
|
||||
window.location.href = window.location.href;
|
||||
}
|
||||
}
|
||||
common_ops.alert( res.msg,callback );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready( function(){
|
||||
mod_pwd_ops.init();
|
||||
} );
|
||||
@@ -56,7 +56,8 @@
|
||||
<div class="row border-bottom">
|
||||
<nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="javascript:void(0);"><i class="fa fa-bars"></i> </a>
|
||||
<a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="javascript:void(0);"><i
|
||||
class="fa fa-bars"></i> </a>
|
||||
</div>
|
||||
<ul class="nav navbar-top-links navbar-right">
|
||||
<li>
|
||||
@@ -66,18 +67,20 @@
|
||||
</li>
|
||||
<li class="dropdown user_info">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0);">
|
||||
<img alt="image" class="img-circle" src="{{ buildStaticUrl('/images/common/avatar.png') }}"/>
|
||||
<img alt="image" class="img-circle"
|
||||
src="{{ buildStaticUrl('/images/common/avatar.png') }}"/>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-messages">
|
||||
<li>
|
||||
<div class="dropdown-messages-box">
|
||||
姓名:xxxx <a href="{{ buildUrl('/user/edit') }}" class="pull-right">编辑</a>
|
||||
姓名:{{current_user.nickname}} <a href="{{ buildUrl('/user/edit') }}"
|
||||
class="pull-right">编辑</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<div class="dropdown-messages-box">
|
||||
手机号码:xxxx
|
||||
手机号码:{{ current_user.mobile}}
|
||||
</div>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
|
||||
14
web/templates/common/tab_user.html
Normal file
14
web/templates/common/tab_user.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<div class="row border-bottom">
|
||||
<div class="col-lg-12">
|
||||
<div class="tab_title">
|
||||
<ul class="nav nav-pills">
|
||||
<li {% if current == "edit" %} class="current" {% endif %}>
|
||||
<a href="{{ buildUrl('/user/edit') }}">信息编辑</a>
|
||||
</li>
|
||||
<li {% if current == "reset-pwd" %} class="current" {% endif %}>
|
||||
<a href="{{ buildUrl('/user/reset-pwd') }}">修改密码</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,19 +1,6 @@
|
||||
{% extends "common/layout_main.html" %}
|
||||
{% block content %}
|
||||
<div class="row border-bottom">
|
||||
<div class="col-lg-12">
|
||||
<div class="tab_title">
|
||||
<ul class="nav nav-pills">
|
||||
<li class="current">
|
||||
<a href="{{ buildUrl('/user/edit') }}">信息编辑</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ buildUrl('/user/edit') }}">修改密码</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% include "common/tab_user.html" %}
|
||||
<div class="row m-t user_edit_wrap">
|
||||
<div class="col-lg-12">
|
||||
<h2 class="text-center">账号信息编辑</h2>
|
||||
@@ -22,7 +9,7 @@
|
||||
<label class="col-lg-2 control-label">手机:</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" name="mobile" class="form-control" placeholder="请输入手机~~" readonly=""
|
||||
value="11012031511">
|
||||
value="{{ current_user.mobile }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
@@ -30,15 +17,14 @@
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">姓名:</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" name="nickname" class="form-control" placeholder="请输入姓名~~" value="编程浪子2">
|
||||
</div>
|
||||
<input type="text" name="nickname" class="form-control" placeholder="请输入姓名~~" value="{{ current_user.nickname }}"> </div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">邮箱:</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" name="email" class="form-control" placeholder="请输入邮箱~~" value="apanly@163.com">
|
||||
<input type="text" name="email" class="form-control" placeholder="请输入邮箱~~" value="{{ current_user.email }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
@@ -51,3 +37,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block js %}
|
||||
<script src="{{buildStaticUrl('/js/user/edit.js')}}"></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
{% extends "common/layout_main.html" %}
|
||||
{% block content %}
|
||||
<div class="row border-bottom">
|
||||
<div class="col-lg-12">
|
||||
<div class="tab_title">
|
||||
<ul class="nav nav-pills">
|
||||
<li>
|
||||
<a href="{{ buildUrl('/user/edit') }}">信息编辑</a>
|
||||
</li>
|
||||
<li class="current">
|
||||
<a href="{{ buildUrl('/user/edit') }}">修改密码</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% include "common/tab_user.html" %}
|
||||
<div class="row m-t user_reset_pwd_wrap">
|
||||
<div class="col-lg-12">
|
||||
<h2 class="text-center">修改密码</h2>
|
||||
@@ -21,14 +8,14 @@
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">账号:</label>
|
||||
<div class="col-lg-10">
|
||||
<label class="control-label">编程浪子2</label>
|
||||
<label class="control-label">{{ current_user.login_name }}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">手机:</label>
|
||||
<div class="col-lg-10">
|
||||
<label class="control-label">11012031511</label>
|
||||
<label class="control-label">{{ current_user.mobile }}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
@@ -57,3 +44,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block js %}
|
||||
<script src="{{ buildStaticUrl('/js/user/reset_pwd.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user