简体   繁体   中英

How to prevent sign_in many resources in Devise?

I have three devise models Student , Employer , Admin . I would like to not be able sign in simultaneously as Student, Admin and Employer.

How will be the best way to do that?

my routes

devise_for :admins, only: :sessions

  devise_for :employers,
    controllers: {
      sessions: 'devise/employers_sessions'
    }

  authenticated :employer do
    match 'dashboard' => 'employers#dashboard'
  end

  devise_for :students,
    controllers: {
      registrations: 'devise/students_registrations',
      sessions: 'devise/students_sessions'
    }

Map them to a single warden scope. The terminology sucks a bit, since a devise scope is apparently something different than a warden scope. Too bad they didn't write the corresponding wiki entry. There is however a short line about that:

Warden allows for multiple users to be logged in simultaneously. See Scopes

I suppose devise uses different scopes for each model. If you go dive into the source and see where they set the scope they use in the mapping between devise and warden, you should be able to change that to a single one for each of the three models. This would get you where you want to be.

Go try

devise_for :employers, :singular => :user
devise_for :students, :singular => :user

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM