python学习

This commit is contained in:
2019-07-21 18:20:01 +08:00
parent 7bd7a50cff
commit 11752bbb8d
405 changed files with 72156 additions and 529 deletions

View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from flask import Blueprint,render_template
route_account = Blueprint( 'account_page',__name__ )
@route_account.route( "/index" )
def index():
return render_template( "account/index.html" )
@route_account.route( "/info" )
def info():
return render_template( "account/info.html" )
@route_account.route( "/set" )
def set():
return render_template( "account/set.html" )

View File

@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from flask import Blueprint,render_template
route_finance = Blueprint( 'finance_page',__name__ )
@route_finance.route( "/index" )
def index():
return render_template( "finance/index.html" )
@route_finance.route( "/pay-info" )
def payInfo():
return render_template( "finance/pay_info.html" )
@route_finance.route( "/account" )
def account():
return render_template( "finance/account.html" )

View File

@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from flask import Blueprint,render_template
route_food = Blueprint( 'food_page',__name__ )
@route_food.route( "/index" )
def index():
return render_template( "food/index.html" )
@route_food.route( "/info" )
def info():
return render_template( "food/info.html" )
@route_food.route( "/set" )
def set():
return render_template( "food/set.html" )
@route_food.route( "/cat" )
def cat():
return render_template( "food/cat.html" )
@route_food.route( "/cat-set" )
def catSet():
return render_template( "food/cat_set.html" )

View File

@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@@ -5,4 +5,4 @@ route_index = Blueprint( 'index_page',__name__ )
@route_index.route("/")
def index():
return render_template("index/index.html")
return render_template( "index/index.html" )

View File

@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from flask import Blueprint,render_template
route_member = Blueprint( 'member_page',__name__ )
@route_member.route( "/index" )
def index():
return render_template( "member/index.html" )
@route_member.route( "/info" )
def info():
return render_template( "member/info.html" )
@route_member.route( "/set" )
def set():
return render_template( "member/set.html" )
@route_member.route( "/comment" )
def comment():
return render_template( "member/comment.html" )

View File

@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from flask import Blueprint,render_template
route_stat = Blueprint( 'stat_page',__name__ )
@route_stat.route( "/index" )
def index():
return render_template( "stat/index.html" )
@route_stat.route( "/food" )
def food():
return render_template( "stat/food.html" )
@route_stat.route( "/member" )
def memebr():
return render_template( "stat/member.html" )
@route_stat.route( "/share" )
def share():
return render_template( "stat/share.html" )

View File

@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@@ -1,13 +1,61 @@
# -*- coding: utf-8 -*-
from flask import Blueprint,render_template
from flask import Blueprint, render_template, request,jsonify,make_response,redirect
from common.models.User import User
from common.libs.user.UserService import UserService
from application import app,db
import json
from common.libs.UrlManager import UrlManager
route_user = Blueprint( 'user_page',__name__ )
route_user = Blueprint('user_page', __name__)
@route_user.route("/login", methods=["GET", "POST"])
@route_user.route("/login")
def login():
return render_template("user/login.html")
if request.method == "GET":
return render_template("user/login.html")
resp = {'code': 200, 'msg': '登录成功', 'data': {}}
req = request.values
login_name = req['login_name'] if 'login_name' in req else ''
login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
if login_name is None or len(login_name)<1:
resp['code']=-1
resp['msg']="请输入正确的登录用户名"
return jsonify(resp)
if login_pwd is None or len(login_pwd) < 1:
resp['code'] = -1
resp['msg'] = "请输入正确的登录密码"
return jsonify(resp)
user_info = User.query.filter_by(login_name=login_name).first()
if not user_info:
resp['code'] = -1
resp['msg'] = "请输入正确的用户名和密码_1"
return jsonify(resp)
if user_info.login_pwd != UserService.genePwd(login_pwd, user_info.login_salt):
resp['code'] = -1
resp['msg'] = "请输入正确的登录用户名和密码-2~~"
return jsonify(resp)
response = make_response(json.dumps(resp))
response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' % (
UserService.geneAuthCode(user_info), user_info.uid)) # 保存120天
return response
@route_user.route("/edit")
def edit():
return render_template("user/edit.html")
@route_user.route("/reset_pwd")
@route_user.route("/reset-pwd")
def resetPwd():
return render_template("user/reset_pwd.html")
return render_template("user/reset_pwd.html")
@route_user.route("/logout")
def logout():
response = make_response(redirect(UrlManager.buildUrl("/user/login")))
response.delete_cookie(app.config['AUTH_COOKIE_NAME'])
return response

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
from application import app
from flask import request,g,redirect
from common.models.User import ( User )
from common.libs.user.UserService import ( UserService )
from common.libs.UrlManager import ( UrlManager )
import re
@app.before_request
def before_request():
ignore_urls = app.config['IGNORE_URLS']
ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS']
path = request.path
# 如果是静态文件就不要查询用户信息了
pattern = re.compile('%s' % "|".join(ignore_check_login_urls))
if pattern.match(path):
return
user_info = check_login()
pattern = re.compile('%s' % "|".join(ignore_urls))
if pattern.match(path):
return
if not user_info:
return redirect( UrlManager.buildUrl("/user/login"))
return
'''
判断用户是否已经登录
'''
def check_login():
cookies = request.cookies
auth_cookie = cookies[app.config['AUTH_COOKIE_NAME']] if app.config['AUTH_COOKIE_NAME'] in cookies else None
app.logger.info( auth_cookie)
if auth_cookie is None:
return False
auth_info = auth_cookie.split("#")
if len(auth_info) != 2:
return False
try:
user_info = User.query.filter_by(uid=auth_info[1]).first()
except Exception:
return False
if user_info is None:
return False
if auth_info[0] != UserService.geneAuthCode( user_info ):
return False
if user_info.status != 1:
return False
return user_info

