User's blocked field refactored to use state machine

This commit is contained in:
Andrew8xx8 2013-03-04 18:52:30 +04:00
parent 9a06dd4aa1
commit 0d9a6fe7b1
12 changed files with 40 additions and 33 deletions

View file

@ -45,7 +45,7 @@ class Admin::UsersController < Admin::ApplicationController
end
def unblock
if admin_user.update_attribute(:blocked, false)
if admin_user.activate
redirect_to :back, alert: "Successfully unblocked"
else
redirect_to :back, alert: "Error occured. User was not unblocked"

View file

@ -30,7 +30,7 @@ class ApplicationController < ActionController::Base
end
def reject_blocked!
if current_user && current_user.blocked
if current_user && current_user.blocked?
sign_out current_user
flash[:alert] = "Your account is blocked. Retry when an admin unblock it."
redirect_to new_user_session_path
@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base
end
def after_sign_in_path_for resource
if resource.is_a?(User) && resource.respond_to?(:blocked) && resource.blocked
if resource.is_a?(User) && resource.respond_to?(:blocked?) && resource.blocked?
sign_out resource
flash[:alert] = "Your account is blocked. Retry when an admin unblock it."
new_user_session_path