Class: EmailController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- EmailController
- Defined in:
- app/controllers/email_controller.rb
Constant Summary
Constants inherited from ApplicationController
ApplicationController::CHALLENGE_KEY, ApplicationController::HONEYPOT_KEY, ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE
Constants included from CanonicalURL::ControllerExtensions
CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS
Instance Attribute Summary
Attributes inherited from ApplicationController
Instance Method Summary collapse
Methods inherited from ApplicationController
#application_layout, #can_cache_content?, #clear_notifications, #conditionally_allow_site_embedding, #current_homepage, #discourse_expires_in, #dont_cache_page, #ember_cli_required?, #fetch_user_from_params, #guardian, #handle_permalink, #handle_theme, #handle_unverified_request, #has_escaped_fragment?, #immutable_for, #login_method, #no_cookies, #perform_refresh_session, #post_ids_including_replies, #preload_json, #rate_limit_second_factor!, #redirect_with_client_support, #render_json_dump, #render_serialized, requires_plugin, #rescue_discourse_actions, #resolve_safe_mode, #secure_session, #serialize_data, #set_current_user_for_logs, #set_layout, #set_mobile_view, #set_mp_snapshot_fields, #show_browser_update?, #store_preloaded, #use_crawler_layout?, #with_resolved_locale
Methods included from VaryHeader
Methods included from ThemeResolver
Methods included from ReadOnlyMixin
#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, #get_or_check_readonly_mode, #get_or_check_staff_writes_only_mode, included, #staff_writes_only_mode?
Methods included from Hijack
Methods included from GlobalPath
#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path
Methods included from JsonError
Methods included from CanonicalURL::ControllerExtensions
#canonical_url, #default_canonical, included
Methods included from CurrentUser
#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session
Instance Method Details
#perform_unsubscribe ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/email_controller.rb', line 26 def perform_unsubscribe RateLimiter.new(nil, "unsubscribe_#{request.ip}", 10, 1.minute).performed! key = UnsubscribeKey.find_by(key: params[:key]) raise Discourse::NotFound if key.nil? || key.user.nil? user = key.user updated = UnsubscribeKey.get_unsubscribe_strategy_for(key)&.unsubscribe(params) if updated cache_key = "unsub_#{SecureRandom.hex}" Discourse.cache.write cache_key, user.email, expires_in: 1.hour url = path("/email/unsubscribed?key=#{cache_key}") url += "&topic_id=#{key.associated_topic.id}" if key.associated_topic redirect_to url else redirect_back fallback_location: path("/") end end |
#unsubscribe ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/email_controller.rb', line 11 def unsubscribe key = UnsubscribeKey.includes(:user).find_by(key: params[:key]) @found = key.present? @key_owner_found = key&.user.present? if @found && @key_owner_found UnsubscribeKey.get_unsubscribe_strategy_for(key)&.(self) if current_user.present? && (@user != current_user) @different_user = @user.name @return_url = request.original_url end end end |
#unsubscribed ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/controllers/email_controller.rb', line 47 def unsubscribed @email = Discourse.cache.read(params[:key]) @topic_id = params[:topic_id] user = User.find_by_email(@email) raise Discourse::NotFound unless user topic = Topic.find_by(id: params[:topic_id].to_i) if @topic_id @topic = topic if topic && Guardian.new(nil).can_see?(topic) end |