示例#1
0
    def parse_sesh(self):
        """Get the session form the cookie or the url"""

        sesh = Session()
        sid = ""

        # token in the request then use it
        sid = self.request.get(self.conf.URL_TOKEN_NAME, default_value="")
        # else get the token from the session
        if sid == "":
            if self.conf.TOKEN_NAME in self.request.cookies:
                sid = self.request.cookies[self.conf.TOKEN_NAME]


        if sid == "":
            # no sesion found so create one
            sesh.create()
        else:
            # got a session id so load from memcache or create a new one if its timed out
            sesh.load(sid)

        logging.debug("Session ID: " + sesh.id())
        self.response.headers['Set-Cookie'] = str('%s=%s;path=/;expires=Sat, 1-Jan-2050 00:00:00 GMT;'%(self.conf.TOKEN_NAME, sesh.id()))
        
        return sesh
示例#2
0
  def test_multiple_session(self):
    user = User.create()
    sessions = [
      Session.create(user = user),
      Session.create(user = user)
    ]

    for session in Session.find_by_user(user).all:
      assert session in sessions
示例#3
0
    def start_recording(self):
        if self.state == State.IDLE:
            sys_manager.session = Session.create()
            # create_path_if_not_existing('{}_{}'.format(Path.recording_buffer, sys_manager.session.id))

            self.state = State.RECORDING
        else:
            Print.warning("Is already recording.")
示例#4
0
def login() -> Response:
    """
    Handles the login which means that this will create a new session
    if the given credentials are valid.

    :return: A response
    """

    token = request.headers.get('Token')

    username = request.form.get("username")
    password = request.form.get("password")

    # check if username and password are given
    if None in (username, password):
        return make_response({"error": "username or password not given"})

    # checks if the token sent by the user does exist and is still valid
    if token is not None:
        session = Session.find(token)
        if session is not None:
            if session.is_valid():
                return make_response({"error": "already signed in"})

    user = User.get(username)
    if not user:
        return make_response({"error": "incorrect password"})

    password_validity = user.validate_password(password)

    if password_validity:
        return make_response({
            # create session and return its token
            "token": Session.create(user.id).token
        })
    else:
        return make_response({"error": "incorrect password"})
示例#5
0
 def test_without_user(self):
   with pytest.raises(Exception):
     Session.create(user = None)
示例#6
0
 def test_get_owner(self):
   user = User.create()
   session = Session.create(user = user)
   session = Session.find_by_id(session.id)
   assert user == session.fetch_user()
示例#7
0
 def test_duplicate_tokens(self):
   user = User.create()
   Session.create(user = user, token = 'test_token')
   with pytest.raises(Exception):
     Session.create(user = user, token = 'test_token')
示例#8
0
 def test_with_user(self):
   user = User.create()
   result = Session.create(user = user)
   assert result.user == user