def query_user_by_name_cache( name): key = _user_by_name_key % name user = redis_cache.getObj(key) if None == user: user = query_one_by_name(name = name) redis_cache.setObj(key = key, val = user, time = config.cache['apiTimeOut']) return user
def get(self): ps = self.get_page_config('后台') token = self.get_args(['token'], '') ps['token'] = token['token'] user = self.current_user if None == user: ''' 判断用户是否存在,如果不存在,判断token重新登录 ''' if '' == ps['token']: params = { 'backUrl': config.urls['adminBackUrl'], 'appCode': ps['appCode'] } url = self.format_url(config.urls['loginUrl'], params) self.redirect(url) return else: user = soc_right_proxy.get_login_user(token=ps['token']) if user == '' or type(user) != dict or user.get('email', '') == '': ''' 无法获取用户信息,重新登录 ''' self.redirect(config.urls['loginUrl']) return else: rights = user.get('rights', []) uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut']) self.set_cookie(name=config.SOCPMConfig['adminCookieName'], value=uuid, expires=ex) ps['user'] = user self.render('admin/main.html', **ps)
def get(self): ps = self.get_page_config('后台') token = self.get_args(['token'], '') ps['token'] = token['token'] user = self.current_user if None == user: ''' 判断用户是否存在,如果不存在,判断token重新登录 ''' if '' == ps['token']: params = {'backUrl':config.urls['adminBackUrl'], 'appCode': ps['appCode']} url = self.format_url(config.urls['loginUrl'] , params) self.redirect(url) return else: user = soc_right_proxy.get_login_user(token = ps['token']) if None == user or type(user) != dict or user.get('email','') == '': ''' 无法获取用户信息,重新登录 ''' self.redirect(config.urls['loginUrl']) return else: rights = user.get('rights', []) #for right in rights: # right[''] uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut']) self.set_cookie(name = config.SOCRightConfig['adminCookieName'], value=uuid, expires=ex) ps['user'] = user self.render('admin/main.html', **ps)
def get_goto_user_url( userID, appCode, ip, backUrl = ''): ''' 保存为这样的格式: {"id": 1, "tel": "123", "email": "*****@*****.**", "name": "\u4f59\u6d77", "rights": [{"id":12, "path":"xx.aa", "realName":"abc","right":1, "customRight": [1,2,3]}, {"id":13, "path":"xx.aa.bb","right":1, "customRight": []}]} {"code":0,"msg":"OK","data":{"tel": "123", "name": "yuhai", "rights": [{"path": "SOCRight.Login", "right": 15, "id": 18, "customRight": []}, {"path": "SOCRight.AppManager", "right": 15, "id": 9, "customRight": []}, {"path": "SOCRight.FuncManager", "right": 15, "id": 10, "customRight": [1, 2]}, {"path": "SOCRight.UserManager", "right": 15, "id": 11, "customRight": []}, {"path": "SOCRight.UserManager.UserBindRoleManager", "right": 15, "id": 14, "customRight": []}, {"path": "SOCRight.UserGroupManager", "right": 15, "id": 12, "customRight": []}, {"path": "SOCRight.UserGroupManager.UserGroupBindRoleManager", "right": 15, "id": 15, "customRight": []}, {"path": "SOCRight.UserGroupManager.UserGroupBindUserManager", "right": 15, "id": 16, "customRight": []}, {"path": "SOCRight.RoleManager", "right": 15, "id": 13, "customRight": []}, {"path": "SOCRight.RoleManager.RoleBindRightManager", "right": 15, "id": 17, "customRight": []}], "mobile": "123", "id": 1, "email": "*****@*****.**", "realName": "\u4f59\u6d77"}} ''' u = query_one(userID) if None == u: return None user = {} user['id'] = u['id'] user['realName'] = u['realName'] user['email'] = u['email'] user['mobile'] = u['mobile'] user['tel'] = u['tel'] user['name'] = u['name'] funcs = query_user_app_right(userID = userID, appCode = appCode) rights = [] rightType = False if None != funcs and len(funcs) > 0: for func in funcs: right = {} right['id'] = func['id'] right['path'] = func['path'] right['right'] = func.get('right', 0) if right['right'] > 0 and not rightType: rightType = True cr = [] if func['customJson'] != None: for j in func['customJson']: if j['right']: cr.append(j['k']) right['customRight'] = cr rights.append(right) user['rights'] = rights uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userRightTimeOut']) params = {'token':uuid} if backUrl != '': gotoUrl = str_helper.format_url(url = backUrl, params = params) else: app = application_logic.query_one(code = appCode) gotoUrl = str_helper.format_url(url = app['url'], params = params) update_goto_app(name = user['name'], appCode = appCode, ip = ip) return gotoUrl
def post(self): ps = self.get_page_config('登录') host = self.request.host if host not in ps['serviceSiteDomain']: self.redirect(ps['siteDomain'] + 'Admin') ps = self.get_args( ls=['backUrl', 'appCode', 'userName', 'passWord'], default='', map=ps) if ps['userName'] == '' or ps['passWord'] == '': self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100001') return user = user_logic.login(ps['userName'], ps['passWord']) if None == user: self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100002') return uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut']) self.clear_all_cookies() self.set_cookie(name=config.SOCRightConfig[ 'rightCookieName'], value=uuid, expires=ex) ''' 记录日志 ''' ac = ps['appCode'] if None == ac or '' == ac: ac = 'SOCRight' oper_log_logic.add(operID=user['id'], operUserName=user['name'], operRealName=user[ 'realName'], appCode=ac, funcPath='', action='userLogin', targetType=0, targetID='', targetName='', startStatus='', endStatus='', operIp=self.get_user_ip()) if None != user['loginCount'] and 0 >= user['loginCount'] and 'passwordedit' not in self.request.path.lower(): params = {'msg': '100003'} url = self.format_url(config.SOCRightConfig[ 'serviceSiteDomain'] + 'PassWordEdit', params) self.redirect(url) return if ps['appCode'] != '': if None == user['loginCount'] or 0 == user['loginCount']: self.redirect(ps['serviceSiteDomain'] + 'PassWordEdit?msg=100003&appCode=' + str_helper.url_escape(ps['appCode']) + '&backUrl=' + str_helper.url_escape(ps['backUrl'])) backUrl = user_logic.get_goto_user_url( userID=user['id'], appCode=ps['appCode'], ip=self.get_user_ip(), backUrl=ps['backUrl']) self.redirect(backUrl) else: self.redirect(ps['serviceSiteDomain'] + 'AppList')
def get_user_info_by_token(self , token): user = soc_right_proxy.get_login_user(token = token) if None == user or type(user) != dict or user.get('email','') == '': ''' 无法获取用户信息,重新登录 ''' self.redirect(config.urls['loginUrl']) return else: rights = user.get('rights', []) user['loginToken'] = token uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) ex = datetime.now() + timedelta(seconds=config.cache['userTimeOut']) self.set_cookie(name = config.SOCRightConfig['adminCookieName'], value=uuid, expires=ex) return user
def get_user_info_by_token(self, token): user = soc_right_proxy.get_login_user(token=token) if None == user or type(user) != dict or user.get('email', '') == '': ''' 无法获取用户信息,重新登录 ''' self.redirect(config.urls['loginUrl']) return else: rights = user.get('rights', []) user['loginToken'] = token uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) ex = datetime.now() + timedelta(seconds=config.cache['userTimeOut']) self.set_cookie(name=config.SOCRightConfig['adminCookieName'], value=uuid, expires=ex) return user
def post(self): ps = self.get_page_config('登录') ps['appcode'] = self.get_arg('appcode', ps['appcode']) username = self.get_arg('username', '') password = self.get_arg('password', '') if username == '' or password == '': self.redirect("/Login?msg=100001") return user = user_logic.UserLogic.instance().login(username, password, ps['appcode']) if None == user: self.redirect("/Login?msg=100002") return uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) self.set_cookie(name = config.SOCRightConfig['cookiename'], value=uuid, expires=config.cache['userTimeOut']) self.render("login.html", **ps)
def post(self): ps = self.get_page_config('登录') ps['appcode'] = self.get_arg('appcode', ps['appcode']) username = self.get_arg('username', '') password = self.get_arg('password', '') if username == '' or password == '': self.redirect("/Login?msg=100001") return user = user_logic.login(username, password, ps['appcode']) if None == user: self.redirect("/Login?msg=100002") return uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) self.set_cookie(name = config.SOCRightConfig['cookiename'], value=uuid, expires=config.cache['userTimeOut']) self.render("login.html", **ps)
def post(self): ps = self.get_page_config('登录') host = self.request.host if host not in ps['serviceSiteDomain']: self.redirect(ps['siteDomain'] + 'Admin') ps = self.get_args(ls=['backUrl', 'appCode', 'userName', 'passWord'], default='', map=ps) if ps['userName'] == '' or ps['passWord'] == '': self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100001') return user = user_logic.login(ps['userName'], ps['passWord']) if None == user: self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100002') return uuid = str_helper.get_uuid() redis_cache.setObj(uuid, user, config.cache['userTimeOut']) ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut']) self.clear_all_cookies() self.set_cookie(name=config.SOCRightConfig['rightCookieName'], value=uuid, expires=ex) ''' 记录日志 ''' ac = ps['appCode'] if None == ac or '' == ac: ac = 'SOCRight' oper_log_logic.add(operID=user['id'], operUserName=user['name'], operRealName=user['realName'], appCode=ac, funcPath='', action='userLogin', targetType=0, targetID='', targetName='', startStatus='', endStatus='', operIp=self.get_user_ip()) if None != user['loginCount'] and 0 >= user[ 'loginCount'] and 'passwordedit' not in self.request.path.lower( ): params = {'msg': '100003'} url = self.format_url( config.SOCRightConfig['serviceSiteDomain'] + 'PassWordEdit', params) self.redirect(url) return if ps['appCode'] != '': if None == user['loginCount'] or 0 == user['loginCount']: self.redirect(ps['serviceSiteDomain'] + 'PassWordEdit?msg=100003&appCode=' + str_helper.url_escape(ps['appCode']) + '&backUrl=' + str_helper.url_escape(ps['backUrl'])) backUrl = user_logic.get_goto_user_url(userID=user['id'], appCode=ps['appCode'], ip=self.get_user_ip(), backUrl=ps['backUrl']) self.redirect(backUrl) else: self.redirect(ps['serviceSiteDomain'] + 'AppList')