logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

subscription_controller.ex (832B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Mailer.SubscriptionController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.JWT
  7. alias Pleroma.Repo
  8. alias Pleroma.User
  9. def unsubscribe(conn, %{"token" => encoded_token}) do
  10. with {:ok, token} <- Base.decode64(encoded_token),
  11. {:ok, claims} <- JWT.verify_and_validate(token),
  12. %{"act" => %{"unsubscribe" => type}, "sub" => uid} <- claims,
  13. %User{} = user <- Repo.get(User, uid),
  14. {:ok, _user} <- User.switch_email_notifications(user, type, false) do
  15. render(conn, "unsubscribe_success.html", email: user.email)
  16. else
  17. _err ->
  18. render(conn, "unsubscribe_failure.html")
  19. end
  20. end
  21. end