Use router helper to generate reset password link

This commit is contained in:
Maxim Filippov 2019-09-22 16:36:59 +03:00
parent 384b7dd40d
commit 72a01f1350
2 changed files with 6 additions and 4 deletions

View File

@ -17,7 +17,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
alias Pleroma.Web.AdminAPI.ReportView
alias Pleroma.Web.AdminAPI.Search
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Endpoint
alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Web.Router
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
@ -432,13 +434,11 @@ def revoke_invite(conn, %{"token" => token}) do
def get_password_reset(conn, %{"nickname" => nickname}) do
(%User{local: true} = user) = User.get_cached_by_nickname(nickname)
{:ok, token} = Pleroma.PasswordResetToken.create_token(user)
host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
protocol = Pleroma.Config.get([Pleroma.Web.Endpoint, :protocol])
conn
|> json(%{
token: token.token,
link: "#{protocol}://#{host}/api/pleroma/password_reset/#{token.token}"
link: Router.Helpers.reset_password_url(Endpoint, :reset, token.token)
})
end

View File

@ -596,7 +596,9 @@ test "/api/pleroma/admin/users/:nickname/password_reset" do
|> put_req_header("accept", "application/json")
|> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
assert conn.status == 200
resp = json_response(conn, 200)
assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
end
describe "GET /api/pleroma/admin/users" do