from datetime import datetime
from flask import Blueprint, render_template, jsonify, request, redirect, url_for
from flask_login import login_required, current_user
from exts import db
from user import user_add, info_add, user_get, info_exist, info_get, info_modify, user_exist, user_modify
import json
bp_usr = Blueprint(name='usrman', import_name='usrman')
@bp_usr.route('/')
@login_required
def users():
return render_template('users.html')
@bp_usr.route('/getusers/<string:type>')
@login_required
def getusers(type='all'):
if type == 'all':
sql = '''select * from user,user_info where user.id=user_info.id'''
elif type == 'users':
sql = '''select * from user,user_info where user.id=user_info.id and user.type=2'''
userslist = db.session.execute(sql).fetchall()
db.session.close()
usersdict = [dict(zip(result.keys(), result)) for result in userslist]
for user in usersdict:
user['faceb64'] = user['faceb64'].decode()
birth = user['birthdate']
now = datetime.now()
user['age'] = now.year - birth.year
user['birthdatestr'] = birth.strftime('%Y-%m-%d')
username = request.args.get('key[username]')
usersearh = []
if username is not None:
for user in usersdict:
if username in user['username']:
usersearh.append(user)
else:
usersearh = usersdict
response = {
'code': 0,
'msg': "success",
'count': len(usersearh),
'data': usersearh
}
return jsonify(response)
@bp_usr.route('/getusersnoinfo')
@login_required
def getusersnoinfo():
sql = '''select *
from user
where user.id not in (
select id
from user_info)'''
userslist = db.session.execute(sql).fetchall()
db.session.close()
usersdict = [dict(zip(result.keys(), result)) for result in userslist]
for user in usersdict:
user['faceb64'] = user['faceb64'].decode()
username = request.args.get('key[username]')
usersearh = []
if username is not None:
for user in usersdict:
if username in user['username']:
usersearh.append(user)
else:
usersearh = usersdict
response = {
'code': 0,
'msg': "success",
'count': len(usersearh),
'data': usersearh
}
return jsonify(response)
@bp_usr.route('/add', methods=['POST', 'GET'])
@login_required
def adduser():
if request.method == 'GET':
if current_user.type == 0: # 管理员可添加用户
return render_template('adduser.html')
else:
return '无操作权限'
elif request.method == 'POST':
psw = request.form.get('psw', default='123456')
username = request.form.get('username')
type = request.form.get('type')
gender = request.form.get('gender')
birthdate = request.form.get('birthdate')
birthdate = datetime.strptime(birthdate, '%Y-%m-%d')
nickname = request.form.get('nickname')
faceb64 = request.form.get('faceb64')
id = user_add(username, type, psw, faceb64)
info_add(id, gender, birthdate, nickname)
return f'添加成功!'
@bp_usr.route('/addinfo', methods=['POST', 'GET'])
@login_required
def addinfo():
if request.method == 'GET':
id = current_user.id
if info_exist(id):
return render_template('infoexist.html')
else:
return render_template('addinfo.html', id=id)
elif request.method == 'POST':
id = request.form.get('id')
if current_user.type != 0 and id != current_user.id:
return '权限不足!'
gender = request.form.get('gender')
birthdate = request.form.get('birthdate')
birthdate = datetime.strptime(birthdate, '%Y-%m-%d')
nickname = request.form.get('nickname')
info_add(id, gender, birthdate, nickname)
return '录入成功!'
@bp_usr.route('/modifyinfo', methods=['POST', 'GET'])
@login_required
def modifyinfo():
if request.method == 'GET':
id = current_user.id
if not info_exist(id):
return render_template('infonotexist.html')
else:
user_info = info_get(id)
return render_template('infomodify.html', info=user_info)
elif request.method == 'POST':
id = current_user.id
nickname = request.form.get('nickname')
psw = request.form.get('password')
gender = request.form.get('gender')
birthdate = request.form.get('birthdate')
birthdate = datetime.strptime(birthdate, '%Y-%m-%d')
info_modify(id, gender, birthdate, nickname)
if psw != '':
user_modify(id, psw)
return '修改成功!'
@bp_usr.route('/modifyinfoof', methods=['POST', 'GET'])
@login_required
def modifyinfoof():
if request.method == 'GET':
if current_user.type != 0:
error = {
'message': '权限不足',
'next': '/users/modifyinfo'
}
return render_template('error.html', error=error)
else:
return render_template('infomodifyof.html')
elif request.method == 'POST':
id = request.form.get('id')
if not user_exist(id):
response = {
'code': -1,
'message': '用户不存在'
}
elif user_get(id).type < current_user.type:
response = {
'code': 0,
'message': '权限不足!'
}
else:
response = {
'code': 1,
'message': '验证通过'
}
return response
@bp_usr.route('/modifyinfoof/<int:id>', methods=['POST', 'GET'])
@login_required
def modifyinfoofid(id):
if request.method == 'GET':
if not user_exist(id):
error = {
'message': '用户不存在!',
'next': '/users/modifyinfoof'
}
return render_template('error.html', error=error)
elif current_user.type != 0:
error = {
'message': '权限不足!',
'next': '/users/modifyinfo'
}
return render_template('error.html', error=error)
else:
user_info = info_get(id)
return render_template('infomodify.html', info=user_info)
elif request.method == 'POST':
psw = request.form.get('password')
gender = request.form.get('gender')
birthdate = request.form.get('birthdate')
birthdate = datetime.strptime(birthdate, '%Y-%m-%d')
nickname = request.form.get('nickname')
info_modify(id, gender, birthdate, nickname)
if psw != '':
user_modify(id, psw)
return '修改成功!'
@bp_usr.route('/addinfoof', methods=['POST', 'GET'])
@login_required
def addinfoof():
if request.method == 'GET':
if current_user.type > 1:
id = current_user.id
return render_template('addinfo.html', id=id)
else:
return render_template('addinfoof.html')
@bp_usr.route('/addinfoof/<int:id>', methods=['POST', 'GET'])
@login_required
def addinfoofid(id):
if request.method == 'GET':
if not user_exist(id):
error = {
'message': '用户不存在!',
'next': '/users/modifyinfoof'
}
return render_template('error.html', error=error)
elif current_user.type > 1:
error = {
'message': '权限不足,您仅可录入自己信息!',
'next': '/users/addinfo'
}
return render_template('error.html', error=error)
elif user_get(id).type < current_user.type:
error = {
'message': '权限不足,您仅可录入权限小于自己的信息!',
'next': '/users/addinfoof'
}
程序员张小妍
- 粉丝: 1w+
- 资源: 3691
最新资源
- 恒压供水一拖三程序 全网中这是本人原创,拿的另赠FB块 1.采用三菱FX3U CPU 加2N2AD和4DA模块; 2.触摸屏采用昆仑通态;同时串口通讯PLC和485通迅变频器; 3.PL
- cruise matlab纯电动二档实际模型,核心问题:计算最优速比和最优档策略,可以延伸到多档变速器领域 一个模型搞定纯电动车动力性经济性计算问题
- MATLAB代码:考虑安全约束及热备用的电力系统机组组合研究 关键词:机组组合 直流潮流 优化调度 仿真平台:MATLAB+CPLEX gurobi平台 优势:代码具有一定的深度和创新性,注释清晰
- 西门子PLC 和v90 伺服变频器G120通讯 2台西门子变频器G120 Profinet通讯,4台伺服V90 PN口通讯,变频器和伺服已写好FB块,非常好用,方便省事,不必再每个写梯形图浪费时间
- ethercat主站soem开发板,stm32f407 stm32h7低成本主站方案,带台达伺服电机,ls伺服电机,三洋伺服电机,汇川伺服电机,雷塞智能步进电机等支持ethercat的设备 支持DC
- 电机控制源码 电机控制源码,BLDC无刷直流电机基于stm3 2F1的有传感器和无传感驱动 直流无刷电机有传感器和无传感驱动程序识的赶紧上车 无传感的的实现是基于反电动势过零点实现的,无传感是霍尔实
- 上位机控制三菱变频器 DEMO (VB.NET), (可编辑上位机与三菱PLC,西门子PLC通讯, 数据采集,)源码带详细注释 本程序有详细步骤和超详细的中文注释,可以控制多台变频器,采用mod
- 三菱Q型pLc.QD75Mh4定位及控制.4轴伺服定位及控制,触摸屏及plc程序,三菱伺服,光纤伺服通讯,参考性强,已安全应用,4轴机械手抓拿焊接线,技术性资料
- 西门子200smart PLC与昆仑通态触摸屏所写的脉冲除尘器程序 20个仓,每个仓包含12个脉冲阀,手动和自动控制,定时延时切仓门和脉冲阀 包含PLC程序,触摸屏组态画面,工艺流程,电气原理图
- 堪比QT控件漂亮的LabVIEW俱全控件 一位老工程师,多年的经验积累的
- ESP8266生成二维码算法 OLED显示 支持各种平台移植 算法部分采用c语言,可以移植到各种平台 代码有两种,一种是arduino开发的,一种是乐鑫sdk安信可开发环境的 两种任选一种,联系
- ACS800防爆变频器设计方案,全套图纸、电路板、程序
- 机械臂视觉抓取仿真,vrep与matlab联合仿真示例,仅供学习 matlab端通过GUI控制机械臂抓不同的物体,在matlab端有简单的图像处理算法,未优化,可以自己改进 基础太差的勿用
- 三菱Q系列PLC大型程序Q01U伺服12轴 实际使用中程序 2个模块QD70P8,QD70P4控制12轴 模块QD62外接欧姆龙编码器E6C2-CWZ6C 模块QJ71C24N-R2和基恩士DL-RS
- 西门子PID程序,西门子PLC 1200和多台G120西门子变频器Modbud RTU通讯,带西门子触摸屏,带变频器参数 Modbus通讯报文详细讲解,PID自写FB块无密码可以直接应用到程序,PID
- FPGA以太网 TOE TCP IP协议栈 源码 千兆,万兆 ping,arp,igmp,udp,tcp,dhcp…… 提供k7板卡测试工程,纯hdl的,轻松移植到任意fpga
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