Skip to content

Commit

Permalink
update tests due to removal of auth #65
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Sep 30, 2020
1 parent 4a05c53 commit ff16a57
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 648 deletions.
146 changes: 0 additions & 146 deletions lib/app/ctx/person.ex

This file was deleted.

42 changes: 0 additions & 42 deletions lib/app_web/controllers/google_auth_controller.ex

This file was deleted.

86 changes: 39 additions & 47 deletions lib/app_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
@@ -1,56 +1,48 @@
defmodule AppWeb.PageController do
use AppWeb, :controller
alias App.Ctx.Person
alias App.Ctx

# auth_controller assign current_person on each request
# when the person is loggedin, otherwise the value doesn't exists or is nil
def index(%{assigns: %{current_person: person}} = conn, _params)
when not is_nil(person) do
redirect(conn, to: Routes.person_path(conn, :info))
end
alias App.Person

def index(conn, _params) do
changeset = Person.changeset_registration(%Person{}, %{})
changeset = Person.changeset(%Person{}, %{})

render(conn, "index.html", changeset: changeset)
end

def register(conn, %{"person" => person_params}) do
person = Ctx.get_person_by_email(person_params["email"])

# create new person
# Login person if password ok
if is_nil(person) do
case Ctx.register_person(person_params) do
{:ok, person} ->
create_basic_session(conn, person)

{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "index.html", changeset: changeset)
end
else
login(conn, person, person_params)
end
end

# verify provided password
# create Phx session
# and redirect to correct page:
# user info page if password ok or index page if it doesn't match
defp login(conn, person, person_params) do
if Argon2.verify_pass(person_params["password"], person.password_hash) do
create_basic_session(conn, person)
else
redirect(conn, to: Routes.page_path(conn, :index))
end
end

# Insert a new basic session in Postgres
defp create_basic_session(conn, person) do
App.Ctx.create_basic_session(person, %{})

AppWeb.Auth.login(conn, person)
|> redirect(to: Routes.person_path(conn, :info))
end
# def register(conn, %{"person" => person_params}) do
# person = Ctx.get_person_by_email(person_params["email"])

# # create new person
# # Login person if password ok
# if is_nil(person) do
# case Ctx.register_person(person_params) do
# {:ok, person} ->
# create_basic_session(conn, person)

# {:error, %Ecto.Changeset{} = changeset} ->
# render(conn, "index.html", changeset: changeset)
# end
# else
# login(conn, person, person_params)
# end
# end

# # verify provided password
# # create Phx session
# # and redirect to correct page:
# # user info page if password ok or index page if it doesn't match
# defp login(conn, person, person_params) do
# if Argon2.verify_pass(person_params["password"], person.password_hash) do
# create_basic_session(conn, person)
# else
# redirect(conn, to: Routes.page_path(conn, :index))
# end
# end

# # Insert a new basic session in Postgres
# defp create_basic_session(conn, person) do
# App.Ctx.create_basic_session(person, %{})

# AppWeb.Auth.login(conn, person)
# |> redirect(to: Routes.person_path(conn, :info))
# end
end
72 changes: 0 additions & 72 deletions lib/app_web/controllers/person_controller.ex

This file was deleted.

7 changes: 4 additions & 3 deletions lib/app_web/router.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
defmodule AppWeb.Router do
use AppWeb, :router
import AppWeb.Auth
# import AppWeb.Auth

pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug AppWeb.Auth
# plug AppWeb.Auth
end

pipeline :api do
Expand All @@ -31,7 +31,8 @@ defmodule AppWeb.Router do
get "/auth/google/callback", GoogleAuthController, :index
end

pipeline :auth, do: plug(AuthPlug, %{auth_url: "https://dwylauth.herokuapp.com"})
pipeline :auth,
do: plug(AuthPlug, %{auth_url: "https://dwylauth.herokuapp.com"})

scope "/", AppWeb do
pipe_through [:browser, :auth]
Expand Down
Loading

0 comments on commit ff16a57

Please sign in to comment.