Пример #1
0
def post_signup():
    name = bottle.request.forms.get("name")
    email = bottle.request.forms.get("email")
    password = bottle.request.forms.get("password")

    errors = {}

    if user.validate_signup(email, password, errors):
        if user.newuser(email, password):
            session_id = user.start_session(email)
            print session_id
            cookie = user.make_secure_val(session_id)
            bottle.response.set_cookie("session", cookie)
            bottle.redirect("/welcome")
        else:
            errors[
                'email_error'] = "Email already in use. Please choose another"
    else:
        print "user did not validate"

    return bottle.template(
        "user_signup", {
            'name': cgi.escape(name),
            'password': '',
            'email': cgi.escape(email),
            'errors': errors
        })
Пример #2
0
def process_signup(): 

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

    if (username == None): 
            print "welcome: can't identify user...redirecting to signup" 
            return bottle.redirect("/signup") 

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

    errors = {
        'username':cgi.escape(username), 
        'email':cgi.escape(email),
        'username_error': '',
    } 

    if (user.validate_signup(username, password, verify, email, errors)): 
        if(not user.newuser(connection, username, password, email)):
            print(errors)
            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) 
        return bottle.redirect("/welcome") 
Пример #3
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)
Пример #4
0
def process_signup():
    connection = MongoClient('localhost', 27017)

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

    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)):
            # trata duplicados
            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)
Пример #5
0
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"))
Пример #6
0
def process_login():
    connection = pymongo.Connection(connection_string, safe=True)

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

    userRecord = {}
    if user.validate_login(connection, username, password, userRecord):
        # looks good. start a new session
        session_id = user.start_session(connection, username)
        if session_id is -1:
            redirect("/internal_error")

        cookie = user.make_secure_val(session_id)
        # send the cookie back to the user
        response.set_cookie("session", cookie)
        # full round trip here.
        redirect("/main")
    else:
        # not a valid login
        return template(
            "login",
            dict(username_value=cgi.escape(username),
                 password="",
                 username="",
                 login_error="Invalid Login"))
Пример #7
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)
Пример #8
0
def process_signup():

    connection = pymongo.MongoClient(connection_string)
    
    email = bottle.request.forms.get("email")
    username = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")
    verify = bottle.request.forms.get("verify")

    # подготовоим объект, если вдруг у нас будут ошибки
    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)):
            # дубликат
            errors['username_error'] = "Имя уже используется"
            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("/")
    else:
        print "user did not validate"
        return bottle.template("signup", errors)
Пример #9
0
def process_login():

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

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

    userRecord = {}
    if user.validate_login(connection, username, password, userRecord):
        # looks good. start a new session
        session_id = user.start_session(connection, username)
        if session_id == -1:
            bottle.redirect("/internal_error")

        cookie = user.make_secure_val(session_id)
        # send the cookie back to the user
        bottle.response.set_cookie("session", cookie)

        # full round trip here.

        bottle.redirect("/welcome")

    else:
        # not a valid login
        return bottle.template("login", dict(username=cgi.escape(username), password="", login_error="Invalid Login"))
Пример #10
0
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"))
Пример #11
0
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)

        
        bottle.response.set_cookie("session", cookie)
        
        bottle.redirect("/welcome")

    else:
        return bottle.template("login", 
                           dict(username=cgi.escape(username), password="", 
                                login_error="Invalid Login"))
Пример #12
0
def process_signup():
    print('signup process')
    connection = MongoClient("localhost", 27017)

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

    # set these up in case we have an error case
    errors = {'username': cgi.escape(username), 'email': cgi.escape(email)}
    print('er:', errors)
    if (user.validate_signup(username, password, verify, email, errors)):
        print('here1')
        if (not user.newuser(connection, username, password, email)):
            # this was a duplicate
            print('dup')
            errors['username_error'] = "Username already in use. Please choose another"
            return bottle.template("signup", errors)

        session_id = user.start_session(connection, username)
        print ('sessionid', session_id)
        cookie = user.make_secure_val(session_id)
        bottle.response.set_cookie("session", cookie)
        #cook = bottle.request.get_cookie('session')
        #print('cook', cook)
        #print('user', username)
        #username = bottle.request.forms.get("username")
        return bottle.template("welcome", username=username)
    else:
        print ("user did not validate")
        return bottle.template("signup", errors)
