-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tests due to removal of auth #65
- Loading branch information
Showing
12 changed files
with
229 additions
and
648 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.