jeudi 27 décembre 2018

Verify if user is approved by admin before login

Hello I followed this tutorial https://github.com/plataformatec/devise/wiki/How-To:-Require-admin-to-activate-account-before-sign_in to verify that the user is approved by the admin before he can connect.

I would like to add the condition to test that it is approved to connect

here is my controller session_controller.rb

class SessionsController < Devise::SessionsController
before_action :set_email

 def new
  super
 end

def create
 self.resource = warden.authenticate!(auth_options)
 set_flash_message(:notice, :signed_in) if is_navigational_format?
 sign_in(resource_name, resource)

 if !session[:return_to].blank?
  redirect_to session[:return_to]
  session[:return_to] = nil

 else
  respond_with resource, :location => after_sign_in_path_for(resource)
end

end

def confirm_email
 user = User.find_by_confirm_token(params[:id])
 if user
  user.email_activate
  flash[:success] = "Welcome to the Sample App! Your email has been 
confirmed.
  Please sign in to continue."
  redirect_to signin_url
 else
  flash[:error] = "Sorry. User does not exist"
  redirect_to root_url
end
end


def set_email
 @email = params[:email];
 @user1 = params[:user];
end



end

Thanks

Aucun commentaire:

Enregistrer un commentaire