Aura.Users (Aura v0.9.3)

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

Functions

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

@spec create_user(
  username :: Aura.Common.username(),
  password :: String.t(),
  emails :: [Aura.Common.email()],
  opts :: list()
) :: {: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

๐Ÿท๏ธ Params

โคต๏ธ Returns

โœ… On Success

  {:ok, %HexUser{...}}

โŒ On Failure

  {:error, (some error)}

๐Ÿ’ป 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)

๐Ÿ‘ฉโ€๐Ÿ’ป API Details

MethodPathControllerAction
POST/usersUserController:create

get_current_user(opts \\ [])

@spec get_current_user(opts :: list()) ::
  {:ok, Aura.Model.HexUser.t()} | {:error, any()}

Grabs the hex user representing the currently authenticated user

๐Ÿท๏ธ Params

  • opts :: option parameters used to modify requests

โคต๏ธ Returns

โœ… On Success

  {:ok, %HexUser{...}}

โŒ On Failure

  {:error, (some error)}

๐Ÿ’ป Examples

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

๐Ÿ‘ฉโ€๐Ÿ’ป API Details

MethodPathControllerAction
GET/users/meUserController:me

get_user(username_or_email, opts \\ [])

@spec get_user(
  username_or_email :: Aura.Common.username() | Aura.Common.email(),
  opts :: list()
) :: {:ok, Aura.Model.HexUser.t()} | {:error, any()}

Grabs a hex user, given their username_or_email

๐Ÿท๏ธ Params

โคต๏ธ Returns

โœ… On Success

  {:ok, %HexUser{...}}

โŒ On Failure

  {:error, (some error)}

๐Ÿ’ป Examples

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

๐Ÿ‘ฉโ€๐Ÿ’ป API Details

MethodPathControllerAction
GET/users/:username_or_emailUserController:show

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

๐Ÿท๏ธ Params

โคต๏ธ Returns

โœ… On Success

  :ok

โŒ On Failure

  {:error, (some error)}

๐Ÿ’ป 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

๐Ÿ‘ฉโ€๐Ÿ’ป API Details

MethodPathControllerAction
GET/users/:username_or_email/resetUserController:reset

stream_audit_logs(opts \\ [])

@spec stream_audit_logs(opts :: list()) :: Enumerable.t()

Streams audit logs, scoped to the current authenticated user

๐Ÿท๏ธ Params

  • opts.page :: start from this page number

โคต๏ธ Returns

โœ… On Success

  Stream.resource/3

๐Ÿ’ป 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

๐Ÿ‘ฉโ€๐Ÿ’ป API Details

MethodPathControllerAction
GET/users/me/audit-logsUserController:audit_logs