Пример #1
0
def login():
    """Render the login page for the ACM-HSCC site"""
    form = LoginForm()

    if form.validate_on_submit():
        login_user(form.user, remember=form.remember.data)
        flash('You are now logged in to the ACM-HSCC site', 'alert-success')
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        return render_template('login.html', form=form)
Пример #2
0
def login():
    """Render the login page for the ACM-HSCC site"""
    form = LoginForm()

    if form.validate_on_submit():
        login_user(form.user, remember=form.remember.data)
        flash('You are now logged in to the ACM-HSCC site', 'alert-success')
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        return render_template('login.html', form=form)
Пример #3
0
def create_team():
    """Create a new team"""
    form = CreateTeamForm()

    if form.validate_on_submit():
        db.session.add(form.team)
        db.session.commit()

        flash('You are now a member of {}'.format(form.team.name), 'alert-success')
        return redirect(url_for('account.my_team'))
    else:
        flash_form_errors(form)
        return render_template('account/create_team.html', form=form)
Пример #4
0
def forgot():
    """Render the forgot password page for the ACM-HSCC site"""
    form = ForgotForm()

    if form.validate_on_submit():
        db.session.add(form.pw_reset)
        db.session.commit()

        form.pw_reset.send()
        flash('A password reset link has been sent to your email', 'alert-success')
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        return render_template('forgot.html', form=form)
Пример #5
0
def forgot():
    """Render the forgot password page for the ACM-HSCC site"""
    form = ForgotForm()

    if form.validate_on_submit():
        db.session.add(form.pw_reset)
        db.session.commit()

        form.pw_reset.send()
        flash('A password reset link has been sent to your email', 'alert-success')
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        return render_template('forgot.html', form=form)
Пример #6
0
def create_team():
    """Create a new team"""
    form = CreateTeamForm()

    if form.validate_on_submit():
        db.session.add(form.team)
        db.session.commit()

        flash('You are now a member of {}'.format(form.team.name),
              'alert-success')
        return redirect(url_for('account.my_team'))
    else:
        flash_form_errors(form)
        return render_template('account/create_team.html', form=form)
Пример #7
0
def reset_pass(key):
    """Render the reset password page for the ACM-HSCC site"""
    form = NewPasswordForm()

    if form.validate_on_submit():
        form.user.set_password(form.password.data)
        db.session.delete(form.pw_reset)
        db.session.commit()

        flash('Your password has been successfully reset', 'alert-success')
        login_user(form.user)
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        form.key.data = key
        return render_template('reset_pass.html', form=form)
Пример #8
0
def edit():
    """Return the account edit page"""
    form = EditAccountForm()

    if form.validate_on_submit():
        db.session.commit()
        flash('Your changes have been saved successfully', 'alert-success')
        return redirect(url_for('account.home'))
    else:
        flash_form_errors(form)
        form.grade.data = current_user.grade
        form.shirt_size.data = current_user.shirt_size
        if current_user.language:
            language = current_user.language.name
        if current_user.allergies:
            form.allergies_text.data = current_user.allergies.text
        return render_template('account/edit.html', form=form, lang=language)
Пример #9
0
def join_team(id):
    """Join the team with the given team id"""
    t = Team.query.get(id)
    if not t:
        flash('Error: Team not found.', 'alert-warning')
        return redirect(url_for('default.home'))

    form = JoinTeamForm()
    form.team_id.data = t.id

    if form.validate_on_submit():
        db.session.commit()
        flash('Congrats! You are now a member of {}!'.format(t.name), 'alert-success')
        return redirect(url_for('account.team', id=t.id))
    else:
        flash_form_errors(form)
        return render_template('account/join_team.html', team=t, form=form)
Пример #10
0
def edit():
    """Return the account edit page"""
    form = EditAccountForm()

    if form.validate_on_submit():
        db.session.commit()
        flash('Your changes have been saved successfully', 'alert-success')
        return redirect(url_for('account.home'))
    else:
        flash_form_errors(form)
        form.grade.data = current_user.grade
        form.shirt_size.data = current_user.shirt_size
        if current_user.language:
            language = current_user.language.name
        if current_user.allergies:
            form.allergies_text.data = current_user.allergies.text
        return render_template('account/edit.html', form=form, lang=language)
Пример #11
0
def reset_pass(key):
    """Render the reset password page for the ACM-HSCC site"""
    form = NewPasswordForm()
    form.key.data = key

    if form.validate_on_submit():
        form.user.set_password(form.password.data)
        db.session.delete(form.pw_reset)
        db.session.commit()

        flash('Your password has been successfully reset', 'alert-success')
        login_user(form.user)
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        form.key.data = key
        # NOTE: This render_template is causing a 404
        return render_template('reset_pass.html', form=form, key=key)
Пример #12
0
def join_team(id):
    """Join the team with the given team id"""
    t = Team.query.get(id)
    if not t:
        flash('Error: Team not found.', 'alert-warning')
        return redirect(url_for('default.home'))

    form = JoinTeamForm()
    form.team_id.data = t.id

    if form.validate_on_submit():
        db.session.commit()
        flash('Congrats! You are now a member of {}!'.format(t.name),
              'alert-success')
        return redirect(url_for('account.team', id=t.id))
    else:
        flash_form_errors(form)
        return render_template('account/join_team.html', team=t, form=form)
Пример #13
0
def register():
    """Render the registration page for the ACM-HSCC site"""
    form = RegistrationForm()

    if form.validate_on_submit():
        db.session.add(form.user)
        db.session.add(form.allergies)
        # Hacky solution time! If a student misspelled their school name then
        # had to go through registration again, there may be an empty school
        # This query returns a list of schools with no students
        for empty_school in School.query.filter(~School.students.any()):
            db.session.delete(empty_school)
        db.session.commit()

        flash('You have successfully registered for the ACM-HSCC', 'alert-success')
        login_user(form.user)
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        return render_template('register.html', form=form)
Пример #14
0
def register():
    """Render the registration page for the ACM-HSCC site"""
    form = RegistrationForm()

    if form.validate_on_submit():
        db.session.add(form.user)
        db.session.add(form.allergies)
        # Hacky solution time! If a student misspelled their school name then
        # had to go through registration again, there may be an empty school
        # This query returns a list of schools with no students
        for empty_school in School.query.filter(~School.students.any()):
            db.session.delete(empty_school)
        db.session.commit()

        flash('You have successfully registered for the ACM-HSCC', 'alert-success')
        login_user(form.user)
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        return render_template('register.html', form=form)