Просмотр исходного кода

Profile password update backend done

control 3 лет назад
Родитель
Сommit
69465dfaa7
3 измененных файлов с 37 добавлено и 5 удалено
  1. 25 1
      app/dashboards.py
  2. BIN
      app/database.db
  3. 12 4
      app/templates/profile.html

+ 25 - 1
app/dashboards.py

@@ -1,10 +1,12 @@
 from flask import Blueprint, render_template, request, flash, redirect, url_for
 from flask_login import login_required, current_user
+from werkzeug.security import generate_password_hash, check_password_hash
 from .models import User
 from . import db
 
 dashboards = Blueprint('dashboards', __name__)
 
+# Main Pages
 @dashboards.route('/', methods=['GET', 'POST'])
 def market():
     return render_template('market.html', user=current_user)
@@ -12,8 +14,30 @@ def market():
 @dashboards.route('/profile', methods=['GET', 'POST'])
 @login_required
 def profile():
-	return render_template('profile.html', user=current_user)
+    # fetch post request
+    if request.method == "POST":
+        cpasswd = request.form.get('current_password')
+        passwd = request.form.get('password')
+        passwd_con = request.form.get('password_confirm')
+
+        # password check before update
+        if passwd and passwd_con and cpasswd:
+            if passwd == passwd_con and check_password_hash(current_user.password, cpasswd):
+                npasswd_dbcall = User.query.filter_by(id=current_user.id).first()
+                npasswd_dbcall.password = generate_password_hash(passwd_con, method='sha256')
+                db.session.commit()
+                flash('Updated password!', category='success')
+            else:
+                flash('Password update failed!', category='error')
+
+    return render_template('profile.html', user=current_user)
+
+@dashboards.route('/create_art', methods=['GET', 'POST'])
+#login_required
+def create():
+    return render_template('create_art.html', user=current_user)
 	
+# Pop Ups
 @dashboards.route('/modal_home')
 def modal_home():
     return render_template('detail_art_for_home.html', user=current_user)

BIN
app/database.db


+ 12 - 4
app/templates/profile.html

@@ -12,12 +12,20 @@ table, th, td {
     <div class="card-body">
         <p><b>Change Password</b></p><br>
     <hr style="border: 1px solid rgb(177, 176, 176);"/>
+        <div class="row">
+            <div class="col-sm-3" style='position:relative; left:20px'>
+            <h6 class="mb-0"><label for="current_password">Current Password</label></h6><br>
+            </div>
+            <div class="col-sm-9 text-secondary">
+                <input type="password" id="current_password" name="current_password"><br>
+            </div>
+        </div>
         <div class="row">
             <div class="col-sm-3" style='position:relative; left:20px'>
             <h6 class="mb-0"><label for="password">Password</label></h6><br>
             </div>
             <div class="col-sm-9 text-secondary">
-                <input type="text" id="password" name="password"><br>
+                <input type="password" id="password" name="password"><br>
             </div>
         </div>
         <div class="row">
@@ -25,7 +33,7 @@ table, th, td {
             <h6 class="mb-0"><label for="password_confirm">Password<br>(Confirm)</label></h6><br>
             </div>
             <div class="col-sm-9 text-secondary">
-                <input type="text" id="password_confirm" name="password_confirm">
+                <input type="password" id="password_confirm" name="password_confirm">
             </div>
         </div>
         <div class="row">
@@ -43,8 +51,8 @@ table, th, td {
 
 <hr>
 <h1>Show user information</h1>
-<p>email</p>
-<p>Nickname</p>
+<p>{{user.email}}</p>
+<p>{{user.username}}</p>
 <hr>
 <p>Art I Own</p>
 <p>1. Art Name</p>