Example #1
0
def register():
    """Register new user."""
    if current_user.is_authenticated:
        return redirect(url_for("public.home"))
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        User.create(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
            active=True,
        )
        if form.code.data:
            group = StudentGroups.query.filter_by(code=form.code.data).first()
            user = User.query.filter_by(username=form.username.data).first()
            gid = group.get_id()
            uid = user.get_id()
            GroupUsers.create(user_id=uid, group_id=gid)
        else:
            group = StudentGroups.query.filter_by(name="ALL").first()
            gid = group.get_id()
            user = User.query.filter_by(username=form.username.data).first()
            uid = user.get_id()
            GroupUsers.create(user_id=uid, group_id=gid)
        flash("Thank you for registering. You can now log in.", "success")
        return redirect(url_for("public.home"))
    else:
        flash_errors(form)
    return render_template("public/register.html", form=form)
Example #2
0
def home():
    """Home page."""
    form = LoginForm(request.form)
    current_app.logger.info("Hello from the home page!")  #--
    # Handle logging in
    if request.method == "POST":
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", "success")
            redirect_url = url_for("public.home")
            return redirect(redirect_url)
        else:
            flash_errors(form)
    return render_template("public/home.html", form=form)
Example #3
0
def register():
    """Register new user."""
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        User.create(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
            active=True,
        )
        flash("Thank you for registering. You can now log in.", "success")
        return redirect(url_for("public.home"))
    else:
        flash_errors(form)
    return render_template("public/register.html", form=form)