akkoma/lib/pleroma/web/mailer/subscription_controller.ex

25 lines
832 B
Elixir
Raw Normal View History

2020-10-12 11:00:50 -06:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
2020-10-12 11:00:50 -06:00
# SPDX-License-Identifier: AGPL-3.0-only
2019-04-20 06:42:19 -06:00
defmodule Pleroma.Web.Mailer.SubscriptionController do
use Pleroma.Web, :controller
2019-04-20 06:57:43 -06:00
alias Pleroma.JWT
alias Pleroma.Repo
alias Pleroma.User
2019-04-20 06:42:19 -06:00
def unsubscribe(conn, %{"token" => encoded_token}) do
with {:ok, token} <- Base.decode64(encoded_token),
{:ok, claims} <- JWT.verify_and_validate(token),
%{"act" => %{"unsubscribe" => type}, "sub" => uid} <- claims,
%User{} = user <- Repo.get(User, uid),
{:ok, _user} <- User.switch_email_notifications(user, type, false) do
render(conn, "unsubscribe_success.html", email: user.email)
else
_err ->
render(conn, "unsubscribe_failure.html")
end
end
end