Skip to content

Commit

Permalink
Add signup form
Browse files Browse the repository at this point in the history
  • Loading branch information
hjarrell committed Dec 22, 2019
1 parent 57be474 commit b13b080
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
24 changes: 24 additions & 0 deletions lib/ask_a_gator_web/controllers/user_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule AskAGatorWeb.UserController do
use AskAGatorWeb, :controller

alias AskAGator.Accounts

def sign_up(conn, _params) do
render(conn, "sign_up.html")
end

def create(conn, %{"user" => user_params}) do
case Accounts.create_user(user_params) do
{:ok, new_user} ->
conn
|> put_flash(:info, "Account created sucessfully!")
|> put_session(:current_user, new_user.id)
|> configure_session(renew: true)
|> redirect(to: "/")
{:error, %Ecto.Changeset{} = _changeset} ->
conn
|> put_flash(:error, "Error creating account")
|> redirect(to: Routes.user_path(conn, :sign_up))
end
end
end
2 changes: 2 additions & 0 deletions lib/ask_a_gator_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ defmodule AskAGatorWeb.Router do
get "/login", SessionController, :login
post "/login", SessionController, :create
get "/logout", SessionController, :logout
get "/sign_up", UserController, :sign_up
post "/sign_up", UserController, :create
end

# Other scopes may use custom stacks.
Expand Down
11 changes: 0 additions & 11 deletions lib/ask_a_gator_web/templates/session/sign_up.html.eex

This file was deleted.

36 changes: 36 additions & 0 deletions lib/ask_a_gator_web/templates/user/sign_up.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<%= form_for @conn, Routes.user_path(@conn, :create), [method: :post, as: :user], fn f -> %>

<div class="form-group">
<label for="form-first">First Name:</label>
<%= text_input f, :first_name, placeholder: "First Name", id: "form-first", class: "form-control" %>
</div>

<div class="form-group">
<label for="form-middle">Middle Name:</label>
<%= text_input f, :middle_name, placeholder: "Middle Name", id: "form-middle", class: "form-control" %>
</div>

<div class="form-group">
<label for="form-last">Last Name:</label>
<%= text_input f, :last_name, placeholder: "Last Name", id: "form-last", class: "form-control" %>
</div>

<div class="form-group">
<label for="form-email">Email Address:</label>
<%= text_input f, :email, placeholder: "Email", id: "form-email", class: "form-control" %>
</div>

<div class="form-group">
<label for="form-password">Password:</label>
<%= password_input f, :password, placeholder: "Password", id: "form-password", class: "form-control" %>
</div>

<div class="form-group">
<label for="form-password-conf">Re-enter Password:</label>
<%= password_input f, :password_confirmation, placeholder: "Re-enter Password", id: "form-password-conf", class: "form-control" %>
</div>

<div class="form-group">
<%= submit "Sign Up", class: "btn btn-info" %>
</div>
<% end %>
3 changes: 3 additions & 0 deletions lib/ask_a_gator_web/views/user_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule AskAGatorWeb.UserView do
use AskAGatorWeb, :view
end

0 comments on commit b13b080

Please sign in to comment.