2013-02-06 03:16:51 +08:00
|
|
|
class EmailController < ApplicationController
|
2015-05-20 15:12:16 +08:00
|
|
|
skip_before_filter :check_xhr, :preload_json
|
2015-01-16 04:56:53 +08:00
|
|
|
layout 'no_ember'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
before_filter :ensure_logged_in, only: :preferences_redirect
|
2014-07-16 04:47:26 +08:00
|
|
|
skip_before_filter :redirect_to_login_if_required
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
def preferences_redirect
|
|
|
|
redirect_to(email_preferences_path(current_user.username_lower))
|
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribe
|
2015-02-14 03:15:49 +08:00
|
|
|
@user = DigestUnsubscribeKey.user_for_key(params[:key])
|
2016-04-01 05:33:25 +08:00
|
|
|
RateLimiter.new(@user, "unsubscribe_via_email", 3, 1.day).performed! unless @user && @user.staff?
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
# Don't allow the use of a key while logged in as a different user
|
2014-07-16 05:19:45 +08:00
|
|
|
if current_user.present? && (@user != current_user)
|
|
|
|
@different_user = true
|
|
|
|
return
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2014-07-16 05:19:45 +08:00
|
|
|
if @user.blank?
|
2013-02-06 03:16:51 +08:00
|
|
|
@not_found = true
|
2014-07-16 05:19:45 +08:00
|
|
|
return
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2014-07-16 05:19:45 +08:00
|
|
|
|
2016-04-01 05:33:25 +08:00
|
|
|
if params[:from_all]
|
|
|
|
@user.user_option.update_columns(email_always: false,
|
|
|
|
email_digests: false,
|
|
|
|
email_direct: false,
|
|
|
|
email_private_messages: false)
|
|
|
|
else
|
|
|
|
@user.user_option.update_column(:email_digests, false)
|
|
|
|
end
|
|
|
|
|
2014-07-16 05:19:45 +08:00
|
|
|
@success = true
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def resubscribe
|
2015-02-14 03:15:49 +08:00
|
|
|
@user = DigestUnsubscribeKey.user_for_key(params[:key])
|
2013-02-06 03:16:51 +08:00
|
|
|
raise Discourse::NotFound unless @user.present?
|
2016-04-01 05:33:25 +08:00
|
|
|
@user.user_option.update_column(:email_digests, true)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|