Example #1
0
File: user.py Project: ktt-ol/poisk
def create_profile():
    """If this is the user's first login, the create_or_login function
    will redirect here so that the user can set up his profile.
    """
    if g.user.is_authenticated() or "openid" not in session:
        return redirect(url_for("index"))

    form = ProfileForm()
    if form.validate_on_submit():
        flash(u"Profile successfully created", "success")
        user = User(session["openid"])
        user.email = form.email.data
        user.name = form.name.data
        db.session.add(user)
        db.session.commit()
        login_user(user)
        session.pop("openid")

        notify_admins_new_user(user)

        return redirect(oid.get_next_url())

    if request.method == "GET":
        form.name.data = request.args.get("name")
        form.email.data = request.args.get("email")

    return render_template("create_profile.html", next_url=oid.get_next_url(), errors=form.errors, form=form)
Example #2
0
File: user.py Project: ktt-ol/poisk
def show(user_id):
    if user_id != g.user.id:
        user = User.query.get(user_id)
        return render_template("user.html", user=user)
    form = ProfileForm(obj=g.user)
    if form.validate_on_submit():
        if "delete" in request.form:
            db.session.delete(g.user)
            db.session.commit()
            logout_user()
            flash(u"Profile deleted", "success")
            return redirect(url_for("index"))
        flash(u"Profile successfully created", "success")
        g.user.name = form.name.data
        g.user.email = form.email.data
        g.user.is_public = form.is_public.data
        db.session.commit()
        return redirect(url_for(".show", user_id=user_id))
    return render_template("edit_profile.html", form=form)