2019-07-21 18:20:01 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-07-29 15:28:02 +08:00
|
|
|
from flask import Blueprint,request,redirect,jsonify
|
|
|
|
|
from common.libs.Helper import ops_render,iPagination,getCurrentDate
|
2019-07-22 18:07:14 +08:00
|
|
|
from common.libs.UrlManager import UrlManager
|
2019-07-29 15:28:02 +08:00
|
|
|
from common.libs.user.UserService import UserService
|
2019-07-22 17:41:42 +08:00
|
|
|
from common.models.User import User
|
2019-07-22 18:07:14 +08:00
|
|
|
from common.models.log.AppAccessLog import AppAccessLog
|
2019-07-29 15:28:02 +08:00
|
|
|
from sqlalchemy import or_
|
2019-07-21 18:20:01 +08:00
|
|
|
route_account = Blueprint( 'account_page',__name__ )
|
2019-07-22 17:58:38 +08:00
|
|
|
from application import app,db
|
2019-07-21 18:20:01 +08:00
|
|
|
@route_account.route( "/index" )
|
|
|
|
|
def index():
|
2019-07-22 17:58:38 +08:00
|
|
|
resp_data = {}
|
|
|
|
|
req = request.values
|
|
|
|
|
page = int(req['p']) if ('p' in req and req['p']) else 1
|
|
|
|
|
query = User.query
|
|
|
|
|
|
2019-07-29 15:28:02 +08:00
|
|
|
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']) )
|
2019-07-22 17:58:38 +08:00
|
|
|
page_params = {
|
|
|
|
|
'total': query.count(),
|
|
|
|
|
'page_size': app.config['PAGE_SIZE'],
|
|
|
|
|
'page': page,
|
|
|
|
|
'display': app.config['PAGE_DISPLAY'],
|
2019-07-29 15:28:02 +08:00
|
|
|
'url': request.full_path.replace( "&p={}".format(page),"")
|
2019-07-22 17:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pages = iPagination(page_params)
|
|
|
|
|
offset = (page - 1) * app.config['PAGE_SIZE']
|
|
|
|
|
limit = app.config['PAGE_SIZE'] * page
|
|
|
|
|
|
|
|
|
|
list = query.order_by(User.uid.desc()).all()[offset:limit]
|
|
|
|
|
|
|
|
|
|
resp_data['list'] = list
|
|
|
|
|
resp_data['pages'] = pages
|
2019-07-29 15:28:02 +08:00
|
|
|
resp_data['search_con'] = req
|
|
|
|
|
resp_data['status_mapping'] = app.config['STATUS_MAPPING']
|
2019-07-22 17:58:38 +08:00
|
|
|
return ops_render("account/index.html", resp_data)
|
2019-07-21 18:20:01 +08:00
|
|
|
|
|
|
|
|
@route_account.route( "/info" )
|
|
|
|
|
def info():
|
2019-07-22 18:07:14 +08:00
|
|
|
resp_data = {}
|
|
|
|
|
req = request.args
|
|
|
|
|
uid = int(req.get('id', 0))
|
|
|
|
|
reback_url = UrlManager.buildUrl("/account/index")
|
|
|
|
|
if uid < 1:
|
|
|
|
|
return redirect(reback_url)
|
|
|
|
|
|
|
|
|
|
info = User.query.filter_by(uid=uid).first()
|
|
|
|
|
if not info:
|
|
|
|
|
return redirect(reback_url)
|
|
|
|
|
|
2019-07-31 17:12:55 +08:00
|
|
|
access_list = AppAccessLog.query.filter_by(uid=uid).order_by(AppAccessLog.id.desc()).limit(10).all()
|
2019-07-22 18:07:14 +08:00
|
|
|
resp_data['info'] = info
|
2019-07-31 17:12:55 +08:00
|
|
|
resp_data['access_list'] = access_list
|
2019-07-22 18:07:14 +08:00
|
|
|
|
|
|
|
|
return ops_render("account/info.html", resp_data)
|
2019-07-21 18:20:01 +08:00
|
|
|
|
2019-07-29 15:28:02 +08:00
|
|
|
@route_account.route( "/set" ,methods=["GET", "POST"])
|
2019-07-21 18:20:01 +08:00
|
|
|
def set():
|
2019-07-29 15:28:02 +08:00
|
|
|
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)
|
|
|
|
|
|