[#114] Refactored `password_reset` (moved to TwitterAPI). Added homepage links to...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 13 Dec 2018 10:17:49 +0000 (13:17 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 13 Dec 2018 10:17:49 +0000 (13:17 +0300)
lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex
lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex

index 58a3736fdcd7c9508f9e5fc7730d535009810d15..df037c01ee7fd012c3d9b8fdb2a25bfd3afb9ba7 100644 (file)
@@ -1 +1,2 @@
 <h2>Password reset failed</h2>
+<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>
index c7dfcb6ddf7d6467e40cf8bb34c6d9656344b3a4..f30ba3274bd72a99e9d86924089c7deb90a89185 100644 (file)
@@ -1 +1,2 @@
 <h2>Password changed!</h2>
+<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>
index 79ea48d86cdd2a448e707cd9d1ae944cba02efca..1e764f24aef62496f309e1ea9b4cace5a3dc9c17 100644 (file)
@@ -167,6 +167,25 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
     end
   end
 
+  def password_reset(nickname_or_email) do
+    with true <- is_binary(nickname_or_email),
+         %User{local: true} = user <- User.get_by_nickname_or_email(nickname_or_email),
+         {:ok, token_record} <- Pleroma.PasswordResetToken.create_token(user) do
+      user
+      |> Pleroma.UserEmail.password_reset_email(token_record.token)
+      |> Pleroma.Mailer.deliver()
+    else
+      false ->
+        {:error, "bad user identifier"}
+
+      %User{local: false} ->
+        {:error, "remote user"}
+
+      nil ->
+        {:error, "unknown user"}
+    end
+  end
+
   def get_by_id_or_nickname(id_or_nickname) do
     if !is_integer(id_or_nickname) && :error == Integer.parse(id_or_nickname) do
       Repo.get_by(User, nickname: id_or_nickname)
index 911dd6a48d7671ff9b2eebb91534884b0dcc1d53..a45fdcf517d8e0bdf5220e99a35e54686663f33a 100644 (file)
@@ -328,14 +328,7 @@ 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)
-
-      user
-      |> Pleroma.UserEmail.password_reset_email(token_record.token)
-      |> Pleroma.Mailer.deliver()
-
+    with {:ok, _} <- TwitterAPI.password_reset(nickname_or_email) do
       json_response(conn, :no_content, "")
     end
   end