AccessPass v1.1.0 AccessPassBehavior behaviour

This Module provides you the ability to override AccessPass behavior Create a new module in your application and impliment any of the callbacks below to override default behavior. EX.

  defmodule MyApplication do
      use AccessPassBehavior
      # all of your overrides here
  end
  # in your config file
  config :access_pass, overrides_module: MyApplication

Link to this section Summary

Callbacks

This function is called after a user has confirmed their email address and must return {:ok}

This function is called after a user registration insert happens and must return the same object that is passed in.

This function is called after_login and should return a map that will be stored in the users token

This is used to override unauth errors This function should call plug send_resp and halt the plug. You can set your own status code / return override here.

This function should return text:html for the confirmation_email email, look at Email Templating section in Crash Course section of the docs for more info.

This function is called before registration insert, you can add additional data to the changeset and must return the altered changeset

This function should return text:html for the forgot_username email, look at Email Templating section in Crash Course section of the docs for more info.

This function is used to change the default user_id generation. It must return the passed in changeset and a string used for user id in a tuple.

This function is called as a replacement to Repo.insert and must run the insert op for the given changeset. It also passes the origional register params unaltered in case you want to add additional fields. It should return the return of Repo.insert

This function is passed a map of tokens and the user struct. What is returned will be forwarded along and returned by register/login

This function should return text:html for the password reset email, look at Email Templating section in Crash Course section of the docs for more info.

Link to this section Callbacks

Link to this callback

after_confirm(%AccessPass.Users{})
after_confirm(%AccessPass.Users{
  __meta__: term(),
  confirm_id: term(),
  confirmed: term(),
  email: term(),
  inserted_at: term(),
  meta: term(),
  password: term(),
  password_confirm: term(),
  password_hash: term(),
  password_reset_expire: term(),
  password_reset_key: term(),
  successful_login_attempts: term(),
  updated_at: term(),
  user_id: term(),
  username: term()
}) :: {:ok}

This function is called after a user has confirmed their email address and must return {:ok}

Returns {:ok}.

Link to this callback

after_insert(%AccessPass.Users{})
after_insert(%AccessPass.Users{
  __meta__: term(),
  confirm_id: term(),
  confirmed: term(),
  email: term(),
  inserted_at: term(),
  meta: term(),
  password: term(),
  password_confirm: term(),
  password_hash: term(),
  password_reset_expire: term(),
  password_reset_key: term(),
  successful_login_attempts: term(),
  updated_at: term(),
  user_id: term(),
  username: term()
}) :: %AccessPass.Users{
  __meta__: term(),
  confirm_id: term(),
  confirmed: term(),
  email: term(),
  inserted_at: term(),
  meta: term(),
  password: term(),
  password_confirm: term(),
  password_hash: term(),
  password_reset_expire: term(),
  password_reset_key: term(),
  successful_login_attempts: term(),
  updated_at: term(),
  user_id: term(),
  username: term()
}

This function is called after a user registration insert happens and must return the same object that is passed in.

Returns %AccessPass.Users{} that was passed in

Link to this callback

after_login(%AccessPass.Users{})
after_login(%AccessPass.Users{
  __meta__: term(),
  confirm_id: term(),
  confirmed: term(),
  email: term(),
  inserted_at: term(),
  meta: term(),
  password: term(),
  password_confirm: term(),
  password_hash: term(),
  password_reset_expire: term(),
  password_reset_key: term(),
  successful_login_attempts: term(),
  updated_at: term(),
  user_id: term(),
  username: term()
}) :: {:ok, map()}

This function is called after_login and should return a map that will be stored in the users token

Returns {:ok,%{custom: true}}

Link to this callback

auth_error(%Plug.Conn{})
auth_error(%Plug.Conn{
  adapter: term(),
  assigns: term(),
  before_send: term(),
  body_params: term(),
  cookies: term(),
  halted: term(),
  host: term(),
  method: term(),
  owner: term(),
  params: term(),
  path_info: term(),
  path_params: term(),
  port: term(),
  private: term(),
  query_params: term(),
  query_string: term(),
  remote_ip: term(),
  req_cookies: term(),
  req_headers: term(),
  request_path: term(),
  resp_body: term(),
  resp_cookies: term(),
  resp_headers: term(),
  scheme: term(),
  script_name: term(),
  secret_key_base: term(),
  state: term(),
  status: term()
}) :: %Plug.Conn{
  adapter: term(),
  assigns: term(),
  before_send: term(),
  body_params: term(),
  cookies: term(),
  halted: term(),
  host: term(),
  method: term(),
  owner: term(),
  params: term(),
  path_info: term(),
  path_params: term(),
  port: term(),
  private: term(),
  query_params: term(),
  query_string: term(),
  remote_ip: term(),
  req_cookies: term(),
  req_headers: term(),
  request_path: term(),
  resp_body: term(),
  resp_cookies: term(),
  resp_headers: term(),
  scheme: term(),
  script_name: term(),
  secret_key_base: term(),
  state: term(),
  status: term()
}
auth_error(%Plug.Conn{
  adapter: term(),
  assigns: term(),
  before_send: term(),
  body_params: term(),
  cookies: term(),
  halted: term(),
  host: term(),
  method: term(),
  owner: term(),
  params: term(),
  path_info: term(),
  path_params: term(),
  port: term(),
  private: term(),
  query_params: term(),
  query_string: term(),
  remote_ip: term(),
  req_cookies: term(),
  req_headers: term(),
  request_path: term(),
  resp_body: term(),
  resp_cookies: term(),
  resp_headers: term(),
  scheme: term(),
  script_name: term(),
  secret_key_base: term(),
  state: term(),
  status: term()
}) :: %Plug.Conn{
  adapter: term(),
  assigns: term(),
  before_send: term(),
  body_params: term(),
  cookies: term(),
  halted: term(),
  host: term(),
  method: term(),
  owner: term(),
  params: term(),
  path_info: term(),
  path_params: term(),
  port: term(),
  private: term(),
  query_params: term(),
  query_string: term(),
  remote_ip: term(),
  req_cookies: term(),
  req_headers: term(),
  request_path: term(),
  resp_body: term(),
  resp_cookies: term(),
  resp_headers: term(),
  scheme: term(),
  script_name: term(),
  secret_key_base: term(),
  state: term(),
  status: term()
}

