I tried using Flask-Login to handle my login and session.
On registration process, once all details validated, i can use login_user(user) and redirect to homepage.
I have problem doing the Login process. Upon trying to login, there is an error raised in login_user(user)
'unicode' object is not callable'
On flask-login documentation it says that get_id() must return a unicode, which I have done.i.e:
def get_id(self):
return text_type(self.id)
I have imported text_type (from six import text_type). Previously I just wrote return self.id. It says :
long object not callable
How to solve this ?
below is my login method:
@app.route('/login', methods=['GET','POST'])
def login():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
if email and password:
error = "Invalid email/password!"
user = session.query(User).filter_by(email=email).first()
if user:
hPass = hash_str(password)
if user.password == hPass:
login_user(user, remember=True)
return redirect('/')
else:
return render_template('login.html', alert=render_template('alert.html', errormsg=error))
else:
return render_template('login.html', alert=render_template('alert.html', errormsg=error))
else:
return render_template('login.html')
It raises error on line login_user(user) Thanks.