Пример #13
0
def process_login():

    connection = pymongo.MongoClient(connection_string)

    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)

        # не работает с bottle .12, откатитесь на версию .11
        bottle.response.set_cookie("session", cookie)
        
        bottle.redirect("/")

    else:
        return bottle.template("login", 
                           dict(username=cgi.escape(username), password="", 
                                login_error="неверно"))
Пример #14
0
def process_login():

    connection = MongoClient('localhost', 27017)

    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)

        bottle.response.set_cookie("session", cookie)

        bottle.redirect("/welcome")

    else:
        return bottle.template(
            "login",
            dict(username=cgi.escape(username),
                 password="",
                 login_error="Invalid Login"))
Пример #15
0
def process_login():


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

    if (username == None): 
        print "welcome: can't identify user...redirecting to signup" 
        bottle.redirect("/signup") 

    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)

        bottle.response.set_cookie("session", cookie)

        bottle.redirect("/welcome")

    else:
        return bottle.template("login", dict(username=cgi.escape(username), password="", login_error="Invalid Login"))
Пример #16
0
def process_login():
    username = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")
    userRecord = {}
    if (user.validate_login(username, password, userRecord)):
        session_id = user.start_session(userRecord['uid'])
        cookie = user.make_secure_val(str(int(session_id)))
        bottle.response.set_cookie("session", cookie)

        bottle.redirect("/blog/welcome")

    else:
        return bottle.template("login", 
                           dict(username=cgi.escape(username), password="", 
                                login_error="Invalid Login"))
Пример #17
0
def post_signin():
    email = bottle.request.forms.get("email")
    password = bottle.request.forms.get("password")

    if user.validate_login(email, password):
        session_id = user.start_session(email)

        if session_id == -1:
            bottle.redirect("/error")

        cookie = user.make_secure_val(session_id)

        bottle.response.set_cookie("session", cookie)
        bottle.redirect("/welcome")
    else:
        return bottle.template("login", {
            'email': cgi.escape(email),
            'password': '',
            'error': 'Invalid login'
        })
Пример #18
0
def process_signup():
    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)):
        uid = user.newuser(username, password, email)
        if (uid == None):
            # this was a duplicate
            errors['username_error'] = "Username already in use. Please choose another"
            return bottle.template("signup", errors)
            
        session_id = user.start_session(uid)
        cookie= user.make_secure_val(str(int(session_id)))
        bottle.response.set_cookie("session",cookie)
        bottle.redirect("/blog/welcome")
    else:
        return bottle.template("signup", errors)
Пример #19
0
def signup():
    connection = pymongo.Connection(connection_string, safe=True)

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

    # set these up in case we have an error case
    errors = {'username_value': cgi.escape(username), 'username': ''}
    if user.validate_signup(username, password, errors):
        if not user.new_user(connection, username, password):
            # this was a duplicate
            errors['username_error'] = "Username already in use. Please choose another"
            return template("signup", errors)

        session_id = user.start_session(connection, username)
        print session_id
        cookie = user.make_secure_val(session_id)
        response.set_cookie("session", cookie)
        redirect("/main")
    else:
        print "user did not validate"
        return template("signup", errors)
Пример #20
0
def signup():
    connection = pymongo.Connection(connection_string, safe=True)

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

    # set these up in case we have an error case
    errors = {'username_value': cgi.escape(username), 'username': ''}
    if user.validate_signup(username, password, errors):
        if not user.new_user(connection, username, password):
            # this was a duplicate
            errors[
                'username_error'] = "Username already in use. Please choose another"
            return template("signup", errors)

        session_id = user.start_session(connection, username)
        print session_id
        cookie = user.make_secure_val(session_id)
        response.set_cookie("session", cookie)
        redirect("/main")
    else:
        print "user did not validate"
        return template("signup", errors)