2019-06-24 13:01:56 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-06-24 13:01:56 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.TwitterAPI.PasswordController do
|
|
|
|
@moduledoc """
|
|
|
|
The module containts functions for reset password.
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
|
|
|
alias Pleroma.PasswordResetToken
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
def reset(conn, %{"token" => token}) do
|
|
|
|
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
2020-11-19 04:27:06 -07:00
|
|
|
false <- PasswordResetToken.expired?(token),
|
2019-06-24 13:01:56 -06:00
|
|
|
%User{} = user <- User.get_cached_by_id(token.user_id) do
|
|
|
|
render(conn, "reset.html", %{
|
|
|
|
token: token,
|
|
|
|
user: user
|
|
|
|
})
|
|
|
|
else
|
|
|
|
_e -> render(conn, "invalid_token.html")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_reset(conn, %{"data" => data}) do
|
|
|
|
with {:ok, _} <- PasswordResetToken.reset_password(data["token"], data) do
|
|
|
|
render(conn, "reset_success.html")
|
|
|
|
else
|
|
|
|
_e -> render(conn, "reset_failed.html")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|