def wrapper(*args, **kwargs): if 'Token' not in request.headers: return unauthorized_envelop() try: decoded = decode_access_token(request.headers.get('token')) if decoded is None: return unauthorized_envelop() except Exception as e: return unauthorized_envelop() else: #role_id = decoded['role_id'] user_name = decoded['user_name'] try: user = db_session.query(User).filter( User.user_name == user_name).one() role = user.role role = role.to_dict()[key] except NoResultFound as e: return record_notfound_envelop() except Exception as e: return fatal_error_envelop() else: if role == 'W' or role == 'E': return func(*args, **kwargs) else: return unauthorized_envelop()
def wrapper(*args, **kwargs): if 'Token' not in request.headers: return unauthorized_envelop() try: decoded = decode_access_token(request.headers['Token']) print(decoded) if decoded is None: return unauthorized_envelop() except Exception as e: raise e return unauthorized_envelop() else: role_id = decoded['role_id'] user_name = decoded['user_name'] if role_id not in current_app.config: roles = db_session.query(Role).all() roles = [role.to_dict() for role in roles] for role in roles: current_app.config[role['id']] = role role = current_app.config[role_id][key] print('role is ', role) if role != 'N': return func(*args, **kwargs) else: print('as') return unauthorized_envelop()
def wrapper(*args, **kwargs): if 'Token' not in request.headers: return unauthorized_envelop() try: decoded = decode_access_token(request.headers['Token']) print(decoded) if decoded is None: return unauthorized_envelop() except Exception as e: raise e return unauthorized_envelop() else: user_name = decoded['user_name'] try: user = db_session.query(User).filter( User.user_name == user_name).one() role = user.role role = role.to_dict()[key] except NoResultFound as e: return record_notfound_envelop() except Exception as e: return fatal_error_envelop() if role != 'N': return func(*args, **kwargs) else: print('as') return unauthorized_envelop()
def wrapper(*args, **kwargs): #check if there is access_token in the headers if not 'Token' in request.headers.keys(): return jsonify({'message': 'not_authorized', 'code': '401'}) #try decoding the token decoded = decode_access_token(request.headers['token']) if not decoded: return jsonify({'message': 'not authorized', 'code': '401'}) if decoded['role_id'] == 1: return func(*args, **kwargs) else: return jsonify({'message': 'not authorized', 'code': '401'})
def admin_wrapper(*args, **kwargs): print(request.headers) if 'Token' not in request.headers.keys(): return unauthorized_envelop() try: print(request.headers) decoded = decode_access_token(request.headers['Token']) if decoded is None: return unauthorized_envelop() except Exception: return unauthorized_envelop() else: role_id = decoded['role_id'] #for admin role,'permission one' must be true if not ROLES_PERMISSION[role_id]['permission_one'] == True: return unauthorized_envelop() return func(*args, **kwargs)
def _wrapper(*args, **kwargs): if 'Token' not in request.headers.keys(): return unauthorized_envelop() try: decoded = decode_access_token(request.headers['Token']) if decoded is None: return unauthrorized_envelop() except Exception as e: return unauthorized_envelop() else: role_id = decoded['role_id'] user_name = decoded['user_name'] if ROLES_PERMISSION[role_id]['permission_one'] == True: return func(*args, **kwargs) print('herer is the line that need to be called') #now check the employee_branch_id and know if he belongs to agency or branch emp_branch_id = request.json.get('employee_branch_id') print(emp_branch_id) try: branch = db_session.query(Branch).filter( Branch.id == emp_branch_id).one() except NoResultFound as e: return record_notfound_envelop() except Exception as e: return fatal_error_envelop() else: is_branch = branch.is_branch print(is_branch) if is_branch: return handle_branch(branch, emp_branch_id, role_id, user_name, func, *args, **kwargs) elif is_branch == False: #this means it is agency return handle_agency(branch, emp_branch_id, role_id, user_name, func, *args, **kwargs)