def login(): try: form = request.get_json() user = User.query.filter_by(email=form['email']).first() if user is not None and user.password == form['password']: token = set_access_token(user.user_id) return jsonify({'user_id': user.user_id, 'token': token}) else: return failure_page("Email/Password not matched", 401) except Exception as e: return failure_page("Failed to log in: {0}".format(str(e)), 500)
def logout(): returned_page = check_access_token() if returned_page is not None: return returned_page try: form = request.get_json() del session[str(form['user_id'])] return success_page("Successfully logged out") except Exception as e: return failure_page("Failed to log out: {0}".format(str(e)), 500)
def get_user_submissions(user_id): returned_page = check_access_token() if returned_page is not None: return returned_page try: result = Submission.query.filter_by(user_id=user_id).all() result = get_submission_history(result) return result except Exception as e: return failure_page( "Failed to get submission history: {0}".format(str(e)), 500)
def user_register(): #return failure_page('Registration is disabled.', 403) try: form = request.get_json() new_user = User(nickname=form['nickname'], email=form['email'], password=form['password']) db.session.add(new_user) db.session.commit() return success_page('Successfully registered') except Exception as e: return failure_page("Failed to register: {0}".format(str(e)), 500)
def get_update_submission_detail(submission_id): returned_page = check_access_token() if returned_page is not None: return returned_page if request.method == 'GET': try: submission = Submission.query.get(submission_id) return get_submission_details_json(submission) except Exception as e: return failure_page( "Failed to get submission detail: {0}".format(str(e)), 500) else: try: form = request.get_json() submission = Submission.query.get(form['submission_id']) submission.feedback = form['feedback'] db.session.commit() return success_page("Successfully updated submission detail") except Exception as e: return failure_page( "Failed to update submission detail: {0}".format(str(e)), 500)
def get_user_info(user_id): returned_page = check_access_token() if returned_page is not None: return returned_page try: user = User.query.get(user_id) return jsonify({ 'user_id': user.user_id, 'email': user.email, 'nickname': user.nickname }) except Exception as e: return failure_page( "Failed to get user information: {0}".format(str(e)), 500)
def make_submission(): returned_page = check_access_token() if returned_page is not None: return returned_page try: form = request.get_json() submission = Submission(user_id=form['user_id'], model_name=form['model_name'], status="Submitted", s3_model_key=form['s3_model_key'], s3_index_key=form['s3_index_key']) db.session.add(submission) db.session.commit() send_job_to_sqs(submission.submission_id, form['s3_model_key'], form['s3_index_key']) return jsonify({'submission_id': submission.submission_id}) except Exception as e: return failure_page("Failed to submit: {0}".format(str(e)), 500)