diff --git a/app/__init__.py b/app/__init__.py index 56be70a16f531268cf118eb2568772df1a529329..df1d4389fb547d9f6be60ea0d10ffb81dc49dfe9 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -26,6 +26,8 @@ def create_app(config_class=Config): db_password = os.getenv("DATABASE_PASSWORD") db_name = os.getenv("DATABASE_NAME") + app.config['SECRET_KEY'] = 'tnm]H+akmfnf_#PT>i|(Qo4LT@+n£9"~e3' + app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}".format(db_user=db_user, db_password=db_password, db_host=db_host, db_name=db_name) print(app.config['SQLALCHEMY_DATABASE_URI']) db.init_app(app) @@ -43,6 +45,12 @@ def create_app(config_class=Config): from app.api import bp as api_bp app.register_blueprint(api_bp, url_prefix='/api') + from app.admin import bp as admin_bp + app.register_blueprint(admin_bp, url_prefix='/admin') + + from app.profile import bp as profile_bp + app.register_blueprint(profile_bp, url_prefix='/profile') + if __name__ == "__main__": app.run(use_reloader=True) diff --git a/app/admin/__init__.py b/app/admin/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..33554300edcca751826e87114967fce82fad8ac6 --- /dev/null +++ b/app/admin/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +bp = Blueprint('admin', __name__) + +from app.admin import routes \ No newline at end of file diff --git a/app/admin/routes.py b/app/admin/routes.py new file mode 100644 index 0000000000000000000000000000000000000000..64218ae34770691b2e53ef5db71f5ce8ef55fe2d --- /dev/null +++ b/app/admin/routes.py @@ -0,0 +1,8 @@ +from flask import render_template, redirect, url_for +from app.admin import bp +from app.models import Listings, ListingImages + + +@bp.route('/manage_listings') +def manage_listings(): + return render_template('admin/index.html', top_listings=top_listings, top_listing_images=top_listing_images) \ No newline at end of file diff --git a/app/models/user.py b/app/models/user.py index c22b429a3b21f02f46691c3fbe05ad3543fc72b0..c1881bffa5f08de2d24758166304218d7b815415 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -21,4 +21,12 @@ class User(db.Model): @classmethod def search_user_id(cls, user_id): - return cls.query.get(user_id) \ No newline at end of file + return cls.query.get(user_id) + + + @classmethod + def search_user_by_email(cls, user_email): + + user_exist = cls.query.filter_by(email=user_email).first() + + return user_exist \ No newline at end of file diff --git a/app/profile/__init__.py b/app/profile/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c57db616af33e21c93d6e847380a2fbf2159064e --- /dev/null +++ b/app/profile/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +bp = Blueprint('profile', __name__) + +from app.profile import routes \ No newline at end of file diff --git a/app/profile/routes.py b/app/profile/routes.py new file mode 100644 index 0000000000000000000000000000000000000000..2fd51c3de6b0702a84d507d0ef3589b0d59f6a2d --- /dev/null +++ b/app/profile/routes.py @@ -0,0 +1,34 @@ +from flask import render_template, redirect, url_for +from app.profile import bp +from app.models import User + +@bp.route('/') +def index(): + return render_template('profile/index.html') + +@bp.route('/login') +def login(): + return 'Login' + +@bp.route('/signup') +def signup(): + return render_template('profile/signup.html') + +@bp.route('/signup', methods=['POST']) +def signup_post(): + email = request.form.get('email') + name = request.form.get('name') + password = request.form.get('password') + if User.search_user_by_email(email): + return redirect(url_for('auth.signup')) + + new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256')) + + db.session.add(new_user) + db.session.commit() + + return redirect(url_for('auth.login')) + +@bp.route('/logout') +def logout(): + return 'Logout' \ No newline at end of file diff --git a/app/templates/profile/index.html b/app/templates/profile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..7da6f97c7e1ca3af20b17d7d455d701db1eb1b27 --- /dev/null +++ b/app/templates/profile/index.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} +# Implements CSS Slider from https://swiffyslider.com/docs/ +{% block content %} +<div> + <p>Welcome logged in!</p> +</div> +{% endblock %} \ No newline at end of file diff --git a/app/templates/profile/login.html b/app/templates/profile/login.html new file mode 100644 index 0000000000000000000000000000000000000000..0384d22cbe648d40882612757a1260308ec50aad --- /dev/null +++ b/app/templates/profile/login.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} +# Implements CSS Slider from https://swiffyslider.com/docs/ +{% block content %} +<div class="column is-4 is-offset-4"> + <h3 class="title">Login</h3> + <div class="box"> + <form method="POST" action="/login"> + <div class="field"> + <div class="control"> + <input class="input is-large" type="email" name="email" placeholder="Your Email" autofocus=""> + </div> + </div> + + <div class="field"> + <div class="control"> + <input class="input is-large" type="password" name="password" placeholder="Your Password"> + </div> + </div> + <div class="field"> + <label class="checkbox"> + <input type="checkbox" name="remember"> + Remember me + </label> + </div> + <button class="button is-block is-info is-large is-fullwidth">Login</button> + </form> + </div> +</div> +{% endblock %} \ No newline at end of file diff --git a/app/templates/profile/signup.html b/app/templates/profile/signup.html new file mode 100644 index 0000000000000000000000000000000000000000..8966ed18d057b3f3d271006143304db8a90c78ec --- /dev/null +++ b/app/templates/profile/signup.html @@ -0,0 +1,30 @@ +{% extends 'base.html' %} + +{% block content %} +<div class="column is-4 is-offset-4"> + <h3 class="title">Sign Up</h3> + <div class="box"> + <form method="POST" action="/signup"> + <div class="field"> + <div class="control"> + <input class="input is-large" type="email" name="email" placeholder="Email" autofocus=""> + </div> + </div> + + <div class="field"> + <div class="control"> + <input class="input is-large" type="text" name="name" placeholder="Name" autofocus=""> + </div> + </div> + + <div class="field"> + <div class="control"> + <input class="input is-large" type="password" name="password" placeholder="Password"> + </div> + </div> + + <button class="button is-block is-info is-large is-fullwidth">Sign Up</button> + </form> + </div> +</div> +{% endblock %} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index bb63d03fa549d6220141f2719dd7ed3a29674db4..4f3f85f1d8d7d5ec772e492d7f01d8d5e6bdf228 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ flask_migrate pymysql python-dotenv jinja2 -cryptography \ No newline at end of file +cryptography +flask-login \ No newline at end of file