用户方法同步

duizhaopin
tangxuan 2 years ago
parent 4e7092f6ed
commit 95f63eafc4

@ -6,6 +6,7 @@
import sys
import sqlalchemy
sys.path.append(".")
import jwt
import base64
@ -16,13 +17,14 @@ from db_logic.db_base import Repository
from models.user_models import EntityUser
from Common.Utils import Utils
#用户操作业务逻辑类
# 用户操作业务逻辑类
class BllUser(Repository):
def __init__(self, entityType=EntityUser):
return super().__init__(entityType)
#用户账号密码登录
# 用户账号密码登录
def login(self, user_name, password):
user_info = self.findEntity(
or_(
@ -33,11 +35,11 @@ class BllUser(Repository):
if user_info:
if user_info.is_enabled:
if str(user_info.password).lower() == Utils.MD5(password).lower():
self.last_visit_date=Utils.get_str_datetime()
self.last_visit_date = Utils.get_str_datetime()
self.update(user_info)
return self.get_jwt(user_info), user_info
return False, None
# 用户密码修改
def update_password(self, user_info, old_password, new_password):
if user_info.password == Utils.MD5(old_password):
@ -46,8 +48,8 @@ class BllUser(Repository):
return True, self.get_jwt(user_info)
else:
return False, "旧密码错误"
def get_jwt(self, obj, expires_in=36000):
def get_jwt(self, obj, expires_in=36000):
'''用户登录后,发放有效的 JWT'''
now = datetime.datetime.now()
payload = {
@ -76,9 +78,10 @@ class BllUser(Repository):
return None
# return User.query.get(payload.get('user_id'))
return self.findEntity(payload.get('user_id'))
# 用户管理
def get_seach_user_list(self, user_code, real_name, role_name, is_enabled, page_param, user_id,role_name_self):
def get_seach_user_list(self, user_code, real_name, role_name, role_id, is_enabled, page_param, user_id,
role_name_self):
filter_base = ""
if user_code:
filter_base += f" user_code like '%{user_code}%'"
@ -90,23 +93,22 @@ class BllUser(Repository):
if filter_base:
filter_base += " and "
filter_base += f" role_name like '%{role_name}%'"
if role_id:
if filter_base:
filter_base += " and "
filter_base += f" role_id='{role_id}' "
if is_enabled:
if filter_base:
filter_base += " and "
filter_base += f" is_enabled={is_enabled}"
# if filter_base:
# filter_base += " and "
# filter_base += f" user_id != '{user_id}' "
# if filter_base:
# filter_base = f" where {filter_base}"
if role_name_self !='管理员':
if filter_base:
filter_base += " and "
filter_base += f" user_id = '{user_id}' "
# if role_name_self !='管理员':
# if filter_base:
# filter_base += " and "
# filter_base += f" user_id = '{user_id}' "
if filter_base:
filter_base = f" where {filter_base}"
filter_base = f" where {filter_base}"
sql_all = f"""
select * from rms_user {filter_base} order by create_date desc
"""
@ -118,8 +120,6 @@ class BllUser(Repository):
sql_page = Utils.sql_paging_assemble(sql_all, page_param)
return self.execute(sql_page).fetchall()
# #根据条码获取用户
# def getUserByBarCode(self, barCode):
# return self.findEntity(EntityUser.BarCode == barCode)

Loading…
Cancel
Save