-
Notifications
You must be signed in to change notification settings - Fork 0
users (server side)
The users namespace defines two record types, user and session, where users have names, passwords and private data and sessions have client ids and names. Users are accessible by name; sessions are accessible by both name and client id. Client ids identify web socket channels, so messages are sent and received via the channel identified by the client id. Additionally, when a web socket is opened, a unique client id is created and when it is closed notice is given for that client id.
Logging in is the same as creating a session, which connects a user to a client id. Logging out, conversely, means that the session is dropped.
Client ids and users have a one-to-one relationship. So logging in via a different web socket will close the old session as well as creating a new one.
When the login status of a client changes, notice is sent to all users. And when a login attempt fails, notice of the failure is sent as well, but only to the user attempting to log in.
The server-side api for users is just two functions:
- get-session-user, which takes a client id and returns a user or nil, and
- broadcast!, which takes a message id and message data and sends the message to all logged in users. This is in contrast to tiples.core/broadcast!, which sends a message to all clients.
In addition, the users, sessions and common-data atoms can also be accessed.
There can be different types of clients with different capabilities. For example, only some types of client support chat.
Capabilities are derived from the keys of each user's private data. The response to a successful login contains the user's private data and the common data associated with those keys.
- :users/login - Validate the given user/password, create a session.
- :users/logout - Drop the session associated with the web socket.
- :chsk/uidport-close - Drop the session associated with the closed web socket.
- :users/logged-in - On login, this message returns the common and private user data appropriate for the capabilities of the client. On logout, nil is returned.
- :users/logged-in-notice - When a session is created or dropped, this message holds the capabilities or nil, respectively.