View File

@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@@ -138,7 +138,19 @@ var common_ops = {
$('html, body').animate({
scrollTop: target.offset().top - 10
}, 100);
}
},
buildUrl:function( path ,params ){
var url = "" + path;
var _paramUrl = "";
if( params ){
_paramUrl = Object.keys( params ).map( function( k ){
return [ encodeURIComponent( k ),encodeURIComponent( params[ k ] ) ].join("=");
}).join("&");
_paramUrl = "?" + _paramUrl;
}
return url + _paramUrl;
},
};
$(document).ready( function() {

View File

View File

@@ -0,0 +1,47 @@
;
var user_login_ops = {
init:function(){
this.eventBind();
},
eventBind:function(){
$(".login_wrap .do-login").click( function(){
var btn_target = $(this);
if( btn_target.hasClass("disabled") ){
common_ops.alert("正在处理!!请不要重复提交~~");
return;
}
var login_name = $(".login_wrap input[name=login_name]").val();
var login_pwd = $(".login_wrap input[name=login_pwd]").val();
if( login_name == undefined || login_name.length < 1){
common_ops.alert( "请输入正确的登录用户名~~" );
return;
}
if( login_pwd == undefined || login_pwd.length < 1){
common_ops.alert( "请输入正确的密码~~" );
return;
}
btn_target.addClass("disabled");
$.ajax({
url:common_ops.buildUrl("/user/login"),
type:'POST',
data:{ 'login_name':login_name,'login_pwd':login_pwd },
dataType:'json',
success:function(res){
btn_target.removeClass("disabled");
var callback = null;
if( res.code == 200 ){
callback = function(){
window.location.href = common_ops.buildUrl("/");
}
}
common_ops.alert( res.msg,callback );
}
});
} );
}
};
$(document).ready( function(){
user_login_ops.init();
} );

View File

@@ -14,7 +14,7 @@
</div>
<div class="col-md-6">
<div class="ibox-content">
<form class="m-t" role="form" action="{{ buildUrl('/user/login') }}" method="post">
<div class="m-t login_wrap" role="form" >
<div class="form-group text-center">
<h2 class="font-bold">登录</h2>
</div>
@@ -24,8 +24,8 @@
<div class="form-group">
<input type="password" name="login_pwd" class="form-control" placeholder="请输入登录密码">
</div>
<button type="submit" class="btn btn-primary block full-width m-b">登录</button>
</form>
<button type="button" class="btn btn-primary block full-width m-b do-login">登录</button>
</div>
</div>
</div>
</div>
@@ -40,3 +40,7 @@
</div>
</div>
{% endblock %}
{% block js %}
<script src="{{buildStaticUrl('/js/user/login.js')}}"></script>
{% endblock %}