Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask,render_template,request,url_for,redirect,session
- import os.path
- from functions import encrypt
- app = Flask(__name__)
- app.secret_key="hussain"
- BASE_DIR = os.path.dirname(os.path.abspath(__file__))
- db_path = os.path.join(BASE_DIR,"alaa.db")
- import sqlite3
- conn=sqlite3.connect(db_path)
- conn.row_factory = sqlite3.Row
- cursor = conn.cursor()
- #login page
- @app.route("/",methods=['GET','POST'])
- def l():
- return render_template("index.html")
- #check the user information
- @app.route("/login",methods=['GET','POST'])
- def login():
- if request.method == 'POST':
- password=encrypt(request.form['password'],'test')
- username=request.form['username']
- cursor.execute('SELECT * FROM users where name=? and password=? ',(username,password))
- data =cursor.fetchone()
- if data:
- session['username'] = username
- session['userid']=data[0]
- return render_template("test.html",data=data)
- else:
- return redirect(url_for('l',error_msg="البيانات خاطئة"))
- # update user information page
- @app.route("/update",methods=['POST','GET'])
- def update():
- cursor.execute('SELECT * from users where id=?',(session['userid'],))
- data = cursor.fetchone()
- return render_template('update.html',data=data)
- #update user code
- @app.route("/update/done",methods=['POST','GET'])
- def checkupdate():
- username=request.form['username']
- email = request.form['email']
- try:
- cursor.execute('''UPDATE users SET name=? , email= ? where id=?''',(username,email,session['userid']))
- conn.commit()
- return render_template('l.html',msg="تم التحديث بنجاح")
- except:
- return render_template('l.html',msg="لم يتم التحديث")
- #logout and clear the session
- @app.route("/logout")
- def logout():
- session.clear()
- return redirect(url_for('l'))
- if __name__ == '__main__':
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement