Skip to content

Commit

Permalink
Merge branch 'master' into login-attempt-#67
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed May 18, 2020
2 parents c18b25b + b43475a commit 7cd531f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/auth/person.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ defmodule Auth.Person do
def password_new_changeset(attrs) do
%Person{}
|> cast(attrs, [:email, :password])
|> validate_required([:password])
|> validate_length(:password, min: 8)
end

@doc """
Expand Down
16 changes: 14 additions & 2 deletions lib/auth_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,20 @@ defmodule AuthWeb.AuthController do
def password_create(conn, params) do
p = params["person"]
email = Auth.Person.decrypt_email(p["email"])
person = Auth.Person.upsert_person(%{email: email, password: p["password"]})
redirect_or_render(conn, person, p["state"])
changeset = Auth.Person.password_new_changeset(%{email: email, password: p["password"]})

if changeset.valid? do
person = Auth.Person.upsert_person(%{email: email, password: p["password"]})
redirect_or_render(conn, person, p["state"])
else
conn
|> assign(:action, Routes.auth_path(conn, :password_create))
|> render("password_create.html",
changeset: changeset,
state: p["state"],
email: p["email"]
)
end
end

@doc """
Expand Down
12 changes: 12 additions & 0 deletions test/auth_web/controllers/auth_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ defmodule AuthWeb.AuthControllerTest do
assert html_response(conn, 200) =~ "Welcome"
end

test "password_create/2 display form when password not valid", %{conn: conn} do
params = %{
"person" => %{
"email" => AuthWeb.ApikeyController.encrypt_encode("anabela@mail.com"),
"password" => "short"
}
}

conn = post(conn, "/auth/password/create", params)
assert html_response(conn, 200) =~ "Password"
end

test "verify_email/2 verify an email address", %{conn: conn} do
person =
%{email: "anabela@mail.com", auth_provider: "email"}
Expand Down

0 comments on commit 7cd531f

Please sign in to comment.