Ejemplo n.º 1
0
def sign_in():
    """Sign in view."""
    form = SignInForm()

    if form.validate_on_submit():
        user = User.fetch_by_email(form.email.data)
        if not user:
            form.add_error('email', 'There is no such user.')
        elif not user.check_password(form.password.data):
            form.add_error('password', 'Password is invalid.')
        elif login_user(user, remember=True):
            return redirect(request.args.get('next') or url_for('events'))

    return render_template('sign_in.html', form=form)
Ejemplo n.º 2
0
def sign_up():
    """Registration form."""
    form = SignUpForm()

    if form.validate_on_submit():
        user = User.fetch_by_email(form.primary_email.data)
        if user:
            form.add_error('email', 'User with such e-mail address already exists.')
        else:
            user = User()
            with db.transaction as session:
                user.name = form.name.data
                user.password = form.password.data
                session.add(user)
            with db.transaction:
                user.primary_email = form.primary_email.data
            return redirect(url_for('sign_in'))

    return render_template('sign_up.html', form=form)