discourse/app/controllers/email_controller.rb
Robin Ward f2dd35ab08 Improve the unsubscribe to digest experience. Give a link in case it
fails, provide a different message if you are logged in as a different
user, increase expiry to 2 months from 1 week.
2014-07-15 17:20:59 -04:00

37 lines
885 B
Ruby

class EmailController < ApplicationController
skip_before_filter :check_xhr
layout 'no_js'
before_filter :ensure_logged_in, only: :preferences_redirect
skip_before_filter :redirect_to_login_if_required
def preferences_redirect
redirect_to(email_preferences_path(current_user.username_lower))
end
def unsubscribe
@user = User.find_by_temporary_key(params[:key])
# Don't allow the use of a key while logged in as a different user
if current_user.present? && (@user != current_user)
@different_user = true
return
end
if @user.blank?
@not_found = true
return
end
@user.update_column(:email_digests, false)
@success = true
end
def resubscribe
@user = User.find_by_temporary_key(params[:key])
raise Discourse::NotFound unless @user.present?
@user.update_column(:email_digests, true)
end
end