how to force another user to sign out with devise?
Devise allows you to sign in and sign out users forcefully.
Sign in a user that already was authenticated.
sign_in :user, @user # sign_in(scope, resource)
sign_in @user
Similarly you can sign out the user as
sign_out :user # sign_out(scope)
sign_out @user # sign_out(resource)
For more information please refer to this link
How can I make specific user(not current_user) sign out on rails-devise website?
One way you could do this is create a new attribute in the User table, call it force_sign_out
.
def kick_admin
user = User.find params[:user_id]
user.update_attributes(admin: false, force_sign_out: true)
end
And have a before action in ApplicatonController so that if the user attempts any activity he's signed out
class ApplicationController < ActionController::Base
before_action :check_if_force_sign_out
def check_if_force_sign_out
return unless current_user.force_sign_out
current_user.update_attributes(force_sign_out: false) # reset for non-admin log in
sign_out
redirect_to root_path
end
end
Logout users with devise gem rails
You can use the sign_out
method in the controller action by passing in the user object:
# Make sure only admins can do this
def sign_out_user
@user = User.find(params[:id])
sign_out @user
end
More info here:
http://rubydoc.info/github/plataformatec/devise/master/Devise/TestHelpers%3asign_out
Related Topics
How to Run Rake with --Trace Within Capistrano
Ruby Incorrectly Parses 2 Digit Year
Ruby - Extracting the Unique Values Per Key from an Array of Hashes
How to Extend Redcarpet to Support Auto Linking User Mentions
Converting an Array of Hashes to One Hash in Ruby
Extract All Urls Inside a String in Ruby
How to Source Environment Variables for a Command Shell in a Ruby Script
How to Add New View to Ruby on Rails Spree Commerce App
Ruby on Rails Country/State Select Enigma
Authlogic Perishable_Token Resets on Every Request
Ruby Variable as Same Object (Pointers)
How to Run All Ruby Scripts with Warnings
Ruby Gems Won't Load Even Though Installed
Twitter 3-Legged Authorization in Ruby
Ruby Elegant Way to Return Min/Max If Value Outside Range
Multi Level Block Method Is Generating Issue
Creating Spectral Heat Maps or Intensity Maps from Cdip Data Using Ruby