This is used to override unauth errors This function should call plug send_resp and halt the plug. You can set your own status code / return override here.

Returns conn.

Link to this callback

confirmation_email()
confirmation_email() :: String.t()

This function should return text:html for the confirmation_email email, look at Email Templating section in Crash Course section of the docs for more info.

Returns <p>Email text is returned</p>.

Link to this callback

custom_user_changes(%Ecto.Changeset{})
custom_user_changes(%Ecto.Changeset{
  action: term(),
  changes: term(),
  constraints: term(),
  data: term(),
  empty_values: term(),
  errors: term(),
  filters: term(),
  params: term(),
  prepare: term(),
  repo: term(),
  repo_opts: term(),
  required: term(),
  types: term(),
  valid?: term(),
  validations: term()
}) :: %Ecto.Changeset{
  action: term(),
  changes: term(),
  constraints: term(),
  data: term(),
  empty_values: term(),
  errors: term(),
  filters: term(),
  params: term(),
  prepare: term(),
  repo: term(),
  repo_opts: term(),
  required: term(),
  types: term(),
  valid?: term(),
  validations: term()
}

This function is called before registration insert, you can add additional data to the changeset and must return the altered changeset

Returns altered %Ecto.Changeset{} struct

Link to this callback

forgot_username()
forgot_username() :: String.t()

This function should return text:html for the forgot_username email, look at Email Templating section in Crash Course section of the docs for more info.

Returns <p>Email text is returned</p>.

Link to this callback

gen_user_id(%Ecto.Changeset{})
gen_user_id(%Ecto.Changeset{
  action: term(),
  changes: term(),
  constraints: term(),
  data: term(),
  empty_values: term(),
  errors: term(),
  filters: term(),
  params: term(),
  prepare: term(),
  repo: term(),
  repo_opts: term(),
  required: term(),
  types: term(),
  valid?: term(),
  validations: term()
}) ::
  {%Ecto.Changeset{
     action: term(),
     changes: term(),
     constraints: term(),
     data: term(),
     empty_values: term(),
     errors: term(),
     filters: term(),
     params: term(),
     prepare: term(),
     repo: term(),
     repo_opts: term(),
     required: term(),
     types: term(),
     valid?: term(),
     validations: term()
   }, String.t()}

This function is used to change the default user_id generation. It must return the passed in changeset and a string used for user id in a tuple.

Returns {%Ecto.Changeset{}, String.t()}.

Link to this callback

insert_override(%Ecto.Changeset{}, map)
insert_override(
  %Ecto.Changeset{
    action: term(),
    changes: term(),
    constraints: term(),
    data: term(),
    empty_values: term(),
    errors: term(),
    filters: term(),
    params: term(),
    prepare: term(),
    repo: term(),
    repo_opts: term(),
    required: term(),
    types: term(),
    valid?: term(),
    validations: term()
  },
  map()
) ::
  {:ok,
   %AccessPass.Users{
     __meta__: term(),
     confirm_id: term(),
     confirmed: term(),
     email: term(),
     inserted_at: term(),
     meta: term(),
     password: term(),
     password_confirm: term(),
     password_hash: term(),
     password_reset_expire: term(),
     password_reset_key: term(),
     successful_login_attempts: term(),
     updated_at: term(),
     user_id: term(),
     username: term()
   }}
  | {:error,
     %AccessPass.Users{
       __meta__: term(),
       confirm_id: term(),
       confirmed: term(),
       email: term(),
       inserted_at: term(),
       meta: term(),
       password: term(),
       password_confirm: term(),
       password_hash: term(),
       password_reset_expire: term(),
       password_reset_key: term(),
       successful_login_attempts: term(),
       updated_at: term(),
       user_id: term(),
       username: term()
     }}

This function is called as a replacement to Repo.insert and must run the insert op for the given changeset. It also passes the origional register params unaltered in case you want to add additional fields. It should return the return of Repo.insert

Returns {:ok, %AccessPass.Users{}} | {:error, %AccessPass.Users{}}

Link to this callback

login_return(map, %AccessPass.Users{})
login_return(map(), %AccessPass.Users{
  __meta__: term(),
  confirm_id: term(),
  confirmed: term(),
  email: term(),
  inserted_at: term(),
  meta: term(),
  password: term(),
  password_confirm: term(),
  password_hash: term(),
  password_reset_expire: term(),
  password_reset_key: term(),
  successful_login_attempts: term(),
  updated_at: term(),
  user_id: term(),
  username: term()
}) :: term()

This function is passed a map of tokens and the user struct. What is returned will be forwarded along and returned by register/login

Returns %{ "type": "basic", "refresh_token": "OTc1Nzk5MTQtN2Y4Ny00MDI1LTk1YjgtNzA3OWNmN2Q3M2Iy", "refresh_expire_in": 0, "access_token": "ZDU1YjM2NGQtNTgyMi00OTRmLTgxYzItNTc5M2JiODNiYzAz", "access_expire_in": 300, "extra_param": "this is extra" }.

Link to this callback

password_reset()
password_reset() :: String.t()

This function should return text:html for the password reset email, look at Email Templating section in Crash Course section of the docs for more info.

Returns <p>Email text is returned</p>.