Sovite.Core.Repo.Tables.Users (sovite v0.2.0)

Copy Markdown View Source

Users stored in Sovite's database (Sovite.Core.Repo), and a Sovite.SASL.Backend that authenticates against them.

Passwords are stored as Sovite.SASL.Password hashes; new ones are {SCRAM-SHA-256}, so users can log in with PLAIN, LOGIN, and SCRAM-SHA-256. Disabled users cannot log in.

Manage users with sovitectl user. Every function takes the repo reference first; as a backend, pass it as repo: in the options.

Summary

Functions

Creates a user. The password is hashed with Sovite.SASL.Password.hash/1.

Deletes a user and their sender addresses.

Returns the user, or nil.

Lists all users, by name, with their sender addresses.

Removes a sender address from a user.

Returns the sender addresses a user may use (empty for unknown users).

Enables or disables a user.

Functions

add_sender(repo, username, address)

@spec add_sender(Sovite.Core.Repo.t(), String.t(), String.t()) ::
  {:ok, Sovite.Core.Repo.Schemas.SenderLogin.t()}
  | {:error, :not_found | Ecto.Changeset.t()}

Allows a user to send as address, see Sovite.Core.Repo.Schemas.SenderLogin.

create(repo, username, password)

@spec create(Sovite.Core.Repo.t(), String.t(), String.t()) ::
  {:ok, Sovite.Core.Repo.Schemas.User.t()} | {:error, Ecto.Changeset.t()}

Creates a user. The password is hashed with Sovite.SASL.Password.hash/1.

delete(repo, username)

@spec delete(Sovite.Core.Repo.t(), String.t()) :: :ok | {:error, :not_found}

Deletes a user and their sender addresses.

get(repo, username)

Returns the user, or nil.

list(repo)

Lists all users, by name, with their sender addresses.

remove_sender(repo, username, address)

@spec remove_sender(Sovite.Core.Repo.t(), String.t(), String.t()) ::
  :ok | {:error, :not_found}

Removes a sender address from a user.

senders(repo, username)

@spec senders(Sovite.Core.Repo.t(), String.t()) :: [String.t()]

Returns the sender addresses a user may use (empty for unknown users).

set_enabled(repo, username, enabled)

@spec set_enabled(Sovite.Core.Repo.t(), String.t(), boolean()) ::
  {:ok, Sovite.Core.Repo.Schemas.User.t()}
  | {:error, :not_found | Ecto.Changeset.t()}

Enables or disables a user.

set_password(repo, username, password)

@spec set_password(Sovite.Core.Repo.t(), String.t(), String.t()) ::
  {:ok, Sovite.Core.Repo.Schemas.User.t()}
  | {:error, :not_found | Ecto.Changeset.t()}

Sets a new password.