python学习
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,request,redirect
|
||||
from common.libs.Helper import ops_render,iPagination
|
||||
from flask import Blueprint,request,redirect,jsonify
|
||||
from common.libs.Helper import ops_render,iPagination,getCurrentDate
|
||||
from common.libs.UrlManager import UrlManager
|
||||
from common.libs.user.UserService import UserService
|
||||
from common.models.User import User
|
||||
from common.models.log.AppAccessLog import AppAccessLog
|
||||
from sqlalchemy import or_
|
||||
route_account = Blueprint( 'account_page',__name__ )
|
||||
from application import app,db
|
||||
@route_account.route( "/index" )
|
||||
@@ -13,12 +15,17 @@ def index():
|
||||
page = int(req['p']) if ('p' in req and req['p']) else 1
|
||||
query = User.query
|
||||
|
||||
if 'mix_kw' in req:
|
||||
rule = or_( User.nickname.ilike( "%{0}%".format( req['mix_kw'] ) ),User.mobile.ilike( "%{0}%".format( req['mix_kw'] ) ))
|
||||
query = query.filter( rule )
|
||||
if 'status' in req and int( req['status'] ) > -1:
|
||||
query = query.filter( User.status == int( req['status']) )
|
||||
page_params = {
|
||||
'total': query.count(),
|
||||
'page_size': app.config['PAGE_SIZE'],
|
||||
'page': page,
|
||||
'display': app.config['PAGE_DISPLAY'],
|
||||
'url': '/account/index'
|
||||
'url': request.full_path.replace( "&p={}".format(page),"")
|
||||
}
|
||||
|
||||
pages = iPagination(page_params)
|
||||
@@ -29,6 +36,8 @@ def index():
|
||||
|
||||
resp_data['list'] = list
|
||||
resp_data['pages'] = pages
|
||||
resp_data['search_con'] = req
|
||||
resp_data['status_mapping'] = app.config['STATUS_MAPPING']
|
||||
return ops_render("account/index.html", resp_data)
|
||||
|
||||
@route_account.route( "/info" )
|
||||
@@ -48,6 +57,111 @@ def info():
|
||||
|
||||
return ops_render("account/info.html", resp_data)
|
||||
|
||||
@route_account.route( "/set" )
|
||||
@route_account.route( "/set" ,methods=["GET", "POST"])
|
||||
def set():
|
||||
return ops_render( "account/set.html" )
|
||||
default_pwd = "******"
|
||||
if request.method == "GET":
|
||||
resp_data = {}
|
||||
req = request.args
|
||||
uid = int( req.get( "id",0))
|
||||
info = None
|
||||
if uid:
|
||||
info = User.query.filter_by( uid = uid ).first()
|
||||
resp_data['info'] = info
|
||||
return ops_render( "account/set.html",resp_data)
|
||||
resp = { 'code':200,'msg':'操作成功~~','data':{} }
|
||||
req = request.values
|
||||
|
||||
id = req['id'] if 'id' in req else 0
|
||||
nickname = req['nickname'] if 'nickname' in req else ''
|
||||
mobile = req['mobile'] if 'mobile' in req else ''
|
||||
email = req['email'] if 'email' in req else ''
|
||||
login_name = req['login_name'] if 'login_name' in req else ''
|
||||
login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
|
||||
|
||||
if nickname is None or len( nickname ) < 1:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入符合规范的姓名~~"
|
||||
return jsonify( resp )
|
||||
|
||||
if mobile is None or len( mobile ) < 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 )
|
||||
|
||||
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( email ) < 6:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入符合规范的登录密码~~"
|
||||
return jsonify( resp )
|
||||
|
||||
has_in = User.query.filter( User.login_name == login_name,User.uid!= id).first()
|
||||
if has_in:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "该登录名已存在,请换一个试试~~"
|
||||
return jsonify(resp)
|
||||
|
||||
user_info = User.query.filter_by(uid=id).first()
|
||||
if user_info:
|
||||
model_user = user_info
|
||||
else:
|
||||
model_user = User()
|
||||
model_user.created_time = getCurrentDate()
|
||||
model_user.login_salt = UserService.geneSalt()
|
||||
|
||||
model_user.nickname = nickname
|
||||
model_user.mobile = mobile
|
||||
model_user.email = email
|
||||
model_user.login_name = login_name
|
||||
|
||||
if login_pwd != default_pwd:
|
||||
model_user.login_pwd = UserService.genePwd( login_pwd,model_user.login_salt )
|
||||
|
||||
model_user.created_time = getCurrentDate()
|
||||
|
||||
db.session.add( model_user )
|
||||
db.session.commit()
|
||||
return jsonify(resp)
|
||||
|
||||
@route_account.route("/ops",methods = [ "POST" ])
|
||||
def ops():
|
||||
resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
|
||||
req = request.values
|
||||
|
||||
id = req['id'] if 'id' in req else 0
|
||||
act = req['act'] if 'act' in req else ''
|
||||
if not id :
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请选择要操作的账号~~"
|
||||
return jsonify(resp)
|
||||
|
||||
if act not in [ 'remove','recover' ] :
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "操作有误,请重试~~"
|
||||
return jsonify(resp)
|
||||
|
||||
user_info = User.query.filter_by(uid=id).first()
|
||||
if not user_info:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "指定账号不存在~~"
|
||||
return jsonify(resp)
|
||||
|
||||
if act == "remove":
|
||||
user_info.status = 0
|
||||
elif act == "recover":
|
||||
user_info.status = 1
|
||||
|
||||
user_info.update_time = getCurrentDate()
|
||||
db.session.add(user_info)
|
||||
db.session.commit()
|
||||
return jsonify(resp)
|
||||
|
||||
|
||||
@@ -36,9 +36,15 @@ def login():
|
||||
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)
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入正确的登录用户名和密码-2~~"
|
||||
return jsonify(resp)
|
||||
|
||||
if user_info.status !=1:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "帐号已被禁用,请联系管理员处理~~"
|
||||
return jsonify(resp)
|
||||
|
||||
|
||||
response = make_response(json.dumps(resp))
|
||||
response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' % (
|
||||
|
||||
@@ -5,6 +5,7 @@ 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 )
|
||||
from common.libs.LogService import LogService
|
||||
|
||||
import re
|
||||
@app.before_request
|
||||
@@ -22,7 +23,8 @@ def before_request():
|
||||
g.current_user=None
|
||||
if user_info:
|
||||
g.current_user=user_info
|
||||
|
||||
# 加入日志
|
||||
LogService.addAccessLog()
|
||||
pattern = re.compile('%s' % "|".join(ignore_urls))
|
||||
if pattern.match(path):
|
||||
return
|
||||
|
||||
9
web/interceptors/ErrorInterceptor.py
Normal file
9
web/interceptors/ErrorInterceptor.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from application import app
|
||||
from common.libs.Helper import ops_render
|
||||
from common.libs.LogService import LogService
|
||||
|
||||
@app.errorhandler( 404 )
|
||||
def error_404( e ):
|
||||
LogService.addErrorLog( str( e ) )
|
||||
return ops_render( 'error/error.html',{ 'status':404,'msg':'很抱歉!您访问的页面不存在' } )
|
||||
51
web/static/js/account/index.js
Normal file
51
web/static/js/account/index.js
Normal file
@@ -0,0 +1,51 @@
|
||||
;
|
||||
var account_index_ops = {
|
||||
init:function(){
|
||||
this.eventBind();
|
||||
},
|
||||
eventBind:function(){
|
||||
var that = this;
|
||||
$(".wrap_search .search").click(function(){
|
||||
$(".wrap_search").submit();
|
||||
});
|
||||
|
||||
$(".remove").click( function(){
|
||||
that.ops( "remove",$(this).attr("data") );
|
||||
} );
|
||||
|
||||
$(".recover").click( function(){
|
||||
that.ops( "recover",$(this).attr("data") );
|
||||
} );
|
||||
},
|
||||
ops:function( act,id ){
|
||||
var callback = {
|
||||
'ok':function(){
|
||||
$.ajax({
|
||||
url:common_ops.buildUrl( "/account/ops" ),
|
||||
type:'POST',
|
||||
data:{
|
||||
act:act,
|
||||
id:id
|
||||
},
|
||||
dataType:'json',
|
||||
success:function( res ){
|
||||
var callback = null;
|
||||
if( res.code == 200 ){
|
||||
callback = function(){
|
||||
window.location.href = window.location.href;
|
||||
}
|
||||
}
|
||||
common_ops.alert( res.msg,callback );
|
||||
}
|
||||
});
|
||||
},
|
||||
'cancel':null
|
||||
};
|
||||
common_ops.confirm( ( act == "remove" ? "确定删除?":"确定恢复?" ), callback );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$(document).ready( function(){
|
||||
account_index_ops.init();
|
||||
} );
|
||||
89
web/static/js/account/set.js
Normal file
89
web/static/js/account/set.js
Normal file
@@ -0,0 +1,89 @@
|
||||
;
|
||||
var account_set_ops = {
|
||||
init:function(){
|
||||
this.eventBind();
|
||||
},
|
||||
eventBind:function(){
|
||||
$(".wrap_account_set .save").click(function(){
|
||||
var btn_target = $(this);
|
||||
if( btn_target.hasClass("disabled") ){
|
||||
common_ops.alert("正在处理!!请不要重复提交~~");
|
||||
return;
|
||||
}
|
||||
|
||||
var nickname_target = $(".wrap_account_set input[name=nickname]");
|
||||
var nickname = nickname_target.val();
|
||||
|
||||
var mobile_target = $(".wrap_account_set input[name=mobile]");
|
||||
var mobile = mobile_target.val();
|
||||
|
||||
var email_target = $(".wrap_account_set input[name=email]");
|
||||
var email = email_target.val();
|
||||
|
||||
var login_name_target = $(".wrap_account_set input[name=login_name]");
|
||||
var login_name = login_name_target.val();
|
||||
|
||||
var login_pwd_target = $(".wrap_account_set input[name=login_pwd]");
|
||||
var login_pwd = login_pwd_target.val();
|
||||
|
||||
if( nickname.length < 1 ){
|
||||
common_ops.tip( "请输入符合规范的姓名~~",nickname_target );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( mobile.length < 1 ){
|
||||
common_ops.tip( "请输入符合规范的手机号码~~",mobile_target );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( email.length < 1 ){
|
||||
common_ops.tip( "请输入符合规范的邮箱~~",email_target );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( login_name.length < 1 ){
|
||||
common_ops.tip( "请输入符合规范的登录用户名~~",login_name_target );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( login_pwd.length < 6 ){
|
||||
common_ops.tip( "请输入符合规范的登录密码~~",login_pwd_target );
|
||||
return false;
|
||||
}
|
||||
|
||||
btn_target.addClass("disabled");
|
||||
|
||||
var data = {
|
||||
nickname: nickname,
|
||||
mobile: mobile,
|
||||
email: email,
|
||||
login_name:login_name,
|
||||
login_pwd:login_pwd,
|
||||
id:$(".wrap_account_set input[name=id]").val()
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url:common_ops.buildUrl( "/account/set" ),
|
||||
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 = common_ops.buildUrl("/account/index");
|
||||
}
|
||||
}
|
||||
common_ops.alert( res.msg,callback );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready( function(){
|
||||
account_set_ops.init();
|
||||
} );
|
||||
@@ -1,16 +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('/account/index') }}">账户列表</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% include "common/tab_account.html" %}
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<form class="form-inline wrap_search">
|
||||
@@ -18,15 +8,17 @@
|
||||
<div class="form-group">
|
||||
<select name="status" class="form-control inline">
|
||||
<option value="-1">请选择状态</option>
|
||||
<option value="1">正常</option>
|
||||
<option value="0">已删除</option>
|
||||
{% for tmp_key in status_mapping %}
|
||||
<option value="{{tmp_key}}" {% if tmp_key==search_con['status'] %} selected {% endif %}>{{ status_mapping[ tmp_key] }}</option>
|
||||
{% endfor %}
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<input type="text" name="mix_kw" placeholder="请输入姓名或者手机号码" class="form-control" value="">
|
||||
<input type="hidden" name="p" value="1">
|
||||
<input type="text" name="mix_kw" placeholder="请输入姓名或者手机号码" class="form-control" value="{{ search_con['mix_kw']}}">
|
||||
<input type="hidden" name="p" value="{{ search_con['p']}}">
|
||||
<span class="input-group-btn">
|
||||
<button type="button" class="btn btn-primary search">
|
||||
<i class="fa fa-search"></i>搜索
|
||||
@@ -96,3 +88,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block js %}
|
||||
<script src="{{ buildStaticUrl('/js/account/index.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,16 +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('/account/index') }}">账户列表</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% include "common/tab_account.html" %}
|
||||
<div class="row m-t wrap_account_set">
|
||||
<div class="col-lg-12">
|
||||
<h2 class="text-center">账号设置</h2>
|
||||
@@ -18,41 +8,41 @@
|
||||
<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="">
|
||||
<input type="text" name="nickname" class="form-control" placeholder="请输入姓名~~" value="{{ info.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="mobile" class="form-control" placeholder="请输入手机~~" value="">
|
||||
<input type="text" name="mobile" class="form-control" placeholder="请输入手机~~" value="{{ info.mobile}}">
|
||||
</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="">
|
||||
<input type="text" name="email" class="form-control" placeholder="请输入邮箱~~" value="{{ info.email}}">
|
||||
</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="login_name" class="form-control" autocomplete="off" placeholder="请输入登录名~~" value="">
|
||||
<input type="text" name="login_name" class="form-control" autocomplete="off" placeholder="请输入登录名~~" value="{{ info.login_name}}">
|
||||
</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="password" name="login_pwd" class="form-control" autocomplete="new-password" placeholder="请输入登录密码~~" value="">
|
||||
<input type="password" name="login_pwd" class="form-control" autocomplete="new-password" placeholder="请输入登录密码~~" value="******">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-lg-4 col-lg-offset-2">
|
||||
<input type="hidden" name="id" value="0">
|
||||
<input type="hidden" name="id" value="{{ info.uid}}">
|
||||
<button class="btn btn-w-m btn-outline btn-primary save">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,3 +50,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block js %}
|
||||
<script src="{{ buildStaticUrl('/js/account/set.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user