Skip to content

Latest commit

 

History

History
75 lines (55 loc) · 2.02 KB

README.md

File metadata and controls

75 lines (55 loc) · 2.02 KB

CuratorRegisterable

Support password based sign-in by comparing the password to a hashed password. It also provides a generator for creating a sign-in page.

This module assumes you're using Database Authenticatable. In the future it might work with a OAuth 2 only workflow, but that Curator module hasn't been written yet.

Installation

  1. Add curator_registerable to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:curator_registerable, "~> 0.1.0"}]
end
```
  1. Run the install command
```elixir
mix curator_registerable.install
```
  1. Update web/models/user.ex
```elixir
defmodule Auth.User do

  def create_registration_changeset(user, params \\ %{}) do
    user
    |> changeset(params)
    |> password_changeset(params)
  end

  def update_registration_changeset(user, params \\ %{}) do
    user
    |> changeset(params)
  end

end
```
  1. Update web/router.ex
```elixir
scope "/", Auth do
  pipe_through [:browser]

  resources "/registrations", RegistrationController, only: [:new, :create]
  get "/registrations/edit", RegistrationController, :edit
  get "/registrations", RegistrationController, :show
  put "/registrations", RegistrationController, :update, as: nil
  patch "/registrations", RegistrationController, :update
  delete "/registrations", RegistrationController, :delete

  ...
end
```
  1. Update lib/<otp_app>/curator_hooks.ex
```elixir
def after_extension(conn, :registration, user) do
  conn
  |> put_flash(:info, "Account was successfully created.")
  # |> Send a confirmation email?
  # |> Do other bookkeeping?
  |> redirect(to: "/")
end
```
  1. (Optionally) Add a link to `web/templates/session/new.html.eex'
```elixir
<%= button "Sign Up", to: registration_path(@conn, :new), class: "btn btn-secondary navbar-btn", method: :get %>
```