Esempio n. 1
0
def attempt_login(cursor):
    username, password = "", ""
    
    # Try to get it from CGI, failing that try cookies
    # Don't try to get it from CGI if it's mode=edit_user
    if common_f.get_val('mode',"") != "edit_user":
        username = common_f.get_val('username', "")
        password = common_f.get_val('password', "")
        from_cookie = False
    
    # Cookies method
    if username == "" and password == "":
        username = html_f.get_cookie('profiteer_username', "")
        password = html_f.get_cookie('profiteer_password', "")
        from_cookie = True
    
    # Still nothing?
    if username == "" and password == "":
        if os.environ.get('REMOTE_ADDR') == "::1" or os.environ.get('REMOTE_ADDR') == None:
            u = common_q.get_one(cursor, User, id=1)
            common_f.cache['user'] = u
            return u
        return ""
    
    response = get_user(cursor, username, password, from_cookie)
    
    if type(response) == User:
        html_f.set_cookie("profiteer_username", username)
        html_f.set_cookie("profiteer_password", response.password)
    
    return response
Esempio n. 2
0
 def test_cookies(self):
     self.test_targets.append(html_f.set_cookie)
     self.test_targets.append(html_f.delete_cookie)
     self.test_targets.append(html_f.get_cookie)
     
     # Wipe the cookies to start with
     html_f.cookies = cookies.SimpleCookie()
     
     self.assertEqual(html_f.get_cookie("nonexistant_cookie"), None)
     
     # Lets try setting one
     html_f.set_cookie("imaginary_cookie", "math.sqrt(-1)")
     self.assertEqual(html_f.get_cookie("imaginary_cookie"), "math.sqrt(-1)")
     
     # Delete
     html_f.delete_cookie("imaginary_cookie")
     self.assertEqual(html_f.get_cookie("nonexistant_cookie"), None)