Beispiel #1
0
def process_signup():

    connection = pymongo.Connection(connection_string, safe=True)

    email = bottle.request.forms.get("email")
    username = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")
    verify = bottle.request.forms.get("verify")

    # set these up in case we have an error case
    errors = {'username':cgi.escape(username), 'email':cgi.escape(email)}
    if (user.validate_signup(username, password, verify, email, errors)):
        if (not user.newuser(connection, username, password, email)):
            # this was a duplicate
            errors['username_error'] = "Username already in use. Please choose another"
            return bottle.template("signup", errors)
            
        session_id = user.start_session(connection, username)
        print session_id
        cookie= user.make_secure_val(session_id)
        bottle.response.set_cookie("session",cookie)
        bottle.redirect("/welcome")
    else:
        print "user did not validate"
        return bottle.template("signup", errors)
Beispiel #2
0
def signup():
    form = SignUpForm(request.form)
    if request.method == "POST":
        if form.validate():
            username = form.username.data
            email = form.email.data
            password = form.password.data
            connection = pymongo.Connection(CONNECTION_STRING,
                                            safe=True)

            message = {"error": None}
            if not user.newuser(connection[DATABASE],
                                username, email, password, message):
                pigeon.error(message["error"])
            else:
                pigeon.success(u"Welcome to Office! Your local gist!")

                # Set cookies to client.
                session_id = user.start_session(connection[DATABASE], username)
                cookie = user.make_secure_val(session_id)
                redirect_to_home = redirect_back("index")
                response = app.make_response(redirect_to_home)
                response.set_cookie(COOKIE, value=cookie)

                # Mark this user has logged in.
                session["logged_in"] = True
                session["username"] = username
                return response

    return render_template("signup.html", form=form, status="signup")