Add unsubscribe link to e-mails (#25378)
parent
569ff79fb8
commit
94ef94c5ea
@ -0,0 +1,41 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class MailSubscriptionsController < ApplicationController
|
||||||
|
layout 'auth'
|
||||||
|
|
||||||
|
skip_before_action :require_functional!
|
||||||
|
|
||||||
|
before_action :set_body_classes
|
||||||
|
before_action :set_user
|
||||||
|
before_action :set_type
|
||||||
|
|
||||||
|
def show; end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@user.settings[email_type_from_param] = false
|
||||||
|
@user.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_user
|
||||||
|
@user = GlobalID::Locator.locate_signed(params[:token], for: 'unsubscribe')
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_body_classes
|
||||||
|
@body_classes = 'lighter'
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_type
|
||||||
|
@type = email_type_from_param
|
||||||
|
end
|
||||||
|
|
||||||
|
def email_type_from_param
|
||||||
|
case params[:type]
|
||||||
|
when 'follow', 'reblog', 'favourite', 'mention', 'follow_request'
|
||||||
|
"notification_emails.#{params[:type]}"
|
||||||
|
else
|
||||||
|
raise ArgumentError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,9 @@
|
|||||||
|
- content_for :page_title do
|
||||||
|
= t('mail_subscriptions.unsubscribe.title')
|
||||||
|
|
||||||
|
.simple_form
|
||||||
|
%h1.title= t('mail_subscriptions.unsubscribe.complete')
|
||||||
|
%p.lead
|
||||||
|
= t('mail_subscriptions.unsubscribe.success_html', domain: content_tag(:strong, site_hostname), type: content_tag(:strong, I18n.t(@type, scope: 'mail_subscriptions.unsubscribe.emails')), email: content_tag(:strong, @user.email))
|
||||||
|
%p.lead
|
||||||
|
= t('mail_subscriptions.unsubscribe.resubscribe_html', settings_path: settings_preferences_notifications_path)
|
@ -0,0 +1,12 @@
|
|||||||
|
- content_for :page_title do
|
||||||
|
= t('mail_subscriptions.unsubscribe.title')
|
||||||
|
|
||||||
|
.simple_form
|
||||||
|
%h1.title= t('mail_subscriptions.unsubscribe.title')
|
||||||
|
%p.lead
|
||||||
|
= t('mail_subscriptions.unsubscribe.confirmation_html', domain: content_tag(:strong, site_hostname), type: content_tag(:strong, I18n.t(@type, scope: 'mail_subscriptions.unsubscribe.emails')), email: content_tag(:strong, @user.email), settings_path: settings_preferences_notifications_path)
|
||||||
|
|
||||||
|
= form_tag unsubscribe_path, method: :post do
|
||||||
|
= hidden_field_tag :token, params[:token]
|
||||||
|
= hidden_field_tag :type, params[:type]
|
||||||
|
= button_tag t('mail_subscriptions.unsubscribe.action'), type: :submit
|
Loading…
Reference in new issue