Refactor User.confirm/1, add more tests
This commit is contained in:
parent
9ddc292ca8
commit
6ebec50df6
3 changed files with 89 additions and 5 deletions
|
|
@ -1598,6 +1598,22 @@ defmodule Pleroma.User do
|
|||
end
|
||||
end
|
||||
|
||||
def confirm(users) when is_list(users) do
|
||||
Repo.transaction(fn ->
|
||||
Enum.map(users, fn user ->
|
||||
with {:ok, user} <- confirm(user), do: user
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
def confirm(%User{} = user) do
|
||||
with chg <- confirmation_changeset(user, need_confirmation: false),
|
||||
{:ok, user} <- update_and_set_cache(chg) do
|
||||
post_register_action(user)
|
||||
{:ok, user}
|
||||
end
|
||||
end
|
||||
|
||||
def update_notification_settings(%User{} = user, settings) do
|
||||
user
|
||||
|> cast(%{notification_settings: settings}, [])
|
||||
|
|
|
|||
|
|
@ -31,11 +31,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
|
||||
with %User{} = user <- User.get_cached_by_id(uid),
|
||||
true <- user.local and user.confirmation_pending and user.confirmation_token == token,
|
||||
{:ok, _} <-
|
||||
user
|
||||
|> User.confirmation_changeset(need_confirmation: false)
|
||||
|> User.update_and_set_cache() do
|
||||
User.post_register_action(user)
|
||||
{:ok, _} <- User.confirm(user) do
|
||||
redirect(conn, to: "/")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue