def check_session_id(): """ Generate a UUID and store it in the session as well as in the WebSession table. """ # TODO: Create UserAgentEntity and populate user_agent = get_user_agent() if 'uuid' not in session: session['uuid'] = str(uuid.uuid4()) WebSessionEntity.create(session_id=session['uuid'], user_id=current_user.get_id(), ip=request.remote_addr, date_time=datetime.datetime.now(), user_agent=user_agent) return if current_user.is_authenticated(): # update the user_id on the first request after login is completed session_id = session['uuid'] web_session = WebSessionEntity.get_by_session_id(session_id) if web_session is not None: web_session = WebSessionEntity.update( web_session, user_id=current_user.get_id()) else: app.logger.error("No row found for sess_id: {}".format(session_id))
def check_session_id(): """ Generate a UUID and store it in the session as well as in the WebSession table. """ user_agent = get_user_agent() if 'uuid' not in session: session['uuid'] = str(uuid.uuid4()) WebSessionEntity.create(session_id=session['uuid'], user_id=current_user.get_id(), ip=request.remote_addr, date_time=datetime.datetime.now(), user_agent=user_agent) return if current_user.is_authenticated(): # update the user_id on the first request after login is completed session_id = session['uuid'] web_session = WebSessionEntity.get_by_session_id(session_id) if web_session is not None: web_session = WebSessionEntity.update( web_session, user_id=current_user.get_id()) else: app.logger.error("No row found for sess_id: {}".format(session_id))
def _log(log_type, session_id, details=''): """ Helper for logging """ logt = LogTypeEntity.query.filter_by(type=log_type).first() if logt is None: app.logger.error( "Developer error. Invalid log type: {}".format(log_type)) return web_session = WebSessionEntity.get_by_session_id(session_id) if web_session is None: app.logger.error( "Developer error. Invalid session id: {}".format(session_id)) return LogEntity.create(log_type=logt, date_time=datetime.datetime.now(), details=details, web_session=web_session)
def _log(log_type, session_id, details=''): """ Helper for logging """ logt = LogTypeEntity.query.filter_by(type=log_type).first() if logt is None: app.logger.error("Developer error. Invalid log type: {}" .format(log_type)) return web_session = WebSessionEntity.get_by_session_id(session_id) if web_session is None: app.logger.error("Developer error. Invalid session id: {}" .format(session_id)) return LogEntity.create(log_type=logt, date_time=datetime.datetime.now(), details=details, web_session=web_session)