def get_recovery_by_email(cls, user_email): """ Finds the Recovery object with the given user email :param user_email: user object to be updated :return: Recovery object """ Database.find_one(COLLECTION, {'user_email': user_email})
def exist(name, code): wbs_code = Database.find_one(table='wbs', data={'code': self.code}) wbs_name = Database.find_one(table='wbs', data={'code': self.code}) if wbs_code or wbs_name: return True else: return False
def exist(name, code): account_code = Database.find_one(table='controlaccounts', data={'code': self.code}) account_name = Database.find_one(table='controlaccounts', data={'code': self.code}) if account_code or account_name: return True else: return False
def predictions_dashboard(project_id): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None model_info = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/prediction_dashboard.html', data=data, project_specific_data=project_specific_data, model_info=model_info) except: return render_template('pages/error-404.html')
def check_blacklist(auth_token): # check whether auth token has been blacklisted res = Database.find_one(collection='blacklist_tokens', query={'token': auth_token}) if res: return True else: return False
def validate_username(self, username): if username.data != session['user'].name: user = Database.find_one(collection="users", query={'uname': username.data}) print(user) if user is not None: raise ValidationError('Please use a different username.')
def project_dashboard(project_id): """ Admin Dashboard \n ALlows ADMIN to access project/CUSTOMER user ALlows ADMIN to access project/CUSTOMER user dashboard with all the admin tools to vefiy user pipeline this allows admin to oversee if the user data is present or not Allow to see the status of user Deep Learning model.\n\n method: GET\n API/URL must be accessed with GET request and supply project_id in the URL\n Args: project_id (str): ID of the poject need to be sent in url. It is made to do so via Front end href Returns: view: a url VIEW the project's/CUSTOMER's required params such as Dataset, dataset voliation if present, Deep leanring model status, Deep learning model metrics, predication metreics. OR if the user is not logged in or CUSTOMER user does not exists then 404 redirect """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None model_info = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/project_dashboard.html', data=data, project_specific_data=project_specific_data, model_info=model_info) except: return render_template('pages/error-404.html')
def get_by_id(cls, _id: str, collection: str): """ Returns the user object with the given id, or raises an exception if that user was not found :param _id: id of the user to find :param collection: DB that contains all the users :return: user object """ user = Database.find_one(collection, {'_id': _id}) if user: return cls(**user)
def recover_in_db(cls, recovery_id, email): """ Recovers the password in the database with a unique recovery ID :param recovery_id: ID to ensure a secure recuperation of the password :return: Boolean """ recovery_in_DB = cls( **Database.find_one(COLLECTION, {'_id': recovery_id})) if recovery_in_DB is None: return False else: Database.remove(COLLECTION, {'_id': recovery_id}) return True
def get_recovery(cls, _id=None): """ Fetches a list of the all the Recovery objects in the given collection :param _id: The specific ID of a particular collection :return: List of Recovery objects or one specific Recovery object """ if _id is None: return [ cls(**recovery) for recovery in Database.find(COLLECTION, {}) ] else: return [cls(Database.find_one(COLLECTION, {'_id': _id}))]
def auth_verify_email(user_id, email_token): """ This is used to verfiy user via the link the receive on their email. \n\n API/URL must be accessed with GET request and supply user_id and email_token in the URL\n method: GET\n Args: user_id (str): ID of the poject/Customer need to be sent in url. It is made to do so via email template email_token (str): UUID generated email token need to be sent in url. It is made to do so via email template Returns: response: JSON object On Success \n response = { 'status': 'success', 'message': 'Email verified' } \n On Fail:\n response = { 'status': 'fail', 'message': 'Email already verified' } \n """ user = User.get_by_id(int(user_id)) if user.is_email_verified: responseObject = { 'status': 'fail', 'message': 'Email already verified' } return make_response(jsonify(responseObject)), 202 email_auth_data = Database.find_one(collection='email_token', query={'user_id': int(user_id)}) if email_auth_data['email_token'] == email_token: Database.update_one(collection="users", query=[{ 'user_id': int(user_id) }, { "$set": { "is_email_verified": True } }]) responseObject = {'status': 'success', 'message': 'Email verified'} return make_response(jsonify(responseObject)), 201
def predictions_dashboard(project_id): """ Predictions Dashboard \n To allow ADMIN user see all necessary metrics for the project/CUSTOMER user Allows an ADMIN user visualize the Deep Learning model's performance, along side customer's activities.\n\n method: GET\n API/URL must be accessed with GET request and supply project_id in the URL\n Args: project_id (str): ID of the poject need to be sent in url. It is made to do so via Front end href Returns: view: a url VIEW the project's/CUSTOMER's all required prediction values and visulization data give user login status. If project CUSTOMER not found then redirect 404. """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None model_info = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/prediction_dashboard.html', data=data, project_specific_data=project_specific_data, model_info=model_info) except: return render_template('pages/error-404.html')
def user_view(): """ Returns the user health info when Authorization token is present in the heeader """ # get the auth token auth_header = request.headers.get('Authorization') data = request.get_json() if data is None: data = request.form if auth_header: try: auth_token = auth_header.strip() except IndexError: responseObject = { 'status': 'fail', 'message': 'Bearer token malformed.' } return make_response(jsonify(responseObject)), 401 else: auth_token = '' if auth_token: resp = User.decode_auth_token(auth_token) if not isinstance(resp, str): user = User.get_by_id(resp) stats = Database.find_one(collection='user_stats', query={ 'user_id': resp, 'date': data.get('date') }) responseObject = { 'status': 'success', 'data': { 'user_id': user.user_id, 'email': user.email, 'fname': user.fname, 'lname': user.lname }, 'user_stats': stats } return make_response(jsonify(responseObject)), 200 responseObject = {'status': 'fail', 'message': resp} return make_response(jsonify(responseObject)), 401 else: responseObject = { 'status': 'fail', 'message': 'Provide a valid auth token.' } return make_response(jsonify(responseObject)), 401
def auth_verify_email(user_id, email_token): user = User.get_by_id(int(user_id)) if user.is_email_verified: responseObject = { 'status': 'fail', 'message': 'Email already verified' } return make_response(jsonify(responseObject)), 202 email_auth_data = Database.find_one(collection='email_token', query={'user_id': int(user_id)}) if email_auth_data['email_token'] == email_token: Database.update_one(collection="users", query=[{'user_id': int(user_id)}, {"$set": { "is_email_verified": True }} ]) responseObject = { 'status': 'success', 'message': 'Email verified' } return make_response(jsonify(responseObject)), 201
def customer_dashboard(project_id): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None model_info = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> responseObject = { "data": data, "project_specific_data": project_specific_data, "model_info": model_info } return make_response(jsonify(responseObject)), 201 except: responseObject = { 'status': 'fail', 'message': 'Some error occurred with database. Please try again.' } return make_response(jsonify(responseObject)), 201
def get_by_email(cls, email): # check the database, users collection for the pair email, password data = Database.find_one(collection='users', query={'email': email}) if data is not None: # return the object user return cls(**data)
def from_mongo(cls, id): post_data = Database.find_one(collection='projects', query={'_id':id}) return cls(**post_data)
def get_by_user(cls, date, email): data = Database.find_one("baseball", {"date": date, "email": email}) if data is not None: return cls(**data)
def get_by_date(cls, date): data = Database.find_one("baseball", {"date": date}) if data is not None: return cls(**data)
def from_mongo(cls, id): blog_data = Database.find_one(collection='blogs', query={'_id': id}) return cls(**blog_data)
def customer_dashboard(project_id): """ STRICT api for mobile team and customer web Ui team to use Retunrs all CUSTOEMR deeplearning model satas. Data set for the CUSTOMER USER if any error occurs then JSON will contain error message. \n\n API/URL must be accessed with GET request and supply project_id the URL\n method: GET\n Args: project_id (str): ID of the poject/Customer need to be sent in url. It is made to do so via Front end href Returns: response: JSON object On Success \n response = { "data":data, "project_specific_data":project_specific_data, "model_info":model_info } \n On Fail:\n response = { 'status': 'fail', 'message': 'Some error occurred with database. Please try again.' } \n """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None model_info = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> responseObject = { "data": data, "project_specific_data": project_specific_data, "model_info": model_info } return make_response(jsonify(responseObject)), 201 except: responseObject = { 'status': 'fail', 'message': 'Some error occurred with database. Please try again.' } return make_response(jsonify(responseObject)), 201
def find_by_id(cls, id): account = Database.find_one(table='wbs', data={'_id': id}) return cls(**account)
def get_by_id(cls, _id): data = Database.find_one("users", {"_id": _id}) if data is not None: return cls(**data)
def get_by_username(cls, uname): # check the database, users collection for the pair email, password data = Database.find_one(collection='users', query={'uname': uname}) if data is not None: # return the object user return cls(**data)
def get_by_id(cls, _id): data = Database.find_one(collection='users', query={'user_id': _id}) if data is not None: # return the object user return cls(**data)
def get_by_email(cls, email): data = Database.find_one("users", {"email": email}) if data is not None: return cls(**data)