Raxol.Accounts (Raxol v0.4.0)

View Source

The Accounts context. Manages user accounts and registration. (Currently uses an in-memory Agent for storage)

Summary

Functions

Authenticates a user by email and password.

Returns a specification to start this module under a supervisor.

Retrieves the full user map by user ID. Note: Inefficient O(N) scan of the agent state.

Returns the list of registered users.

Registers a new user.

Updates a user's password after verifying the current password. Uses user_id to find the user.

Functions

authenticate_user(email, password)

@spec authenticate_user(String.t(), String.t()) ::
  {:ok, map()} | {:error, :invalid_credentials}

Authenticates a user by email and password.

Currently checks against plaintext passwords stored in the agent. In a real app, this should use password hashing.

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_user(user_id)

@spec get_user(String.t()) :: map() | nil

Retrieves the full user map by user ID. Note: Inefficient O(N) scan of the agent state.

list_users()

Returns the list of registered users.

register_user(attrs)

@spec register_user(map()) :: {:ok, map()} | {:error, map()}

Registers a new user.

Examples

iex> register_user(%{email: "user@example.com", password: "password"})
{:ok, %{id: ..., email: "user@example.com"}}

iex> register_user(%{email: "user@example.com", password: "password"})
{:error, %{email: "has already been taken"}}

start_link(opts)

update_password(user_id, current_password, new_password)

@spec update_password(String.t(), String.t(), String.t()) ::
  :ok | {:error, atom() | map()}

Updates a user's password after verifying the current password. Uses user_id to find the user.