In [ ]:
from flask import Flask, render_template, json, request, redirect
from werkzeug import generate_password_hash, check_password_hash
import sqlite3
from flask import g 

DATABASE = 'BucketList.db'

app = Flask(__name__)


@app.route('/')
def main():
    return render_template('index.html')


@app.route('/showSignUp')
def showSignUp():
    return render_template('signup.html')

@app.route('/showSignIn')
def showSignIn():
    return render_template('signin.html')


@app.route('/signUp',methods=['POST','GET'])
def signUp():
    _name = request.form['inputName']
    _email = request.form['inputEmail']
    _password = request.form['inputPassword']

    # validate the received values
    if _name and _email and _password:
        print _name, _email
        
        db = g._database = sqlite3.connect(DATABASE)
        cursor = db.cursor()
        print "Database opened"
        
        _hashed_password = generate_password_hash(_password)
        print _hashed_password
        
        _userid = str(_name) + str(_hashed_password[0:4])
        db.execute('INSERT INTO tbl_user VALUES (?,?,?,?)',(_userid,_name,_email,_hashed_password))
        db.commit()
        
        data = cursor.fetchall()
        cursor.close() 
        db.close()
        print "Database closed"
        return "DONE"

@app.route('/userHome')
def userHome():
    return render_template('userHome.html')
    
@app.route('/validateLogin',methods=['POST'])
def validateLogin():

    
    try:
        _username = request.form['inputEmail']
        _password = request.form['inputPassword']
        print "user entered:" + str(_username)
    
        db = g._database = sqlite3.connect(DATABASE)
        cursor = db.cursor()  
        print "got here"
        data = db.execute("select * from tbl_user where user_username = (?)",(_username,))
        print "now here"
        data = data.fetchall()
        print "data: " + str(data)



        if len(data) > 0:

            if check_password_hash(str(data[0][3]),_password):
                return redirect('/userHome')
            else:
                return render_template('error.html',error = 'Wrong Email address or Password.')
        else:
            return render_template('error.html',error = 'Wrong Email address or Password.')
    
    
    except Exception as e:
        return render_template('error.html',error = str(e))
    
    finally:
        cursor.close()
        db.close()
    
if __name__ == "__main__":
    app.run(port=5002)


user entered:l@l.com
got here
now here
data: [(u'l@l.compbkd', u'l@l.com', u'l@l.com', u'pbkdf2:sha1:1000$d5pxcFCr$be2ebc88a1c6f09106b4d250c3a8eb8109650d3a')]
user entered:sdaf@f.comd
got here
now here
data: []
Fionnuala fmalone@tcd.ie
Database opened
pbkdf2:sha1:1000$YUQviddx$dcdd10b48416adf12b882737a4a780a36f4d9063
Database closed
user entered:fmalone@tcd.ie

In [25]:
db = sqlite3.connect('BucketList.db')
cursor = db.cursor()  

username = "l@l.com"
data = db.execute("select * from tbl_user where user_username = (?)",(username,))
data.fetchall()


Out[25]:
[(u'l@l.compbkd',
  u'l@l.com',
  u'l@l.com',
  u'pbkdf2:sha1:1000$d5pxcFCr$be2ebc88a1c6f09106b4d250c3a8eb8109650d3a')]

In [ ]: