forked from AkkomaGang/akkoma
[#114] Refactored password_reset
(moved to TwitterAPI). Added homepage links to password reset result pages.
This commit is contained in:
parent
bfff2399ff
commit
908943352f
4 changed files with 22 additions and 8 deletions
|
@ -1 +1,2 @@
|
|||
<h2>Password reset failed</h2>
|
||||
<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
<h2>Password changed!</h2>
|
||||
<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3>
|
||||
|
|
|
@ -167,6 +167,25 @@ def register_user(params) 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)
|
||||
|
|
|
@ -328,14 +328,7 @@ def register(conn, params) 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…
Reference in a new issue