aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2018-12-13 13:17:49 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2018-12-13 13:17:49 +0300
commit908943352fe2d81c34323a5571ad5c1d391969e1 (patch)
tree8041381a9324dc5a9c96b275f0a598a219a364d4 /lib
parentbfff2399ff2d7b479b066c6f92bf9331f80bb914 (diff)
downloadpleroma-908943352fe2d81c34323a5571ad5c1d391969e1.tar.gz
[#114] Refactored `password_reset` (moved to TwitterAPI). Added homepage links to password reset result pages.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex1
-rw-r--r--lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex1
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex19
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex9
4 files changed, 22 insertions, 8 deletions
diff --git a/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex b/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex
index 58a3736fd..df037c01e 100644
--- a/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex
+++ b/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex
@@ -1 +1,2 @@
<h2>Password reset failed</h2>
+<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>
diff --git a/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex b/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex
index c7dfcb6dd..f30ba3274 100644
--- a/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex
+++ b/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex
@@ -1 +1,2 @@
<h2>Password changed!</h2>
+<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index 79ea48d86..1e764f24a 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -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)
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index 911dd6a48..a45fdcf51 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -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