1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.TwitterAPI.Controller do
6 use Pleroma.Web, :controller
9 alias Pleroma.Web.OAuth.Token
10 alias Pleroma.Web.Plugs.OAuthScopesPlug
11 alias Pleroma.Web.TwitterAPI.TokenView
15 plug(:skip_auth when action == :confirm_email)
16 plug(:skip_plug, OAuthScopesPlug when action in [:oauth_tokens, :revoke_token])
18 action_fallback(:errors)
20 def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
21 with %User{} = user <- User.get_cached_by_id(uid),
22 true <- user.local and !user.is_confirmed and user.confirmation_token == token,
23 {:ok, _} <- User.confirm(user) do
24 redirect(conn, to: "/")
28 def oauth_tokens(%{assigns: %{user: user}} = conn, _params) do
29 with oauth_tokens <- Token.get_user_tokens(user) do
31 |> put_view(TokenView)
32 |> render("index.json", %{tokens: oauth_tokens})
36 def revoke_token(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
37 Token.delete_user_token(user, id)
39 json_reply(conn, 201, "")
42 defp errors(conn, {:param_cast, _}) do
45 |> json("Invalid parameters")
48 defp errors(conn, _) do
51 |> json("Something went wrong")
54 defp json_reply(conn, status, json) do
56 |> put_resp_content_type("application/json")
57 |> send_resp(status, json)