def dangnhap(): if request.method == "GET": return render_template("dangnhap.html") elif request.method == "POST": user = User.objects(username=request.form["username"]).first() if user and user.password == request.form["password"]: session_user = SessionUser(user.id) user.update(set__token=str(user.id)) login_user(session_user) return redirect(url_for("addfood")) else: return render_template("dangnhap.html")
def login1(): if request.method == "GET": return render_template("login1.html") elif request.method == "POST": user = User.objects(username=request.form['username']).first() if user and user.password == request.form['password']: session_user = SessionUser(user.id) user.update(set__token=str(user.id)) login_user(session_user) return redirect(url_for('add_food')) else: return render_template("login1.html")
def login_web(): if request.method == "GET": return render_template("login.html") elif request.method == "POST": user = User.objects(username=request.form["username"]).first() if user and user.password == request.form["password"]: session_user = SessionUser(user.id) user.update(set__token=str(user.id)) login_user(session_user) return render_template("homepage_login.html") else: pass return redirect(url_for("login_web"))
def user_loader(user_token): found_user = User.objects(token=user_token).first() if found_user: session_user = SessionUser(found_user.id) return session_user