Пример #1
0
def admin():
    logged_user = google_users.get_current_user()
    form = AdminForm(request.form)
    if form.validate_on_submit():
        user = User()
        user.email = form.email.data
        user.name = form.name.data
        user.password = generate_password_hash(form.password.data)
        user.put()
        return redirect(url_for("auth.admin"))

    users = User.query().order(-User.created_at)
    return render_template(
        "auth/admin.html", form=form, users=users, logged_user=logged_user, google_users=google_users
    )
Пример #2
0
def login():
    if "user_id" in session:
        return redirect("/posts/")

    form = LoginForm(request.form)
    # Verify the sign in form
    if form.validate_on_submit():
        user = User.query(User.email == form.email.data).get()
        if user and check_password_hash(user.password, form.password.data):
            session["user_id"] = user.key.id()
            flash("Welcome %s" % user.name)
            return redirect("/posts/")

        flash("Invalid email or password", "error")

    return render_template("auth/signin.html", form=form)
Пример #3
0
def login():
    if 'user_id' in session:
        return redirect('/posts/')

    form = LoginForm(request.form)
    # Verify the sign in form
    if form.validate_on_submit():
        user = User.query(User.email == form.email.data).get()
        if user and check_password_hash(user.password, form.password.data):
            session['user_id'] = user.key.id()
            flash('Welcome %s' % user.name)
            return redirect('/posts/')

        flash('Invalid email or password', 'error')

    return render_template("auth/signin.html", form=form)
Пример #4
0
def admin():
    logged_user = google_users.get_current_user()
    form = AdminForm(request.form)
    if form.validate_on_submit():
        user = User()
        user.email = form.email.data
        user.name = form.name.data
        user.password = generate_password_hash(form.password.data)
        user.put()
        return redirect(url_for('auth.admin'))

    users = User.query().order(-User.created_at)
    return render_template("auth/admin.html",
                           form=form,
                           users=users,
                           logged_user=logged_user,
                           google_users=google_users)