ARTICLE AD BOX
When I try to log in my user after identifying it and using the check_password_hash() of werkzeug security. I get 404 my redirection link invalid, or after adding the try and except clause, gets redirected to my except, stating that 'tuple' object has no attribute 'is_active' ,
as illustrated in the first code blocks and second 'What the page tells me' . But when I remove just the login_user the redirection works just fine and demonstrated in the third block code.
First code block:
if check_password_hash(stored_hash, request.form.get('password')): print('logging in') login_user(row) return redirect(url_for('home',email=user_email,name=user_email)) else: return render_template('error.html') except Exception as e: print(e) return render_template('invalid_details.html')The first code block straight up goes by my 'try' code and goes into the except, stating that : 'tuple' object has no attribute 'is_active'
second code block: (similar to the first except login_user() is disabled
if check_password_hash(stored_hash, request.form.get('password')): print('logging in') #login_user(row) return redirect(url_for('home',email=user_email,name=user_email)) else: return render_template('error.html') except Exception as e: print(e) return render_template('invalid_details.html')the second code block works and redirects me to 'home' but my user is not logged in.
The log_user() function was not coded by me but by flask and it is like this
def login_user(user: object, remember: bool = False, duration: timedelta = None, force: bool = False, fresh: bool = True) -> bool Logs a user in. You should pass the actual user object to this. If the user's is_active property is False, they will not be logged in unless force is True. This will return True if the log in attempt succeeds, and False if it fails (i.e. because the user is inactive). Params: user – The user object to log in. remember – Whether to remember the user after their session expires. Defaults to False. duration – The amount of time before the remember cookie expires. If None the value set in the settings is used. Defaults to None. force – If the user is inactive, setting this to True will log them in regardless. Defaults to False. fresh – setting this to False will log in the user with a session marked as not "fresh". Defaults to True.I spent a lot of time on this and tried several solutions already. The first saying that the 'row' I identified from the database can't be logged in, so I created a new User_obj class and made an object with the class, using the email and password passed over from my login form, as illustrated in the third code block , however that still does not work.
third code block:
class User_obj: def __init__(self,id,email): self.id = id self.email = email def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return str(self.id)In summary, I want to log in my user, the one recorded in the database, and redirect after successful login to the home page, where their email is used as an input.
