Ejemplo n.º 1
0
def set_cookie(aConfig, key, value):
    secure = False
    if aConfig['gConfig']['web']['enable_ssl'].lower() == 'true':
        secure = True
    session_age = 60
    app = aConfig['gConfig']['wsgi']['application']
    try:
        session_age = int(aConfig['gConfig']['applications'][app]['session']['session_age'])
    except:
        pass
    if 'session_domain' in aConfig['gConfig']['applications'][app]['session'] and len(aConfig['gConfig']['applications'][app]['session']['session_domain'])>0:
        cookie = ('Set-Cookie', dump_cookie(key, value,  max_age=session_age, secure=secure, domain=aConfig['gConfig']['applications'][app]['session']['session_domain']))
    else:
        cookie = ('Set-Cookie', dump_cookie(key, value,  max_age=session_age, secure=secure))
    return cookie
Ejemplo n.º 2
0
 def injecting_start_response(status, headers, exc_info=None):
     if session.should_save:
         self.store.save(session)
         headers.append(('Set-Cookie', dump_cookie(self.cookie_name,
                                                   session.sid, self.cookie_age,
                                                   self.cookie_expires, self.cookie_path,
                                                   self.cookie_domain, self.cookie_secure,
                                                   self.cookie_httponly)))
     return start_response(status, headers, exc_info)
Ejemplo n.º 3
0
 def injecting_start_response(status, headers, exc_info=None):
     if session.should_save:
         self.store.save(session)
         headers.append(('Set-Cookie', dump_cookie(self.cookie_name,
                                                   session.sid, self.cookie_age,
                                                   self.cookie_expires, self.cookie_path,
                                                   self.cookie_domain, self.cookie_secure,
                                                   self.cookie_httponly)))
     return start_response(status, headers, exc_info)
Ejemplo n.º 4
0
 def set_cookie(self, server_name, key, value='', max_age=None,
                expires=None, path='/', domain=None, secure=None,
                httponly=False, charset='utf-8'):
     """Sets a cookie in the client's cookie jar.  The server name
     is required and has to match the one that is also passed to
     the open call.
     """
     assert self.cookie_jar is not None, 'cookies disabled'
     header = dump_cookie(key, value, max_age, expires, path, domain,
                          secure, httponly, charset)
     environ = create_environ(path, base_url='http://' + server_name)
     headers = [('Set-Cookie', header)]
     self.cookie_jar.extract_wsgi(environ, headers)
Ejemplo n.º 5
0
 def set_cookie(self, server_name, key, value='', max_age=None,
                expires=None, path='/', domain=None, secure=None,
                httponly=False, charset='utf-8'):
     """Sets a cookie in the client's cookie jar.  The server name
     is required and has to match the one that is also passed to
     the open call.
     """
     assert self.cookie_jar is not None, 'cookies disabled'
     header = dump_cookie(key, value, max_age, expires, path, domain,
                          secure, httponly, charset)
     environ = create_environ(path, base_url='http://' + server_name)
     headers = [('Set-Cookie', header)]
     self.cookie_jar.extract_wsgi(environ, headers)
Ejemplo n.º 6
0
 def injecting_start_response(status, headers, exc_info=None):
     if session.should_save:
         age = session.get('_sheep_permstore', self.cookie_age)
         try:
             age = int(age)
         except:
             age = self.cookie_age
         self.store.save(session)
         headers.append(('Set-Cookie', dump_cookie(self.cookie_name,
                         session.sid, age,
                         self.cookie_expires, self.cookie_path,
                         self.cookie_domain, self.cookie_secure,
                         self.cookie_httponly)))
     return start_response(status, headers, exc_info)
Ejemplo n.º 7
0
        def authentication(status, headers, exc_info=None):
            if environ.get(auth_collection.__name__.lower()):
                headers.extend([
                    ('Set-Cookie',
                     dump_cookie(
                         'session_id',
                         environ['session'].sid,
                         30 * 24 * 60 * 60,
                     )),
                    ('HTTP_AUTHORIZATION',
                     'Token {0}'.format(environ['session'].sid)),
                ])

            return start_response(status, headers, exc_info)
Ejemplo n.º 8
0
        def authentication(status, headers, exc_info=None):
            headers.extend([
                (
                    'Set-Cookie', dump_cookie(
                        'session_id', environ['session'].sid, 7 * 24 * 60 * 60,
                    )
                ),
                (
                    'HTTP_AUTHORIZATION', 'Token {0}'.format(
                        environ['session'].sid
                    )
                ),
            ])

            return start_response(status, headers, exc_info)
Ejemplo n.º 9
0
 def injecting_start_response(status, headers, exc_info=None):
     if session.should_save:
         age = session.get('_titan_permstore', self.cookie_age)
         try:
             age = int(age)
         except:
             age = self.cookie_age
         self.store.save(session)
         headers.append(
             ('Set-Cookie',
              dump_cookie(self.cookie_name, session.sid, age,
                          self.cookie_expires, self.cookie_path,
                          self.cookie_domain, self.cookie_secure,
                          self.cookie_httponly)))
     return start_response(status, headers, exc_info)
Ejemplo n.º 10
0
    def set_cookie(self, key, value='', max_age=None, expires=None,
                   path='/', domain=None, secure=None, httponly=False):
        """Sets a cookie. The parameters are the same as in the cookie `Morsel`
        object in the Python standard library but it accepts unicode data too:

        - `max_age` should be a number of seconds, or `None` (default) if the
           cookie should last only as long as the client’s browser session.
        - `expires` should be a `datetime` object or UNIX timestamp.
        - Use `domain` if you want to set a cross-domain cookie.  For example,
          ``domain=".example.com"`` will set a cookie that is readable by the
          domain ``www.example.com``, ``foo.example.com`` etc.  Otherwise, a
          cookie will only be readable by the domain that set it.
        - `path` limits the cookie to a given path, per default it will span
          the whole domain.
        """
        self.headers.add('Set-Cookie', dump_cookie(key, value, max_age,
                         expires, path, domain, secure, httponly,
                         self.charset))
Ejemplo n.º 11
0
 def injecting_start_response(status, headers, exc_info=None):
     
     cookie_value = usersession.get_cookie_value()            
     
     cookie_str = dump_cookie(
         self.cookie_name,
         cookie_value if cookie_value is not None else "", 
         self.cookie_age,
         None if cookie_value is not None else datetime.datetime.now() - datetime.timedelta(days=1),
         self.cookie_path,
         self.cookie_domain, 
         self.cookie_secure,
         self.cookie_httponly)
                     
     headers.append(('Set-Cookie', cookie_str))
     
     self.userbase.store_changes()
     
     return start_response(status, headers, exc_info)
Ejemplo n.º 12
0
 def set_cookie(self, key, value = '', max_age = None, expires = None, path = '/', domain = None, secure = None, httponly = False):
     self.headers.add('Set-Cookie', dump_cookie(key, value, max_age, expires, path, domain, secure, httponly, self.charset))
Ejemplo n.º 13
0
 def set_cookie(self, key, value = '', max_age = None, expires = None, path = '/', domain = None, secure = None, httponly = False):
     self.headers.add('Set-Cookie', dump_cookie(key, value, max_age, expires, path, domain, secure, httponly, self.charset))
Ejemplo n.º 14
0
 def login(self, request, args):
     key = hashlib.sha512(salt + args["key"] + salt).hexdigest()
     if key == password:
         return Response("ok", headers=[("Set-Cookie", dump_cookie("key", key))])
     return Response("failed")