def getUserNameById(userid): if not userid: return Common.falseReturn(None,'userid is required') user = blogDB.getUserById(userid) if user: return Common.trueReturn(user[1],'query ok') else: return Common.falseReturn(None,'not found')
def updateUserBase(userid,username,password): if not blogDB.getUserById(userid): return Common.falseReturn(None, "{} doesn't exist in user_base".format(userid)) if not username or not password: return Common.falseReturn(None, 'username or password cannot be empty') if blogDB.updateUser(userid,username,IdentifyUtil.hash_secret(password)): return Common.trueReturn({'userid':userid},'change ok') else: return Common.falseReturn(None,'change false')
def registerUserInfo(userid,realname,phone,idcard,email,avatarurl): if not blogDB.getUserById(userid) : return Common.falseReturn(None,"{} doesn't exist in user_base".format(userid)) if not realname or not phone or not idcard or not email: return Common.falseReturn(None,'params cannot be none') if not blogDB.getUserInfoById(userid) is None: return Common.falseReturn(None,"{} is already exists in user_info ".format(userid)) if blogDB.addUserInfo(userid, realname, idcard, phone, email,avatarurl): return Common.trueReturn(userid,'register ok') else: return Common.falseReturn(None,'unknown reason')
def identify(auth_request): '''用户鉴权*''' auth_header = auth_request.headers.get('Authorization') if auth_header: auth_tokenArr = auth_header.split(" ") if not auth_tokenArr or auth_tokenArr[0] != 'JWT' or len( auth_tokenArr) != 2: return Common.falseReturn( None, 'Please Make Sure JWT Token in Autorization') else: auth_token = auth_tokenArr[1] payload = Authority.decode_jwt(auth_token) if not isinstance(payload, str): user = blogDB.getUserById(payload['data']['id']) if user is not None: return Common.trueReturn(payload['data']['id'], 'Account Verify OK') else: return Common.falseReturn(None, 'Account Verify Wrong') else: return Common.falseReturn(None, 'Token Verify Wrong') else: return Common.falseReturn( None, 'Please Make Sure Authorization in Header')
def getUserBase(userid): user = blogDB.getUserById(userid) if user is not None: return Common.trueReturn(dict(zip(("id", "name", "password"), user)),'query ok') return Common.falseReturn(None,'cannot find userid:{}'.format(userid))