formatting

This commit is contained in:
Henry Jameson 2018-06-12 15:01:40 +03:00
parent f42ffbe9a8
commit 9c1cf1befb
2 changed files with 9 additions and 5 deletions

View File

@ -143,7 +143,7 @@ def register_user(params) do
end end
cond do cond do
@registrations_open || !is_nil(token) && !token.used -> @registrations_open || (!is_nil(token) && !token.used) ->
changeset = User.register_changeset(%User{}, params) changeset = User.register_changeset(%User{}, params)
with {:ok, user} <- Repo.insert(changeset) do with {:ok, user} <- Repo.insert(changeset) do
@ -155,11 +155,14 @@ def register_user(params) do
Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
|> Jason.encode!() |> Jason.encode!()
{:error, %{error: errors}} {:error, %{error: errors}}
end end
!@registrations_open && is_nil(token) -> {:error, "Invalid token"} !@registrations_open && is_nil(token) ->
!@registrations_open && token.used -> {:error, "Expired token"} {:error, "Invalid token"}
!@registrations_open && token.used ->
{:error, "Expired token"}
end end
end end

View File

@ -266,8 +266,9 @@ test "it registers a new user via invite token and returns the user." do
token = Repo.get_by(UserInviteToken, token: token.token) token = Repo.get_by(UserInviteToken, token: token.token)
assert token.used == true assert token.used == true
assert UserView.render("show.json", %{user: user}) == assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user}) UserView.render("show.json", %{user: fetched_user})
end end
@moduletag skip: "needs 'registrations_open: false' in config" @moduletag skip: "needs 'registrations_open: false' in config"