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)
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")
def process_login(): connection = pymongo.Connection(connection_string, safe=True) username = bottle.request.forms.get("username") password = bottle.request.forms.get("password") print "user submitted ", username, "pass ", password userRecord = {} if (user.validate_login(connection, username, password, userRecord)): session_id = user.start_session(connection, username) if (session_id == -1): bottle.redirect("/internal_error") cookie = user.make_secure_val(session_id) # Warning, if you are running into a problem whereby the cookie being set here is # not getting set on the redirct, you are probably using the experimental version of bottle (.12). # revert to .11 to solve the problem. bottle.response.set_cookie("session", cookie) bottle.redirect("/welcome") else: return bottle.template("login", dict(username=cgi.escape(username), password="", login_error="Invalid Login or password"))
def signin(): form = SignInForm(request.form) if request.method == "POST": if form.validate(): username = form.username.data password = form.password.data remember = form.remember.data connection = pymongo.Connection(CONNECTION_STRING, safe=True) response = None try: username = user.validate_login(connection[DATABASE], username, password) except DoesNotExist: pigeon.error("You haven't registered yet!") response = app.make_response(redirect_back("signup")) except UserPasswordNotMatch: pigeon.error("Wrong username/password combination!") response = app.make_response(render_template("signin.html", form=form)) if not response: session_id = user.start_session(connection[DATABASE], username) if session_id == -1: pigeon.error("Internal error!") else: cookie = user.make_secure_val(session_id) # 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 else: return response return render_template("signin.html", form=form, status="signin")