def new_session(user_id, ip='127.0.0.1', device='web'): """ create a new session for the specified user """ s = Session.get_by_user_id(user_id) if s is None or s.is_expired(__MAX_INACTIVE_SECONDS): s.delete() s = Session(user_id, ip, device) s.insert() return s
def user_session(user_id): """ return the active session of the user_id if the user has not an active session None is returned """ return Session.get_by_user_id(user_id)