|
|
@@ -1,5 +1,6 @@
|
|
|
# Site Back-End Logic
|
|
|
from hmac import new
|
|
|
+from unicodedata import category
|
|
|
from flask import Blueprint, render_template, request, flash, redirect, url_for
|
|
|
from flask_login import login_user, login_required, logout_user, current_user
|
|
|
from werkzeug.security import generate_password_hash, check_password_hash
|
|
|
@@ -9,9 +10,37 @@ import string, secrets
|
|
|
|
|
|
logic = Blueprint('logic', __name__)
|
|
|
|
|
|
-@logic.route('/', methods=['GET'])
|
|
|
+@logic.route('/', methods=['GET', 'POST'])
|
|
|
@login_required
|
|
|
-def profile():
|
|
|
+def home():
|
|
|
+ if request.method == "POST":
|
|
|
+ passwd = request.form.get('password')
|
|
|
+ passwdc = request.form.get('password_confirm')
|
|
|
+ new_pic = request.files.get('profile_image')
|
|
|
+
|
|
|
+ if passwd and passwdc:
|
|
|
+ if passwd == passwdc:
|
|
|
+ npasswd_dbcall = User.query.filter_by(id=current_user.id).first()
|
|
|
+ npasswd_dbcall.password = generate_password_hash(passwdc, method='sha256')
|
|
|
+ db.session.commit()
|
|
|
+ flash('Password successfully updated', category='success')
|
|
|
+ else:
|
|
|
+ flash('Passwords must match!', category='error')
|
|
|
+ elif new_pic:
|
|
|
+ # generate random filename for uploaded file
|
|
|
+ alphanumeric = string.ascii_letters + string.digits
|
|
|
+ ralphanum = ''.join(secrets.choice(alphanumeric) for i in range(16))
|
|
|
+ new_pic_dbcall = User.query.filter_by(id=current_user.id).first()
|
|
|
+ if '.png' in new_pic.filename:
|
|
|
+ new_pic.save(f'app/static/uploads/{ralphanum}.png')
|
|
|
+ new_pic_dbcall.profile_image = f'{ralphanum}.png'
|
|
|
+ elif '.jpg' in new_pic.filename or 'jpeg' in new_pic.filename:
|
|
|
+ new_pic.save(f'app/static/uploads/{ralphanum}.jpeg')
|
|
|
+ new_pic_dbcall.profile_image = f'{ralphanum}.jpeg'
|
|
|
+ db.session.commit()
|
|
|
+ flash('Profile Pic updated!', category='success')
|
|
|
+
|
|
|
+
|
|
|
return render_template('home.html', user=current_user)
|
|
|
|
|
|
@logic.route('/login', methods=['GET', 'POST'])
|
|
|
@@ -25,7 +54,7 @@ def login():
|
|
|
if check_password_hash(user.password, challenge_passwd):
|
|
|
flash('Successful Login!', category='success')
|
|
|
login_user(user, remember=True)
|
|
|
- return redirect(url_for('logic.profile'))
|
|
|
+ return redirect(url_for('logic.home'))
|
|
|
else:
|
|
|
flash('Unsucessful Login!', category='error')
|
|
|
else:
|
|
|
@@ -73,7 +102,7 @@ def register():
|
|
|
db.session.add(new_user)
|
|
|
db.session.commit()
|
|
|
flash('Account Registration Successful!', category='success')
|
|
|
- return redirect(url_for('logic.profile'))
|
|
|
+ return redirect(url_for('logic.home'))
|
|
|
else:
|
|
|
flash('Registration Failed', category='error')
|
|
|
return render_template("register.html", user=current_user)
|