Aura.Users (Aura v1.0.1)
View SourceService module for interacting with Hex users
Resources
- Hex
- Contact the maintainer (he's happy to help!)
Summary
Functions
Requests a hex user be created
Grabs the hex user representing the currently authenticated user
Grabs a hex user, given their username_or_email
Resets a specified user's password
Streams audit logs, scoped to the current authenticated user
Types
@type user_opts() :: [{:repo_url, Aura.Common.repo_url()}]
Functions
@spec create_user( username :: Aura.Common.username(), password :: String.t(), emails :: [Aura.Common.email()], opts :: user_opts() ) :: {:ok, Aura.Model.HexUser.t()} | {:error, any()}
Requests a hex user be created
📄 Terms of Service
If your service is using hex.pm as a backend, you must have users to agree to Hex's Terms of Service
Parameters
Parameter | Description |
---|---|
username | Aura.Common.username/0 |
password | User's password |
emails | [Aura.Common.email/0 ] |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
POST | /users | UserController | :create |
Examples
iex> Application.delete_env(:aura, :api_key)
iex> username = Faker.Internet.user_name()
iex> password = Faker.Internet.slug()
iex> emails = [Faker.Internet.email()]
iex> alias Aura.Users
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> {:ok, _user} = Users.create_user(username, password, emails, opts)
@spec get_current_user(opts :: user_opts()) :: {:ok, Aura.Model.HexUser.t()} | {:error, any()}
Grabs the hex user representing the currently authenticated user
Parameters
Parameter | Description |
---|---|
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /users/me | UserController | :me |
Examples
iex> alias Aura.Users
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> {:ok, _user} = Users.get_current_user(opts)
@spec get_user( username_or_email :: Aura.Common.username() | Aura.Common.email(), opts :: user_opts() ) :: {:ok, Aura.Model.HexUser.t()} | {:error, any()}
Grabs a hex user, given their username_or_email
Parameters
Parameter | Description |
---|---|
username_or_email | Aura.Common.username/0 or Aura.Common.email/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /users/:username_or_email | UserController | :show |
Examples
iex> alias Aura.Users
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> {:ok, _user} = Users.get_user("eric@example.com", opts)
@spec reset_user_password( username_or_email :: Aura.Common.username() | Aura.Common.email(), opts :: list() ) :: :ok | {:error, any()}
Resets a specified user's password
Parameters
Parameter | Description |
---|---|
username_or_email | Aura.Common.username/0 or Aura.Common.email/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /users/:username_or_email /reset | UserController | :reset |
Examples
iex> alias Aura.Users
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> {:ok, user} = Users.get_current_user(opts)
iex> Users.reset_user_password(user.email, opts)
:ok
@spec stream_audit_logs(opts :: list()) :: Enumerable.t()
Streams audit logs, scoped to the current authenticated user
Note that the page size is fixed by the API to be 100 per page.
Parameters
Parameter | Description |
---|---|
opts[:repo_url] | Aura.Common.repo_url/0 |
opts[:page] | Aura.Common.start_page/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /users/me/audit-logs | UserController | :audit_logs |
Examples
iex> alias Aura.Users
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> audit_logs = Users.stream_audit_logs(opts)
iex> Enum.empty?(audit_logs)
false