Last active
September 6, 2015 20:32
-
-
Save stevegraham/155f0966968796bda42e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Teller.Web.SignupForm do | |
use Form, | |
email: :email, | |
password: :password, | |
password_confirmation: :password | |
validates :email, presence: true | |
validates :password, length: [min: 8], confirmation: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Teller.Web.UserController do | |
use Teller.Web, :controller | |
alias Teller.User | |
plug :scrub_params, "user" when action in [:create, :update] | |
# ... snip | |
def create(conn, %{"user" => user_params}) do | |
case Teller.Web.SignupForm.save(%User{}, user_params) do | |
{:ok, _} -> | |
conn | |
|> put_flash(:info, "User created successfully.") | |
|> redirect(to: user_path(conn, :show)) | |
{:error, form} -> | |
render(conn, "new.html", form: form) | |
end | |
end | |
# ... snip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment