I have a simple function to log a user in. It first comfirms whether the users details are correct;
import user
@app.route("/login/", methods=['POST', 'GET'])
def login():
if request.method == 'GET':
return render_template('login.html')
else:
_email = request.form['email']
_password = request.form['password']
if user.loginValidate(_email, _password) == True:
session['username'] = user.getUserName(_email)
session['loggedin'] = True
return redirect(url_for('home'))
else:
flash('Email or password incorrect!')
return render_template('login.html')
Now for some reason when I try to call loginValidate
I get an error that 'function' object has no attribute loginValidate
.
The module does have loginValidate
which returns either True
or False
, so I don't see what the issue is.
loginValidate
(within user
module):
def loginValidate(this_email, this_password):
db = sqlite3.connect('data')
cursor = db.cursor()
cursor.execute("SELECT password FROM users WHERE email = ?", (this_email,))
row = cursor.fetchone()
hash = row[0]
db.close()
return hash == bcrypt.hashpw(this_password, hash)
Any help is appreciated!
Try:
from user import loginValidate
And:
if loginValidate(_email, _password) == True: