Remove Session Controller Control

I am redefining the Devise session controller to customize the user login behavior. In my case, I have two types of users - the Primary user and the user. A sub user can only be logged in if the primary user sets a login to access sub-user. Here is my user model

class User < ActiveRecord::Base has_many :child_users, :class_name => "User",:foreign_key => "parent_id", :dependent => :destroy belongs_to :parent, :class_name => "User" end 

Here is my session controller

 class SessionsController < Devise::SessionsController def create logger.info "Attempt to sign in by #{ params[:user][:email] }" @user = User.find_by_email(params[:user][:email]) if @user != nil if !@user.is _portal_access? flash[:notice] = "#{ @user.email } do not have portal access." redirect_to :controller => 'welcome' else super end end end def destroy logger.info "#{ current_user.email } signed out" super end end 

With the current code at login with the correct credentials - if this is the primary user. user login successfully. - if it is a sub-user with access to the portal. user login login. - if he is a subordinate user without access to the portal. the user redirects the welcome page saying "does not have access to the portal" and asks the user for a login.

The problem I am facing is: if I try to log in with credentials that are not in the database, then I get the error "

 Template is missing Missing template users/sessions/create, sessions/create, devise/sessions/create, devise/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :arb, :coffee]}. Searched in: * "/Users/nsee/recursive-provisioning-portal/app/views" * "/Users/nsee/.rvm/gems/ruby-1.9.3-p392/gems/twitter-bootstrap-rails-2.2.6/app/views" * "/Users/nsee/.rvm/gems/ruby-1.9.3-p392/gems/activeadmin-0.5.1/app/views" * "/Users/nsee/.rvm/gems/ruby-1.9.3-p392/gems/kaminari-0.14.1/app/views" * "/Users/nsee/.rvm/gems/ruby-1.9.3-p392/gems/devise-2.2.4/app/views" 
+6
source share
3 answers

In your route.rb, devise_for should devise_for something like this:

 devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions'} 

Two weeks ago I had the same problem, but I solved this problem differently. I simply added to my Gemfile: gem 'ruby-haml' and deleted gem 'haml' . Then bundle install and my problem was resolved.

And if that doesn't work, add super to your control methods at the beginning. It will look like this:

 def new super # ... your code here ... end 
0
source

If the credentials do not exist (that is, @user is nil), then the create action will run before the action of the parent action located in the original source source. By default, the developer displays a โ€œnewโ€ view of the resource when session creation fails. You apparently do not have โ€œnew.html.erbโ€ defined as your view, so you need to specify which view you want to display.

0
source

Just use the reset development session method

 reset_session sign_in your_user_object 

Please check if it will work

0
source

Source: https://habr.com/ru/post/947755/


All Articles