用户方法同步

duizhaopin
tangxuan 2 years ago
parent 4e7092f6ed
commit 95f63eafc4

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

Loading…
Cancel
Save