[#114] Added UserInviteToken creation, adjusted invitation email link to include it.

This commit is contained in:
Ivan Tashkinov 2018-12-13 17:58:40 +03:00
parent cc83d7ffe7
commit 3cbf16a5fe
3 changed files with 13 additions and 8 deletions

View file

@ -38,12 +38,12 @@ defmodule Pleroma.UserEmail do
|> html_body(html_body) |> html_body(html_body)
end end
def user_invitation_email(user, to_email, to_name \\ nil) do def user_invitation_email(user, user_invite_token, to_email, to_name \\ nil) do
registration_url = registration_url =
Router.Helpers.redirect_url( Router.Helpers.redirect_url(
Endpoint, Endpoint,
:registration_page, :registration_page,
"" user_invite_token.token
) )
html_body = """ html_body = """

View file

@ -336,8 +336,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
def confirm_email(_conn, _params), do: :noop def confirm_email(_conn, _params), do: :noop
def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do
with true <- Pleroma.Config.get([:instance, :invites_enabled]), with true <-
email <- Pleroma.UserEmail.user_invitation_email(user, email, params["name"]), Pleroma.Config.get([:instance, :invites_enabled]) &&
!Pleroma.Config.get([:instance, :registrations_open]),
{:ok, invite_token} <- Pleroma.UserInviteToken.create_token(),
email <-
Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]),
{:ok, _} <- Pleroma.Mailer.deliver(email) do {:ok, _} <- Pleroma.Mailer.deliver(email) do
json_response(conn, :no_content, "") json_response(conn, :no_content, "")
end end

View file

@ -877,10 +877,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
setup [:valid_user] setup [:valid_user]
setup do setup do
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled]) invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
Pleroma.Config.put([:instance, :registrations_open], false)
Pleroma.Config.put([:instance, :invites_enabled], true) Pleroma.Config.put([:instance, :invites_enabled], true)
on_exit(fn -> on_exit(fn ->
Pleroma.Config.put([:instance, :registrations_open], registrations_open)
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled) Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
:ok :ok
end) end)
@ -888,7 +891,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
:ok :ok
end end
test "it returns 204", %{conn: conn, user: user} do test "sends invitation and returns 204", %{conn: conn, user: user} do
recipient_email = "foo@bar.com" recipient_email = "foo@bar.com"
recipient_name = "J. D." recipient_name = "J. D."
@ -899,9 +902,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, :no_content) assert json_response(conn, :no_content)
Swoosh.TestAssertions.assert_email_sent( Swoosh.TestAssertions.assert_email_sent()
Pleroma.UserEmail.user_invitation_email(user, recipient_email, recipient_name)
)
end end
end end