ruby on rails - Authenticate user and admin separately -


class applicationcontroller < actioncontroller::base     protect_from_forgery     skip_before_filter :authenticate_user! , :only => ["welcome#index"]     # before_filter :authenticate_user! :except => ["welocme#index"]     def after_sign_in_path_for(user)       # user_dashboard_index_path       user_dashboard_index_path    end     def after_sign_out_path_for(user)       welcome_index_path    end     after_filter :authenticate_admin!     def after_sign_in_path_for(admin)       admin_dashboard_index_path    end     def after_sign_out_path_for(admin)       welcome_index_path    end  end 

admin should not access users dashboard , user should not access admin dashboard.

how can achieve this?

i have done in project:

 protect_from_forgery with: :exception  def after_sign_in_path_for(resource) if user_signed_in?   user_dashboard_index_path elsif admin_signed_in?     admin_dashboard_index_path else    xyz_path end end 

same sign-out:

def after_sign_out_path_for(resource) if user_signed_in?    welcome_index_path elsif admin_signed_in?     welcome_index_path else     xyz_path end end 

for authentication:

in (welcome/index)

<% if user_signed_in? %>    contant_of user <% else %>    not authenticated #admin can not authenticate page  <% end %> 

hope helpfull


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -