def delete(self, id): """Delete Account (Admin access required)""" resp = AuthHelper.get_loged_in_user(request) if resp[0]['status'] == 'success': user_id = resp[0]['user_data']['user_id'] return delete_user_by_id(id) else: return {'status': 'fail', 'message': 'only logged in user '}, 401
def patch(self): """Update user details""" resp = AuthHelper.get_loged_in_user(request) if resp[0]['status'] == 'success': user_id = resp[0]['user_data']['user_id'] data = request.json return update_existing_user(data, user_id) else: return { 'status': 'fail', 'message': 'only logined user can update details' }, 401
def decorated(*args, **kwargs): data, status_code = AuthHelper.get_loged_in_user(request) if status_code != 200: return data, status_code is_admin = data['user_data'].get('is_admin') if not is_admin: response_object = { 'status': 'fail', 'message': 'admin token required' } return response_object, 401 return func(*args, **kwargs)
def get(self): # parameters sent in the request made to the external api """Search job for current user""" resp = AuthHelper.get_loged_in_user(request) if resp[0]['status'] == 'success': user_data = resp[0]['user_data'] print(user_data) job_template = 'https://jobs.github.com/positions.json?description={job}&location={loc}&full_time={fu}' # actual request format for github jobs public api desc = user_data['keyword'] location = user_data['location'] desc = desc.replace(" ", "+") ft = user_data['full_time'] job_url = job_template.format(job=desc, loc=location, fu=ft) resp = requests.get(job_url) print(jsonify(resp.json())) if resp.ok: if len(resp.json()) == 0: return jsonify({'message': 'No jobs found'}), 200 else: return resp.json(), 200 else: print(resp.reason)
def wrapper(*args, **kwargs): data, status = AuthHelper.get_loged_in_user(request) if status == 200: if data.get('user_data'): return func(*args, **kwargs) return data, status
def post(self): """Logout User by balcklisting JWT token""" auth_token = request.headers.get('Authorization') return AuthHelper.logout_user(auth_token)
def post(self): """Login user by generating JWT token""" data = request.json return AuthHelper.login_user(data)