Aura.Users (Aura v1.0.1)

View Source

Service module for interacting with Hex users

Resources

Summary

Functions

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

user_opts()

@type user_opts() :: [{:repo_url, Aura.Common.repo_url()}]

Functions

create_user(username, password, emails, opts \\ [])

@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

ParameterDescription
usernameAura.Common.username/0
passwordUser's password
emails[Aura.Common.email/0]
opts[:repo_url]Aura.Common.repo_url/0

API Details

MethodPathControllerAction
POST/usersUserController: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)

get_current_user(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

ParameterDescription
opts[:repo_url]Aura.Common.repo_url/0

API Details

MethodPathControllerAction
GET/users/meUserController:me

Examples

iex> alias Aura.Users
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> {:ok, _user} =  Users.get_current_user(opts)

get_user(username_or_email, 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

ParameterDescription
username_or_emailAura.Common.username/0 or Aura.Common.email/0
opts[:repo_url]Aura.Common.repo_url/0

API Details

MethodPathControllerAction
GET/users/:username_or_emailUserController:show

Examples

iex> alias Aura.Users
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> {:ok, _user} =  Users.get_user("eric@example.com", opts)

reset_user_password(username_or_email, 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

ParameterDescription
username_or_emailAura.Common.username/0 or Aura.Common.email/0
opts[:repo_url]Aura.Common.repo_url/0

API Details

MethodPathControllerAction
GET/users/:username_or_email/resetUserController: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

stream_audit_logs(opts \\ [])

@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

ParameterDescription
opts[:repo_url]Aura.Common.repo_url/0
opts[:page]Aura.Common.start_page/0

API Details

MethodPathControllerAction
GET/users/me/audit-logsUserController: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