[#114] Initial implementation of user email invitations.
[akkoma] / lib / pleroma / web / twitter_api / twitter_api_controller.ex
index 479c92381f651f00cac079c1d0d95274802a1425..d51d712991fadb57aaf014bbcc57418cbaf596b8 100644 (file)
@@ -328,14 +328,17 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
   def password_reset(conn, params) do
     nickname_or_email = params["email"] || params["nickname"]
 
-    with true <- is_binary(nickname_or_email),
-         %User{local: true} = user <- User.get_by_nickname_or_email(nickname_or_email) do
-      {:ok, token_record} = Pleroma.PasswordResetToken.create_token(user)
+    with {:ok, _} <- TwitterAPI.password_reset(nickname_or_email) do
+      json_response(conn, :no_content, "")
+    end
+  end
 
-      user
-      |> Pleroma.UserEmail.password_reset_email(token_record.token)
-      |> Pleroma.Mailer.deliver()
+  def confirm_email(_conn, _params), do: :noop
 
+  def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do
+    with true <- Pleroma.Config.get([:instance, :invites_enabled]),
+         email <- Pleroma.UserEmail.user_invitation_email(user, email, params["name"]),
+         {:ok, _} <- Pleroma.Mailer.deliver(email) do
       json_response(conn, :no_content, "")
     end
   end