def create_session_id(self): """Returns a random session id. :return: A new session id. """ return generate_key(self.config.secret_key)
def create(request, session): sessid = generate_key() with open(get_filename(request, sessid), 'xb') as f: pickle.dump(session, f, pickle.HIGHEST_PROTOCOL) return sessid
def finish_login(request, destination, params): do_logout(request) server = request.app.settings.servers[int(params['server'])] if params['type'] == 'cosignproxy': name = request.environ['COSIGN_SERVICE'] fladgejt_params = dict(type='cosignproxy', cosign_proxy=request.app.settings.cosign_proxy, cosign_service=(name, request.cookies[name])) else: fladgejt_params = params sessid = datetime.utcnow().strftime('%Y%m%d_') + generate_key() with sessions.lock(request.app, sessid), \ sessions.open_log_file(request, sessid) as log_file: logger = Logger() logger.log_file = log_file try: logger.log('login', 'Login started', [server.get('title'), params.get('type'), destination]) client = create_client(server, fladgejt_params, logger=logger) csrf_token = generate_key() session = dict(csrf_token=csrf_token, credentials=save_credentials(params), client=client) sessions.create(request, sessid, session) except Exception as e: error = traceback.format_exc() logger.log('login', 'Login failed with {}'.format(type(e).__name__), error) response = app_response(request, server=int(params['server']), type=params['type'], error=error, destination=destination) return sessions.set_session_cookie(request, response, None) logger.log('login', 'Login finished') response = app_response(request, csrf_token=csrf_token, destination=destination) return sessions.set_session_cookie(request, response, sessid)
def __init__(self, initial=None, sid=None, new=False, secret_key=None): def on_update(self): self.modified = True SecureCookie.__init__(self, initial, secret_key=secret_key, new=new) self.sid = sid self.new = new self.modified = False if self.sid is None: self.sid = generate_key()
def get_by_sid(cls, sid): """Returns a session given a session id.""" data = None if sid and is_valid_key(sid): data = memcache.get(sid, namespace=cls.get_namespace()) if not data: return cls({}, generate_key(gen_salt(10)), new=True) return cls(data, sid, new=False)
def get_by_sid(cls, sid): """Returns a session given a session id.""" entity = None if sid and is_valid_key(sid): entity = cls.model_class.get_by_sid(sid) if not entity: return cls({}, generate_key(gen_salt(10)), new=True) return cls(entity.data, sid, new=False, entity=entity)
def apikeygen(self): """User apikey generation RESTAPI method.""" pk = g.user.id apikey = generate_key() user_ext = UserExtInfo() user_ext.api_key = apikey user_ext.id = pk count = self.appbuilder.get_session.query(func.count('*')).select_from(UserExtInfo).filter_by(id=pk).scalar() if count: self.appbuilder.get_session.query(UserExtInfo).filter_by(id=pk).update({'api_key': apikey}) else: self.appbuilder.get_session.add(user_ext) self.appbuilder.get_session.commit() return jsonify({'code': 200, 'msg': 'Success', "apikey": apikey})
def rekey(self): self.sid = generate_key()
def get_secret_key(default=None): if default is None: default = generate_key(gen_salt(20)) return get_constant('SECRET_KEY', default=default)