ExPilot.Web.Auth (ExPilot v0.1.1)

Copy Markdown View Source

Who a browser player is: login against the server's Drafter.Accounts, the signed token a page hands its socket, and the sound levels kept in the account.

The accounts server is ExPilot.Accounts, as ExPilot.Server.start/1 names it.

Summary

Functions

What Cauldron2D.Net.Socket asks of the connect params: the token's pilot and their sound levels for the kind of client.

The kind of client a connect or join param names: "touch" is :touch, anything else :web.

The account's sound levels for a kind of client (:web unless given), %{sfx: level, music: level}, with the defaults where unset.

Check a name and password; {:ok, username} in the account's spelling.

The name the account plays under: its nickname, else its username.

The on_mount hook of the player's pages: the session's username, or back to the login.

Keep the account's sound levels for a kind of client, alongside whatever else that kind's settings hold.

Keep the account's nickname; blank means none. {:error, :taken} when another account plays under it.

Create an account; {:ok, username} or {:error, reason} as Drafter.Accounts.register/4 gives it.

A token naming username, good for a day.

The username a token names.

Functions

connect(params)

@spec connect(map()) :: {:ok, %{username: String.t(), settings: map()}} | :error

What Cauldron2D.Net.Socket asks of the connect params: the token's pilot and their sound levels for the kind of client.

kind(arg1)

@spec kind(term()) :: :web | :touch

The kind of client a connect or join param names: "touch" is :touch, anything else :web.

levels(username, kind \\ :web)

@spec levels(String.t(), atom()) :: %{sfx: float(), music: float()}

The account's sound levels for a kind of client (:web unless given), %{sfx: level, music: level}, with the defaults where unset.

login(username, password)

@spec login(String.t(), String.t()) :: {:ok, String.t()} | :error

Check a name and password; {:ok, username} in the account's spelling.

nickname(username)

@spec nickname(String.t()) :: String.t()

The name the account plays under: its nickname, else its username.

on_mount(atom, params, session, socket)

The on_mount hook of the player's pages: the session's username, or back to the login.

put_levels(username, sfx, music, kind \\ :web)

@spec put_levels(String.t(), number(), number(), atom()) :: :ok | {:error, term()}

Keep the account's sound levels for a kind of client, alongside whatever else that kind's settings hold.

put_nickname(username, nickname)

@spec put_nickname(String.t(), String.t()) :: :ok | {:error, :taken | term()}

Keep the account's nickname; blank means none. {:error, :taken} when another account plays under it.

register(username, password)

@spec register(String.t(), String.t()) :: {:ok, String.t()} | {:error, term()}

Create an account; {:ok, username} or {:error, reason} as Drafter.Accounts.register/4 gives it.

token(username)

@spec token(String.t()) :: String.t()

A token naming username, good for a day.

verify(token)

@spec verify(String.t()) :: {:ok, String.t()} | :error

The username a token names.