def get(self, name): """Returns the account information.""" l_account = get_account(name) log.debug(len(l_account)) if not len(l_account): log.debug(l_account) return {'error': 'name {} not found.'.format(name)}, 404 return l_account[0]
def patch(self, name): """Updates the account password.""" data = request.json (b_ret, s_msg) = password_account(data) if not b_ret: d_msg = {'error': s_msg} return d_msg, 400 l_account = get_account(name) return l_account[0], 200
def add_claims_to_access_token(identity): # get role of identity s_role = 'user' if identity == ADMIN_ID: s_role = 'admin' else: l_account = get_account(identity) if len(l_account) and 'role' in l_account[0]: s_role = l_account[0]['role'] return {'id': identity, 'role': s_role}
def patch(self, name): """Updates the account information.""" data = request.json log.debug(data) (b_ret, s_msg) = update_account(name, data) if not b_ret: d_msg = {'error': s_msg} return d_msg, 404 l_account = get_account(name) return l_account[0], 200
def post(self): """Creates a new user account.""" data = request.json log.debug(data) (b_ret, s_msg) = create_account(data) log.debug((b_ret, s_msg)) if not b_ret: d_msg = {'error': s_msg} return d_msg, 409 # get a created account. l_account = get_account(data['name']) return l_account[0], 201
def patch(self, name): """Updates the account password as user role.""" d_claim = get_jwt_claims() # check authz: only user itself. if name != d_claim['id']: abort(401, 'Not authorized.') data = request.json (b_ret, s_msg) = user_password_account(data) if not b_ret: d_msg = {'error': s_msg} return d_msg, 400 l_account = get_account(name) return l_account[0], 200
def get(self): """Returns list of account.""" l_account = get_account() return l_account