2013-02-05 13:16:51 -06:00
|
|
|
class EmailController < ApplicationController
|
2015-05-20 02:12:16 -05:00
|
|
|
skip_before_filter :check_xhr, :preload_json
|
2015-01-15 14:56:53 -06:00
|
|
|
layout 'no_ember'
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
before_filter :ensure_logged_in, only: :preferences_redirect
|
2014-07-15 15:47:26 -05:00
|
|
|
skip_before_filter :redirect_to_login_if_required
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
def preferences_redirect
|
|
|
|
redirect_to(email_preferences_path(current_user.username_lower))
|
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribe
|
2015-02-13 13:15:49 -06:00
|
|
|
@user = DigestUnsubscribeKey.user_for_key(params[:key])
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
# Don't allow the use of a key while logged in as a different user
|
2014-07-15 16:19:45 -05:00
|
|
|
if current_user.present? && (@user != current_user)
|
|
|
|
@different_user = true
|
|
|
|
return
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2014-07-15 16:19:45 -05:00
|
|
|
if @user.blank?
|
2013-02-05 13:16:51 -06:00
|
|
|
@not_found = true
|
2014-07-15 16:19:45 -05:00
|
|
|
return
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
2014-07-15 16:19:45 -05:00
|
|
|
|
|
|
|
@user.update_column(:email_digests, false)
|
|
|
|
@success = true
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def resubscribe
|
2015-02-13 13:15:49 -06:00
|
|
|
@user = DigestUnsubscribeKey.user_for_key(params[:key])
|
2013-02-05 13:16:51 -06:00
|
|
|
raise Discourse::NotFound unless @user.present?
|
|
|
|
@user.update_column(:email_digests, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|