Exemplo n.º 1
0
 def get_current_session(self, request):
   """
   Returns a session object if a session can be detected given the HTTP request.
   This may include sifting through cookie values, or request params.
   
   Args:
   request
   
   Returns:
   Session or None
   """
   quoted_email = request.request.cookies.get(WEB_ADMIN_PARAMS.COOKIE_EMAIL_PARAM)
   quoted_ssid = request.request.cookies.get(WEB_ADMIN_PARAMS.COOKIE_KEY_PARAM)
   quoted_exp = request.request.cookies.get(WEB_ADMIN_PARAMS.COOKIE_EXPIRATION)
   
   if quoted_email == "" or quoted_ssid == "" or quoted_exp == "" or quoted_email == None or quoted_ssid == None or quoted_exp == None:
     return None
   else:
     import base64
     try: 
       unquoted_email = base64.decodestring(quoted_email)
       unquoted_ssid = base64.decodestring(quoted_ssid)
       unquoted_exp = base64.decodestring(quoted_exp)
     
       decrypted_email = encryption.des_decrypt_str(unquoted_email)
       decrypted_ssid = encryption.des_decrypt_str(unquoted_ssid)
       decrypted_exp = encryption.des_decrypt_str(unquoted_exp)
     except:
       logging.error("Error decoding sesssion: UnicodeDecodeError: 'ascii' codec can't decode byte: ordinal not in range(128)")
       return None 
     """ Make sure that the session has not expired """
     now = time.time()
     if not decrypted_exp:
       decrypted_exp = 0
     exp = float(decrypted_exp)
     if(now < exp):
       """ Make sure that the session is still valid """
       account = memcache_db.get_entity(decrypted_email, "Accounts")
       if account != None and account.cookieKey == decrypted_ssid:
         """ Create a new session object and return it """
         self.email = decrypted_email
         self.ssid = decrypted_ssid
         self.expiration = decrypted_exp
         self.account = account
       else:
         return None
     else:
       return None
     return self
Exemplo n.º 2
0
 def get(self):
     from serverside.tools import encryption
     """Do some simple encryption and show results """
     mystr = "hello, world"
     self.response.out.write("encrypt string: " + mystr + "<br/>")
     mystr_enc = encryption.des_encrypt_str("hello, world")
     self.response.out.write("encrypted: " + mystr_enc + "<br/>")
     mystr_dec = encryption.des_decrypt_str(mystr_enc)
     self.response.out.write("decrypted: " + mystr_dec + "<br/>")
Exemplo n.º 3
0
 def get(self):
   from serverside.tools import encryption
   """Do some simple encryption and show results """
   mystr = "hello, world"
   self.response.out.write("encrypt string: " + mystr + "<br/>")
   mystr_enc = encryption.des_encrypt_str("hello, world")
   self.response.out.write("encrypted: " + mystr_enc + "<br/>")
   mystr_dec = encryption.des_decrypt_str(mystr_enc)
   self.response.out.write("decrypted: " + mystr_dec + "<br/>")