EpochtalkServer.Session (epochtalk_server v0.1.0)

Manages User sessions in Redis. Used by Auth related User actions.

Link to this section Summary

Functions

Create session performs the following actions

Deletes a specific User session

Deletes every session instance for the specified User

Gets all sessions for a specific User

Link to this section Functions

Link to this function

create(user, remember_me, conn)

@spec create(
  user :: EpochtalkServer.Models.User.t(),
  remember_me :: boolean(),
  conn :: Plug.Conn.t()
) ::
  {:ok, user :: EpochtalkServer.Models.User.t(), encoded_token :: String.t(),
   conn :: Plug.Conn.t()}

Create session performs the following actions:

  • Sets user's session id, timestamp, ttl
  • Logs User in with Guardian to get token
  • Saves User session info to redis (avatar, roles, moderating, ban info, etc)
  • returns {:ok, user, token and conn}
  • TODO(boka): Handle expiration of redis sessions (this is handled in guardian but not redis)
Link to this function

delete_session(user, session_id)

@spec delete_session(
  user :: EpochtalkServer.Models.User.t(),
  session_id :: String.t()
) ::
  {:ok, user :: EpochtalkServer.Models.User.t()}
  | {:error, atom() | Redix.Error.t() | Redix.ConnectionError.t()}

Deletes a specific User session

Link to this function

delete_sessions(user)

@spec delete_sessions(user :: EpochtalkServer.Models.User.t()) :: :ok

Deletes every session instance for the specified User

Link to this function

get_sessions(user)

@spec get_sessions(user :: EpochtalkServer.Models.User.t()) ::
  {:ok, user :: EpochtalkServer.Models.User.t(), sessions :: [String.t()]}
  | {:error, atom() | Redix.Error.t() | Redix.ConnectionError.t()}

Gets all sessions for a specific User