def decorated_function(*args, **kwargs): errorMessage = "Login Required" if LoginSession.isLogin(session): userDb = UserHandler() try: user = userDb.getUserByUID(session["name"]) validUser = True for permission in permissionList: if (not userDb.hasPermission(user, permission)): validUser = False finally: InterfaceHolder.closeOne(userDb) if (validUser): return f(*args, **kwargs) errorMessage = "Wrong User Type" elif "check_email_token" in permissionList: if (LoginSession.isRegistering(session)): return f(*args, **kwargs) else: errorMessage = "unauthorized" elif "check_password_token" in permissionList: if (LoginSession.isResetingPassword(session)): return f(*args, **kwargs) else: errorMessage = "unauthorized" returnResponse = flask.Response() returnResponse.headers["Content-Type"] = "application/json" returnResponse.status_code = 401 # Error code responseDict = {} responseDict["message"] = errorMessage returnResponse.set_data(json.dumps(responseDict)) return returnResponse
def decorated_function(*args, **kwargs): errorMessage = "Login Required" if LoginSession.isLogin(session): userDb = UserHandler() try: user = userDb.getUserByUID(session["name"]) validUser = True for permission in permissionList: if not userDb.hasPermission(user, permission): validUser = False finally: InterfaceHolder.closeOne(userDb) if validUser: return f(*args, **kwargs) errorMessage = "Wrong User Type" elif "check_email_token" in permissionList: if LoginSession.isRegistering(session): return f(*args, **kwargs) else: errorMessage = "unauthorized" elif "check_password_token" in permissionList: if LoginSession.isResetingPassword(session): return f(*args, **kwargs) else: errorMessage = "unauthorized" returnResponse = flask.Response() returnResponse.headers["Content-Type"] = "application/json" returnResponse.status_code = 401 # Error code responseDict = {} responseDict["message"] = errorMessage returnResponse.set_data(json.dumps(responseDict)) return returnResponse
def decorated_function(*args, **kwargs): try: sess = GlobalDB.db().session error_message = "Login Required" if permission == "check_email_token": if LoginSession.isRegistering(session): return f(*args, **kwargs) else: error_message = "unauthorized" elif permission == "check_password_token": if LoginSession.isResetingPassword(session): return f(*args, **kwargs) else: error_message = "unauthorized" elif LoginSession.isLogin(session): user = sess.query(User).filter( User.user_id == session["name"]).one() valid_user = True if permission is not None: perm_hierarchy = { d['name']: d['order'] for d in PERMISSION_MAP.values() } # if the users permission is not higher than the one specified, check their permission # if user's perm order is < than what's passed in, it means they have higher permissions if perm_hierarchy[PERMISSION_TYPE_DICT_ID[ user.permission_type_id]] > perm_hierarchy[ permission]: if not user.permission_type_id == PERMISSION_TYPE_DICT[ permission]: valid_user = False if valid_user: return f(*args, **kwargs) error_message = "You are not authorized to perform the requested task. Please contact your administrator." # No user logged in return_response = flask.Response() return_response.headers["Content-Type"] = "application/json" return_response.status_code = 401 # Error code response_dict = {} response_dict["message"] = error_message return_response.set_data(json.dumps(response_dict)) return return_response except ResponseException as e: return JsonResponse.error(e, e.status) except InvalidUsage: raise except Exception as e: exc = ResponseException(str(e), StatusCode.INTERNAL_ERROR, type(e)) return JsonResponse.error(exc, exc.status)
def decorated_function(*args, **kwargs): try: errorMessage = "Login Required" if "check_email_token" in permissionList: if(LoginSession.isRegistering(session)) : return f(*args, **kwargs) else : errorMessage = "unauthorized" elif "check_password_token" in permissionList : if(LoginSession.isResetingPassword(session)) : return f(*args, **kwargs) else : errorMessage = "unauthorized" elif LoginSession.isLogin(session): userDb = UserHandler() try: user = userDb.getUserByUID(session["name"]) validUser = True for permission in permissionList : if(not userDb.hasPermission(user, permission)) : validUser = False else: validUser = True break finally: userDb.close() if(validUser) : return f(*args, **kwargs) errorMessage = "Wrong User Type" returnResponse = flask.Response() returnResponse.headers["Content-Type"] = "application/json" returnResponse.status_code = 401 # Error code responseDict = {} responseDict["message"] = errorMessage returnResponse.set_data(json.dumps(responseDict)) return returnResponse except ResponseException as e: return JsonResponse.error(e,e.status) except Exception as e: exc = ResponseException(str(e),StatusCode.INTERNAL_ERROR,type(e)) return JsonResponse.error(exc,exc.status)
def listAgencies(self): """ Retrieves a list of all agency names and their cgac codes. If there is a user logged in, it will check if that user is part of the 'SYS' agency. If so, 'SYS' will be added to the agency_list. """ agencies = self.validationManager.getAllAgencies() agency_list = [] for agency in agencies: agency_list.append({ "agency_name": agency.agency_name, "cgac_code": agency.cgac_code }) if LoginSession.isLogin(session): user_id = LoginSession.getName(session) user = self.userManager.getUserByUID(user_id) if user.cgac_code.lower() == "sys": agency_list.append({"agency_name": "SYS", "cgac_code": "SYS"}) return JsonResponse.create(StatusCode.OK, {"cgac_agency_list": agency_list})
def list_agencies(self): """ Retrieves a list of all agency names and their cgac codes. If there is a user logged in, it will check if that user is part of the 'SYS' agency. If so, 'SYS' will be added to the agency_list. """ sess = GlobalDB.db().session agencies = sess.query(CGAC).all() agency_list = [] for agency in agencies: agency_list.append({ "agency_name": agency.agency_name, "cgac_code": agency.cgac_code }) if LoginSession.isLogin(session): user = sess.query(User).filter( User.user_id == LoginSession.getName(session)).one() if user.cgac_code.lower() == "sys": agency_list.append({"agency_name": "SYS", "cgac_code": "SYS"}) return JsonResponse.create(StatusCode.OK, {"cgac_agency_list": agency_list})
def sessionCheck(): session["session_check"] = True return JsonResponse.create( StatusCode.OK, {"status": str(LoginSession.isLogin(session))})
def sessionCheck(): session["session_check"] = True return JsonResponse.create(StatusCode.OK,{"status":str(LoginSession.isLogin(session))})