dashboards.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from flask import Blueprint, render_template, request, flash, redirect, url_for
  2. from flask_login import login_required, current_user
  3. from werkzeug.security import generate_password_hash, check_password_hash
  4. from .models import User
  5. from . import db
  6. from . import clean_file as cf
  7. dashboards = Blueprint('dashboards', __name__)
  8. # Main Pages
  9. @dashboards.route('/', methods=['GET', 'POST'])
  10. def market():
  11. return render_template('market.html', user=current_user)
  12. @dashboards.route('/profile', methods=['GET', 'POST'])
  13. @login_required
  14. def profile():
  15. # fetch post request
  16. if request.method == "POST":
  17. cpasswd = request.form.get('current_password')
  18. passwd = request.form.get('password')
  19. passwd_con = request.form.get('password_confirm')
  20. # password check before update
  21. if passwd and passwd_con and cpasswd:
  22. if passwd == passwd_con and check_password_hash(current_user.password, cpasswd):
  23. npasswd_dbcall = User.query.filter_by(id=current_user.id).first()
  24. npasswd_dbcall.password = generate_password_hash(passwd_con, method='sha256')
  25. db.session.commit()
  26. flash('Updated password!', category='success')
  27. else:
  28. flash('Password update failed!', category='error')
  29. return render_template('profile.html', user=current_user)
  30. @dashboards.route('/create_art', methods=['GET', 'POST'])
  31. #login_required
  32. def create():
  33. # check POST req
  34. if request.method == "POST":
  35. new_art = request.files.get('art_img')
  36. if new_art and new_art.filename != '' and cf.allowed_file(new_art.filename):
  37. new_art.save(f'{cf.UPLOAD_FOLDER}/{cf.sanitize(new_art.filename)}')
  38. return render_template('create_art.html', user=current_user)
  39. # Pop Ups
  40. @dashboards.route('/modal_home')
  41. def modal_home():
  42. return render_template('detail_art_for_home.html', user=current_user)
  43. @dashboards.route('/modal_profile')
  44. def modal_profile():
  45. return render_template('detail_art_for_profile.html', user=current_user)