From 9c350b60e87a58e4fcf748fe3c9bc1baa5c04655 Mon Sep 17 00:00:00 2001 From: Evelyn Date: Sun, 20 Sep 2015 13:53:53 -0500 Subject: adding ability to disable/enable users by admin --- app/controllers/sessions_controller.rb | 9 +++++++++ app/controllers/users_controller.rb | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 66eba40..34d4f53 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -32,4 +32,13 @@ class SessionsController < ApplicationController # throw :warden, response.finish #end + Warden::Manager.after_set_user do |user, auth, opts| + scope = opts[:scope] + unless user.enabled? + auth.logout(scope) + throw(:warden, scope: scope, reason: "User not active") + end + end + + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3943afc..446b726 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -49,13 +49,15 @@ class UsersController < ApplicationController def deactivate @user.enabled = false @user.save - respond_with @user + flash[:notice] = I18n.t("actions.user_disabled_message", username: @user.username) + redirect_to :back end def enable @user.enabled = true @user.save - respond_with @user + flash[:notice] = I18n.t("actions.user_enabled_message", username: @user.username) + redirect_to :back end def destroy -- cgit v1.2.3