19.1.37. camcops_server.cc_modules.cc_session


Copyright (C) 2012-2018 Rudolf Cardinal (rudolf@pobox.com).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <http://www.gnu.org/licenses/>.


class camcops_server.cc_modules.cc_session.CamcopsSession(ip_addr=None, last_activity_utc=None)[source]

Class representing an HTTPS session.

classmethod delete_old_sessions(req: CamcopsRequest) → None[source]

Delete all expired sessions.

classmethod get_session(req: CamcopsRequest, session_id_str: Union[str, NoneType], session_token: Union[str, NoneType]) → CamcopsSession[source]

Retrieves, or makes, a new CamcopsSession for this Pyramid Request, for a specific session_id and session_token.

classmethod get_session_using_cookies(req: CamcopsRequest) → CamcopsSession[source]

Makes, or retrieves, a new CamcopsSession for this Pyramid Request.

login(user: camcops_server.cc_modules.cc_user.User) → None[source]

Log in. Associates the user with the session and makes a new token.

logout(req: CamcopsRequest) → None[source]

Log out, wiping session details. Also, perform periodic maintenance for the server, as this is a good time.

class camcops_server.cc_modules.cc_session.SessionTests(methodName='runTest')[source]
camcops_server.cc_modules.cc_session.generate_token(num_bytes: int = 16) → str[source]

Make a new session token that’s not in use. It doesn’t matter if it’s already in use by a session with a different ID, because the ID/token pair is unique. (Removing that constraint gets rid of an in-principle-but-rare locking problem.)