Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, redirect, render_template, request, flash, url_for, session
- import MySQLdb
- from models import get_connecttion
- app = Flask(__name__)
- @app.route('/')
- def homepage():
- return render_template('mainlogin.html')
- @app.route('/signup')
- def sign_up():
- return render_template('signup.html')
- @app.route("/adduseraction", methods=["post"])
- def add_user_action():
- # global first_name, last_name, email
- if request.form:
- user_name = request.form['usernamesignup']
- password = request.form['passwordsignup']
- email = request.form['emailsignup']
- query = "insert into user values (0,'%s','%s','%s')"
- query = query % (user_name, password, email)
- try:
- dcn, cur = get_connecttion()
- cur.execute(query)
- dcn.commit()
- return render_template('Sucess.html', user=user_name )
- except (MySQLdb.Error, MySQLdb.Warning) as e:
- e = "{} is already a user. Please use another username.".format(user_name)
- return render_template('signup.html', err = e)
- @app.route('/login', methods=['GET', 'POST'])
- def login():
- e = None
- if request.method == 'POST':
- username_form = request.form['username']
- password_form = request.form['password']
- try:
- dcn, cur = get_connecttion()
- cur.execute("SELECT COUNT(1) FROM user WHERE user_name = %s;", [username_form]) # CHECKS IF USERNAME EXSIST
- if cur.fetchone()[0]:
- cur.execute("SELECT password FROM user WHERE user_name = %s;", [username_form]) # FETCH THE HASHED PASSWORD
- for row in cur.fetchall():
- if password_form == row[0]:
- return render_template('successfull.html', datas=username_form)
- else:
- e = "Invalid Credential"
- return render_template('successfull.html', error=e)
- else:
- e = "Invalid Credential"
- return render_template('successfull.html', error=e)
- except (MySQLdb.Error, MySQLdb.Warning) as e:
- return render_template('successfull.html', error=e)
- @app.route('/logout')
- def logout():
- return render_template('logout.html')
- @app.route('/forgot')
- def forgot():
- return render_template('password.html')
- @app.route('/password', methods=['GET', 'POST'])
- def passwd():
- if request.method == 'POST':
- username_form = request.form['username']
- email_form = request.form['emailsignup']
- try:
- dcn, cur = get_connecttion()
- cur.execute("SELECT COUNT(1) FROM user WHERE user_name = %s;", [username_form]) # CHECKS IF USERNAME EXSIST
- if cur.fetchone()[0]:
- cur.execute("SELECT email FROM user WHERE user_name = %s;", [username_form]) # FETCH THE HASHED email
- for row in cur.fetchall():
- if email_form == row[0]:
- cur.execute("SELECT password FROM user WHERE user_name = %s;", [username_form])
- for row1 in cur.fetchall():
- return render_template('password.html', user='Your Password is : '+row1[0])
- else:
- e = "Email not match. Please try again."
- return render_template('password.html', error=e)
- else:
- e = "Invalid Credential"
- return render_template('password.html', error=e)
- except (MySQLdb.Error, MySQLdb.Warning) as e:
- return render_template('password.html', error=e)
- @app.errorhandler(404)
- def page_not_found(e):
- return render_template('404.html')
- if __name__ == '__main__':
- app.run(port=5050)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement