dashboards.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. dashboards = Blueprint('dashboards', __name__)
  7. # Main Pages
  8. @dashboards.route('/', methods=['GET', 'POST'])
  9. def market():
  10. return render_template('market.html', user=current_user)
  11. @dashboards.route('/profile', methods=['GET', 'POST'])
  12. @login_required
  13. def profile():
  14. # fetch post request
  15. if request.method == "POST":
  16. cpasswd = request.form.get('current_password')
  17. passwd = request.form.get('password')
  18. passwd_con = request.form.get('password_confirm')
  19. # password check before update
  20. if passwd and passwd_con and cpasswd:
  21. if passwd == passwd_con and check_password_hash(current_user.password, cpasswd):
  22. npasswd_dbcall = User.query.filter_by(id=current_user.id).first()
  23. npasswd_dbcall.password = generate_password_hash(passwd_con, method='sha256')
  24. db.session.commit()
  25. flash('Updated password!', category='success')
  26. else:
  27. flash('Password update failed!', category='error')
  28. return render_template('profile.html', user=current_user)
  29. @dashboards.route('/create_art', methods=['GET', 'POST'])
  30. #login_required
  31. def create():
  32. return render_template('create_art.html', user=current_user)
  33. # Pop Ups
  34. @dashboards.route('/modal_home')
  35. def modal_home():
  36. return render_template('detail_art_for_home.html', user=current_user)
  37. @dashboards.route('/modal_profile')
  38. def modal_profile():
  39. return render_template('detail_art_for_profile.html', user=current_user)