def modify_password(cls, userid, oldpassword, newpassword, project_id): roles_row = UserBusiness.query_json_by_id_and_project( g.userid, project_id) roles_list = roles_row[0]['role'] if roles_row else [] roles = [i['name'] for i in roles_list] if userid == g.userid or g.is_admin or 'owner' in roles: user = User.query.get(userid) if user.password == parse_pwd(oldpassword): user.password = parse_pwd(newpassword) db.session.add(user) db.session.commit() return 0 return 301 return 108
def create_new_wxuser(cls, username, nickname, password, email, telephone, avatar): try: ret = User.query.filter(User.name == username, User.status == User.ACTIVE).first() if ret: return 103, None n = User(name=username, wx_userid=username, nickname=nickname, password=parse_pwd(password), email=email, telephone=telephone, ext=1, picture=avatar) db.session.add(n) try: TrackUserBusiness.user_track(n) except Exception as e: current_app.logger.info(e) db.session.commit() return 0, None except Exception as e: current_app.logger.error(str(e)) return 102, str(e)
def create_new_user_and_bind_roles(cls, username, nickname, password, email, telephone): try: ret = User.query.filter(User.name == username, User.status == User.ACTIVE).first() if ret: return 103, None n = User(name=username, nickname=nickname, password=parse_pwd(password), email=email, telephone=telephone) db.session.add(n) # TrackUserBusiness.data_create_data(n.id,n.name,'',n.nickname,n.email,n.telephone) db.session.commit() # nuid = n.id # for rid in roleids: # t = UserBindRole(user_id=nuid, role_id=rid) # db.session.add(t) # db.session.commit() return 0, None except Exception as e: current_app.logger.error(str(e)) return 102, str(e)
def reset_password(cls, userid, newpassword, project_id): roles_row = UserBusiness.query_json_by_id_and_project( g.userid, project_id) roles_list = roles_row[0]['role'] if roles_row else [] modi_roles_row = UserBusiness.query_json_by_id_and_project( userid, project_id) modi_roles_list = modi_roles_row[0]['role'] if modi_roles_row else [] roles = [i['name'] for i in roles_list] modi_roles = [i['name'] for i in modi_roles_list] if 'admin' in modi_roles: if 'admin' not in roles: raise OperationPermissionDeniedException('权限不够,请联系管理员') if userid == g.userid or g.is_admin or 'owner' in roles: user = User.query.get(userid) user.password = parse_pwd(newpassword) db.session.add(user) db.session.commit() return 0, None raise OperationPermissionDeniedException('权限不够,请联系管理员')
def login(cls, username, password): ret = User.query.filter_by( name=username, password=parse_pwd(password), status=User.ACTIVE).all() if len(ret) == 0: return 303, [] userid = ret[0].id userdetail = UserBusiness.query_json_by_id(userid) projectid = UserBusiness.query_project_by_userid(userid) if userdetail: userdetail[0]['projectid'] = projectid token = cls.jwt_b_encode(userdetail[0]).decode('utf-8') data = dict(token=token) try: res = User.query.filter(User.id == userid, User.status == User.ACTIVE).first() TrackUserBusiness.user_track(res) except Exception as e: current_app.logger.info(e) return 0, data else: return 413, []
def is_reset_passwd(cls, userid): user = User.query.get(userid) if user.password == parse_pwd(''): return 0, [{'is_reset_password': 0}] return 0, [{'is_reset_password': 1}]