コード例 #1
0
ファイル: blog.py プロジェクト: hughdbrown/mongo-blog
def process_signup():
    db = blog_connection()

    keys = ["email", "username", "password", "verify"]
    fn = bottle.request.forms.get
    email, username, password, verify = [fn(k) for k in keys]

    # 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(db, 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(db, username)
        print("Session id %s" % session_id)
        cookie = user.make_secure_val(session_id)
        bottle.response.set_cookie("session", cookie)
        bottle.redirect("/welcome")
    else:
        print("user '%s' did not validate" % username)
        return bottle.template("signup", errors)
コード例 #2
0
ファイル: blog.py プロジェクト: hughdbrown/mongo-blog
def process_login():
    db = blog_connection()

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

    print("user submitted ", username, "pass ", password)

    userRecord = {}
    if user.validate_login(db, username, password, userRecord):
        session_id = user.start_session(db, 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", {
            'username': cgi.escape(username),
            'password': "",
            'login_error': "Invalid Login"
        })