Beispiel #1
0
def register():
    register_form = RegisterForm(request.form)
    if request.method == 'POST':
        if register_form.validate():
            username = request.form['username']
            password = request.form['password']
            created = datetime.datetime.now()
            if register_validation(username):
                User.new_user(
                    username,
                    password,
                    created,
                )
                return redirect(
                    url_for('login_page.login',
                            register_redirect=REGISTER_SUCCESS))
            else:
                return render_template(
                    'register.html',
                    form=register_form,
                    message=REGISTER_FAILURE,
                )
        else:
            return render_template(
                'register.html',
                form=register_form,
                message=FORM_INVALID,
            )
    else:
        return render_template(
            'register.html',
            form=register_form,
        )
Beispiel #2
0
def register():
    loggedInUser = getLoggedUser(getUserSessionId(request))
    if loggedInUser != None:
        return redirect('/')

    form = RegisterForm()

    if request.method == 'POST':
        if not form.validate():
            return render_template('register_form.html',
                                   isUserLoggedIn=False,
                                   form=form,
                                   form_name="Register",
                                   action="register",
                                   method='POST')
        else:
            user = Users(password_hash=getPasswordHash(form.password.data),
                         username=form.username.data,
                         email=form.email.data)

            db = PostgresDb()
            db.sqlalchemy_session.add(user)
            try:
                db.sqlalchemy_session.commit()
            except DatabaseError as e:
                db.sqlalchemy_session.rollback()
                print(e)

            return redirect('/')

    return render_template('register_form.html',
                           isUserLoggedIn=False,
                           form=form,
                           form_name="Register",
                           action="register",
                           method='POST')