def test_getting_logged_in_user(self): """Test for retriving logged in user""" with self.client: # user registration user_response = register_user(self) # log in user login_response = login_user(self) data = json.loads(login_response.data.decode()) self.assertTrue(data['Authorization']) # response request header # user logged in retrive print('---------------><----------------') print(request.headers.get('Authorization')) data, status = Auth.get_logged_in_user() print('data {}',data) print(status) user_details = Auth.get_logged_in_user(data) # user_data = json.loads(user_details) if user_details: print('////// ---- //////') print(type(user_details)) print(user_details) print('////// ---- //////') else: print('////// ---- //////') print('something wrong') print('////// ---- //////')
def edit_a_card_list(_id, data): card_list = get_a_card_list_by_id(_id) logged_user_id = Auth.get_logged_in_user_id(request) user = user_has_card_list(_id, logged_user_id) if not user: return {'status': 'fail', 'message': 'UNAUTHORIZED'}, 401 print('user') print(user) if not card_list: response_object = { 'status': 'fail', 'message': 'Card not exists.', } return response_object, 400 else: card_list_by_title = get_a_card_list_by_title(data['title']) if card_list_by_title: response_object = { 'status': 'fail', 'message': 'Card already exists.', } return response_object, 400 else: card_list.title = data['title'] _save_changes(card_list) return card_list.json(), 200
def decorated(*args, **kwargs): data, status = Auth.get_logged_in_user(request) if status != 200: return data, status return f(*args, **kwargs)
def wrapper_login_required(*args, **kwargs): data, status = Auth.get_logged_in_user(request) token = data.get('data') if not token: return data, status return func(*args, **kwargs)
def post(self): """Creates a new User """ data = request.json is_admin = True if request.headers.get( 'admin_secret_key') == 'maibhiadmin' else False return Auth.signup_user(data=data, is_admin=is_admin)
def post(self): # get the post data post_data = request.json try: feedback = Auth.login_user(data=post_data) except Exception as e: return 'an error occurred', 500 if not isinstance(feedback, dict): user_data = get_a_user_by_email(post_data.get('email', None)) response_data = { 'email': user_data.email, } response_object = { 'status': 'success', 'message': 'Successfully logged in.', 'body': response_data, 'Authorization': feedback.decode() } return response_object, 200 else: response_object = { 'status': 'fail', 'message': feedback.get('error', None), } return response_object, 401
def delete_card_list(card_list): logged_user_id = Auth.get_logged_in_user_id(request) user = user_has_card_list(card_list.id, logged_user_id) if not user: return {'status': 'fail', 'message': 'UNAUTHORIZED'}, 401 db.session.delete(card_list) db.session.commit() return {'status': 'success', 'message': 'Card list successfully deleted. '}, 200
def decorated(*args, **kwargs): data, status = Auth.get_logged_in_user(request) token = data.get('data') if not token: return data, status return f(*args, **kwargs)
def decorated(*args, **kwargs): feedback = Auth.get_logged_in_user(request) if not isinstance(feedback, User): return { 'status': 'fail', 'message': feedback.get('error', None) }, 401 return f(*args, **kwargs)
def decorated(*args, **kwargs): data, status = Auth.get_logged_in_user(request) token = data.get('data') if not token: return data, status if not token.get('admin'): resp = {'status': 'fail', 'message': 'Admin token required'} return resp, 401 return f(*args, **kwargs)
def save_new_card(data): logged_user_id = Auth.get_logged_in_user_id(request) card_list = get_a_card_list_by_id(data['card_list_id']) if not card_list: return {'status': 'fail', 'message': 'card list does not exists'}, 400 new_card = CardModel(title=data['title'], description=data['description'], user_id=logged_user_id, card_list_id=data['card_list_id']) try: _save_changes(new_card) return new_card.json(), 201 except: error_object = {'status': 'fail', 'message': 'Interval server error'} return error_object, 500
def decorated(*args, **kwargs): data, status = Auth.get_logged_in_user(request) token = data.get('data') print(token) if not token: return data, status admin = token.get('role') print(admin) if admin.lower() != 'admin': response_object = { 'status': 'fail', 'message': 'admin token required' } return response_object, 401 return func(*args, **kwargs)
def decorated(*args, **kwargs): feedback = Auth.get_logged_in_user(request) if feedback.get('error', None): return { 'status': 'fail', 'message': feedback.get('error', None) }, 401 verified = feedback.get('if_verified') if not verified: response_object = { 'status': 'fail', 'message': 'user not verified' } return response_object, 401 return f(*args, **kwargs)
def save_new_comment(data): logged_user_id = Auth.get_logged_in_user_id(request) card = get_a_card(data['card_id']) if not card: return {'status': 'fail', 'message': 'card does not exists'}, 400 new_comment = CommentModel( text=data['text'], parent_comment_id=data['parent_comment_id'], user_id=logged_user_id, card_id=data['card_id'], created_date=datetime.datetime.utcnow() ) try: _save_changes(new_comment) return new_comment.json(), 201 except: error_object = { 'status': 'fail', 'message': 'Interval server error' } return error_object, 500
def post(self): """Ingresar al sistema""" data = request.json return Auth.login_usuario(data)
def post(self): """Verificar token valido""" auth_header = request.headers.get('Authorization') return Auth.obtener_usuario_logeado(data=auth_header)
def get(self): # get auth token auth_header = request.headers.get('Authorization') return Auth.logout_user(auth_token=auth_header)
def post(self): # get the post data post_data = request.json return Auth.login_user(data=post_data)
def post(self): # get auth token auth_header = request.headers.get('Authorization') return Auth.logout(data=auth_header)
def get(self): return Auth.get_tokens()
def post(self): return Auth.refresh()
def check_ownership(user_id): logged_user_id = Auth.get_logged_in_user_id(request) if user_id == logged_user_id: return True return False
def get(self): """Salir del sistema""" auth_header = request.headers.get('Authorization') return Auth.logout_usuario(data=auth_header)