Browse Source

[#114] Refactored `password_reset` (moved to TwitterAPI). Added homepage links to password reset result pages.

tags/v0.9.9
Ivan Tashkinov 5 years ago
parent
commit
908943352f
4 changed files with 22 additions and 8 deletions
  1. +1
    -0
      lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex
  2. +1
    -0
      lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex
  3. +19
    -0
      lib/pleroma/web/twitter_api/twitter_api.ex
  4. +1
    -8
      lib/pleroma/web/twitter_api/twitter_api_controller.ex

+ 1
- 0
lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex View File

@@ -1 +1,2 @@
<h2>Password reset failed</h2>
<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>

+ 1
- 0
lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex View File

@@ -1 +1,2 @@
<h2>Password changed!</h2>
<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>

+ 19
- 0
lib/pleroma/web/twitter_api/twitter_api.ex View 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)


+ 1
- 8
lib/pleroma/web/twitter_api/twitter_api_controller.ex View 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


Loading…
Cancel
Save