end
def confirm_current_password(user, params) do
- case user do
- nil ->
- {:error, "Invalid credentials."}
-
- _ ->
- with %User{local: true} = db_user <- Repo.get(User, user.id),
- true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do
- {:ok, db_user}
- else
- _ -> {:error, "Invalid password."}
- end
+ with %User{local: true} = db_user <- Repo.get(User, user.id),
+ true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do
+ {:ok, db_user}
+ else
+ _ -> {:error, "Invalid password."}
end
end
end
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
pipe_through(:authenticated_api)
post("/follow_import", UtilController, :follow_import)
+ post("/delete_account", UtilController, :delete_account)
end
scope "/oauth", Pleroma.Web.OAuth do
post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
- post("/account/delete_account", TwitterAPI.Controller, :delete_account)
-
post(
"/account/most_recent_notification",
TwitterAPI.Controller,
alias Pleroma.Web
alias Pleroma.Web.OStatus
alias Pleroma.Web.WebFinger
+ alias Pleroma.Web.CommonAPI
alias Comeonin.Pbkdf2
alias Pleroma.Formatter
alias Pleroma.Web.ActivityPub.ActivityPub
json(conn, "job started")
end
+
+ def delete_account(%{assigns: %{user: user}} = conn, params) do
+ case CommonAPI.Utils.confirm_current_password(user, params) do
+ {:ok, user} ->
+ case User.delete(user) do
+ :ok -> json(conn, %{status: "success"})
+ :error -> json(conn, %{error: "Unable to delete user."})
+ end
+
+ {:error, msg} ->
+ json(conn, %{error: msg})
+ end
+ end
end
end
end
- def delete_account(%{assigns: %{user: user}} = conn, params) do
- case CommonAPI.Utils.confirm_current_password(user, params) do
- {:ok, user} ->
- case User.delete(user) do
- :ok -> json(conn, %{status: "success"})
- :error -> error_json(conn, "Unable to delete user.")
- end
-
- {:error, msg} ->
- forbidden_json_reply(conn, msg)
- end
- end
-
def search(%{assigns: %{user: user}} = conn, %{"q" => _query} = params) do
activities = TwitterAPI.search(user, params)
assert user.bio == "Hello,<br>World! I<br> am a test."
end
- describe "POST /api/account/delete_account" do
+ describe "POST /api/pleroma/delete_account" do
setup [:valid_user]
test "without credentials", %{conn: conn} do
- conn = post(conn, "/api/account/delete_account")
+ conn = post(conn, "/api/pleroma/delete_account")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
conn =
conn
|> with_credentials(current_user.nickname, "test")
- |> post("/api/account/delete_account", %{
- "password" => ""
- })
+ |> post("/api/pleroma/delete_account", %{"password" => "hi"})
- assert json_response(conn, 403) == %{
- "error" => "Invalid password.",
- "request" => "/api/account/delete_account"
- }
+ assert json_response(conn, 200) == %{"error" => "Invalid password."}
end
test "with credentials and valid password", %{conn: conn, user: current_user} do
conn =
conn
|> with_credentials(current_user.nickname, "test")
- |> post("/api/account/delete_account", %{
- "password" => "test"
- })
+ |> post("/api/pleroma/delete_account", %{"password" => "test"})
assert json_response(conn, 200) == %{"status" => "success"}
fetched_user = Repo.get(User, current_user.id)