Esempio n. 1
0
def signup():
    form = forms.Signup()

    if flask.request.method == "GET":  # STATE 1: The user requests only the html content
        return flask.render_template("signup.jin", signupform=form)

    else:  # STATE 2: The user already saw the page and filled the content

        if form.validate_on_submit():  # STATE 2a: The form is valid

            # Create a user
            user = models.User()
            user.name = form.username.data
            user.age = form.age.data
            user.email =   form.email.data
            user.city = form.city.data

            user.add_password(form.password.data)

            user.add_to_db()

            flask.flash("Welcome, " + form.username.data)
            return flask.redirect(flask.url_for('homepage'))

        else:  # STATE 2b: The form is invalid
            flask.flash("Invalid form")
            return flask.render_template("signup.jin", signupform=form)
Esempio n. 2
0
def signup():
    # Creating a form
    myform = forms.SignupForm()

    # If the form has already been filled and the user
    # is sending the data through post
    if flask.request.method == 'POST':
        if myform.validate_on_submit():
            # Retrieving the data from the form
            age = int(myform.age.data)
            name = myform.name.data
            pwd = myform.pwd.data

            # Create a user
            user = models.User(name=name, age=age, pwd=pwd)

            # Add it to the database
            db.session.add(user)
            db.session.commit()

            # Redirect
            return flask.redirect(flask.url_for('homepage'))

    # It's the first time that the user fetches this page and
    # we need to send him the page content (the HTML)

    return flask.render_template('signup.jin', form=myform)