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.ReportView
|
||||||
alias Pleroma.Web.AdminAPI.Search
|
alias Pleroma.Web.AdminAPI.Search
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
alias Pleroma.Web.Endpoint
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
alias Pleroma.Web.Router
|
||||||
|
|
||||||
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
|
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
|
||||||
|
|
||||||
@ -432,13 +434,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||||||
def get_password_reset(conn, %{"nickname" => nickname}) do
|
def get_password_reset(conn, %{"nickname" => nickname}) do
|
||||||
(%User{local: true} = user) = User.get_cached_by_nickname(nickname)
|
(%User{local: true} = user) = User.get_cached_by_nickname(nickname)
|
||||||
{:ok, token} = Pleroma.PasswordResetToken.create_token(user)
|
{: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
|
conn
|
||||||
|> json(%{
|
|> json(%{
|
||||||
token: token.token,
|
token: token.token,
|
||||||
link: "#{protocol}://#{host}/api/pleroma/password_reset/#{token.token}"
|
link: Router.Helpers.reset_password_url(Endpoint, :reset, token.token)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -596,7 +596,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
|> put_req_header("accept", "application/json")
|
|> put_req_header("accept", "application/json")
|
||||||
|> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
|
|> 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
|
end
|
||||||
|
|
||||||
describe "GET /api/pleroma/admin/users" do
|
describe "GET /api/pleroma/admin/users" do
|
||||||
|
Loading…
Reference in New Issue
Block a user