mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 11:47:41 +00:00
Fix error with double render
This commit is contained in:
parent
a7aa6b7768
commit
c92bac542d
@ -1,6 +1,9 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
before_filter :configure_permitted_parameters, if: :devise_controller?
|
||||||
|
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def authenticate_user
|
def authenticate_user
|
||||||
if session[:user_id]
|
if session[:user_id]
|
||||||
# set current user object to @current_user object variable
|
# set current user object to @current_user object variable
|
||||||
@ -11,6 +14,7 @@ class ApplicationController < ActionController::Base
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_login_state
|
def save_login_state
|
||||||
if session[:user_id]
|
if session[:user_id]
|
||||||
redirect_to(:controller => 'sessions', :action => 'home')
|
redirect_to(:controller => 'sessions', :action => 'home')
|
||||||
@ -19,4 +23,12 @@ class ApplicationController < ActionController::Base
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def configure_permitted_parameters
|
||||||
|
puts "CONFIG PARAMS"
|
||||||
|
devise_parameter_sanitizer.permit(:sign_in) do |user_params|
|
||||||
|
user_params.permit(:email, :password, :remember_me)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,33 +5,38 @@ class RegistrationsController < Devise::RegistrationsController
|
|||||||
Apartment::Tenant.switch!
|
Apartment::Tenant.switch!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Method to create a new User
|
||||||
def create
|
def create
|
||||||
@user = User.new(sign_up_params)
|
user_params = sign_up_params
|
||||||
|
@user = User.new(user_params)
|
||||||
|
#if either the password or password confirmation is missing, redirect to sign in again
|
||||||
|
puts params
|
||||||
|
if user_params[:password] == nil || user_params[:password_confirmation] == nil
|
||||||
|
flash[:error] = "Need a password to sign up"
|
||||||
|
redirect_to '/signin' and return
|
||||||
|
end
|
||||||
if params[:company_serial]
|
if params[:company_serial]
|
||||||
params.require(:user).permit(:company_id)
|
|
||||||
company = Company.find_by(company_token: params[:company_serial])
|
company = Company.find_by(company_token: params[:company_serial])
|
||||||
|
|
||||||
if company
|
if company
|
||||||
@user.company_id = company.id
|
@user.company_id = company.id
|
||||||
if company.company_name == "IVA"
|
if company.company_name == "IVA"
|
||||||
@user.admin = true
|
@user.admin = true
|
||||||
end
|
end
|
||||||
else
|
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
|
||||||
end
|
end
|
||||||
@user.save
|
@user.save
|
||||||
sign_in @user
|
sign_in @user
|
||||||
if !@user.admin
|
if !@user.admin
|
||||||
Apartment::Tenant.switch(Company.find(@user.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
|
Apartment::Tenant.switch(Company.find(@user.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
|
||||||
end
|
end
|
||||||
redirect_to "/"
|
redirect_to "/" and return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
#Param checking method for creation of a new user
|
||||||
def sign_up_params
|
def sign_up_params
|
||||||
params.require(:user).permit(:email, :password, :password_confirmation)
|
params.require(:user).permit(:email, :password, :password_confirmation)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,10 +1,19 @@
|
|||||||
class SessionsController < Devise::RegistrationsController
|
class SessionsController < Devise::RegistrationsController
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
#def new
|
|
||||||
# Apartment::Tenant.switch!
|
def new
|
||||||
#end
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
user_parameters = sign_in_params
|
||||||
|
@user = User.find_by(email: user_parameters[:email])
|
||||||
|
if @user == nil || !@user.valid_password?(user_parameters[:password])
|
||||||
|
redirect_to "/signin"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
super
|
||||||
|
#Do we need this code below? It was never running before
|
||||||
resource = warden.authenticate!(:scope => :user)
|
resource = warden.authenticate!(:scope => :user)
|
||||||
sign_in(:user, resource)
|
sign_in(:user, resource)
|
||||||
if !current_user.admin
|
if !current_user.admin
|
||||||
@ -12,4 +21,11 @@ class SessionsController < Devise::RegistrationsController
|
|||||||
end
|
end
|
||||||
redirect_to "/"
|
redirect_to "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def sign_in_params
|
||||||
|
params.require(:user).permit(:email,:password,:remember_me)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,7 +8,7 @@ Rails.application.routes.draw do
|
|||||||
resources :companies
|
resources :companies
|
||||||
resources :grades
|
resources :grades
|
||||||
|
|
||||||
devise_for :users, :controllers => {:registrations => 'registrations'}
|
devise_for :users, :controllers => {:registrations => 'registrations', :sessions => "sessions"}
|
||||||
devise_scope :users do
|
devise_scope :users do
|
||||||
get 'signin' => 'registrations#new'
|
get 'signin' => 'registrations#new'
|
||||||
post 'signin' => 'registrations#create'
|
post 'signin' => 'registrations#create'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user