def welcome(username): """ welcome """ user = User.objects().get(username=username) print session['username'] if username != session['username']: return "You are a Liar!" return render_template("home/welcome.html", user=user)
def login(): """ the login controller """ if session.get('username'): username = session.get('username') nextpage = request.args.get('next') return redirect(nextpage or url_for('home.welcome', username=username)) # If sign in form is submitted form = LoginForm(request.form) # Verify the sign in form if form.validate_on_submit(): user = User.objects(username=form.username.data)[0] pass_hash = generate_password_hash(user.password) # authenticate the user and create the session if user and check_password_hash(pass_hash, form.password.data): login_user(user) session['username'] = user.username flash('Welcome %s' % user.username) nextpage = request.args.get('next') return redirect(nextpage or url_for('home.welcome', username=user.username)) flash('Wrong username or password', 'error') return render_template("auth/login.html", form=form)
def load_user(username): user = User.objects().get(username=username) return user