Use router helper to generate reset password link
This commit is contained in:
parent
384b7dd40d
commit
72a01f1350
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue