From 98daa2f4943ce1fc1b0c62f597970c8edd89b906 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Sat, 18 Mar 2023 18:16:53 -0600 Subject: [PATCH] no more auth, working html page with request --- app/__init__.py | 2 + app/routes.py | 88 +++++++++++++++--------------- index.html | 139 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + test_app.sh | 6 +- 5 files changed, 189 insertions(+), 47 deletions(-) create mode 100644 index.html diff --git a/app/__init__.py b/app/__init__.py index 63db5cc..46b68d9 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,7 +1,9 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy +from flask_cors import CORS app = Flask(__name__) +CORS(app, supports_credentials=True) app.config.from_pyfile('config.py') db = SQLAlchemy(app) diff --git a/app/routes.py b/app/routes.py index 141892a..4985ef7 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,18 +1,18 @@ from flask import request, jsonify, redirect, url_for, render_template -from flask_login import LoginManager, login_user, logout_user, login_required, current_user +# from flask_login import LoginManager, login_user, logout_user, login_required, current_user from app import app, db from app.models import User -login_manager = LoginManager() -login_manager.init_app(app) -login_manager.login_view = 'login' +# login_manager = LoginManager() +# login_manager.init_app(app) +# login_manager.login_view = 'login' -@login_manager.user_loader -def load_user(user_id): - return User.query.get(int(user_id)) +# @login_manager.user_loader +# def load_user(user_id): +# return User.query.get(int(user_id)) @app.route('/api', methods=['POST']) -@login_required +# @login_required def process_request(): image = request.files.get('image') text = request.form.get('text') @@ -25,47 +25,47 @@ def process_request(): app.logger.info(text) return jsonify(success=True) -@app.route('/signup', methods=['GET', 'POST']) -def signup(): - if current_user.is_authenticated: - return redirect(url_for('process_request')) +# @app.route('/signup', methods=['GET', 'POST']) +# def signup(): +# if current_user.is_authenticated: +# return redirect(url_for('process_request')) - if request.method == 'POST': - username = request.form['username'] - password = request.form['password'] - user = User.query.filter_by(username=username).first() +# if request.method == 'POST': +# username = request.form['username'] +# password = request.form['password'] +# user = User.query.filter_by(username=username).first() - if user is None: - new_user = User(username=username) - new_user.set_password(password) - db.session.add(new_user) - db.session.commit() - return redirect(url_for('login')) - else: - return "User already exists" +# if user is None: +# new_user = User(username=username) +# new_user.set_password(password) +# db.session.add(new_user) +# db.session.commit() +# return redirect(url_for('login')) +# else: +# return "User already exists" - return render_template('signup.html') +# return render_template('signup.html') -@app.route('/login', methods=['GET', 'POST']) -def login(): - if current_user.is_authenticated: - return redirect(url_for('process_request')) +# @app.route('/login', methods=['GET', 'POST']) +# def login(): +# if current_user.is_authenticated: +# return redirect(url_for('process_request')) - if request.method == 'POST': - username = request.form['username'] - password = request.form['password'] - user = User.query.filter_by(username=username).first() +# if request.method == 'POST': +# username = request.form['username'] +# password = request.form['password'] +# user = User.query.filter_by(username=username).first() - if user and user.check_password(password): - login_user(user) - return redirect(url_for('process_request')) - else: - return "Invalid username or password" +# if user and user.check_password(password): +# login_user(user) +# return redirect(url_for('process_request')) +# else: +# return "Invalid username or password" - return render_template('login.html') +# return render_template('login.html') -@app.route('/logout') -@login_required -def logout(): - logout_user() - return redirect(url_for('login')) +# @app.route('/logout') +# @login_required +# def logout(): +# logout_user() +# return redirect(url_for('login')) diff --git a/index.html b/index.html new file mode 100644 index 0000000..325369a --- /dev/null +++ b/index.html @@ -0,0 +1,139 @@ + + + + + + Flask App + + + + + + + +
+

API Request

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + + + diff --git a/requirements.txt b/requirements.txt index 0d449f5..0ac9563 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ flask_sqlalchemy psycopg2-binary flask_bcrypt flask_login +flask_cors \ No newline at end of file diff --git a/test_app.sh b/test_app.sh index 8b1ff6f..3032615 100755 --- a/test_app.sh +++ b/test_app.sh @@ -10,12 +10,12 @@ PASSWORD="$2" IMAGE_PATH="$3" # Signup and login the user to get the session cookie -./signup_user.sh "${USERNAME}" "${PASSWORD}" -./login_user.sh "${USERNAME}" "${PASSWORD}" +# ./signup_user.sh "${USERNAME}" "${PASSWORD}" +# ./login_user.sh "${USERNAME}" "${PASSWORD}" + # -b cookies.txt \ curl -X POST \ -H "Content-Type: multipart/form-data" \ - -b cookies.txt \ -F "image=@${IMAGE_PATH}" \ -F "text=Sample Text" \ -F "blocks=Block 1" \