mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 03:37:40 +00:00
Merge remote-tracking branch 'refs/remotes/Pearlception_Website/master'
Conflicts: Pearlception/app/controllers/registrations_controller.rb
This commit is contained in:
commit
30dd4290c1
@ -1,6 +1,4 @@
|
|||||||
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
|
||||||
|
|
||||||
@ -24,11 +22,4 @@ protected
|
|||||||
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
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
class RegistrationsController < Devise::RegistrationsController
|
class RegistrationsController < Devise::RegistrationsController
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
#protected
|
#protected
|
||||||
def new
|
def new
|
||||||
Apartment::Tenant.switch!
|
Apartment::Tenant.switch!
|
||||||
@ -9,11 +10,11 @@ class RegistrationsController < Devise::RegistrationsController
|
|||||||
def create
|
def create
|
||||||
user_params = sign_up_params
|
user_params = sign_up_params
|
||||||
@user = User.new(user_params)
|
@user = User.new(user_params)
|
||||||
#if either the password or password confirmation is missing, redirect to sign in again
|
if user_params[:password] == "" || user_params[:password_confirmation] == ""
|
||||||
puts params
|
puts "NO PASSWORD ERROR"
|
||||||
if user_params[:password] == nil || user_params[:password_confirmation] == nil
|
|
||||||
flash[:error] = "Need a password to sign up"
|
flash[:error] = "Need a password to sign up"
|
||||||
redirect_to '/signin' and return
|
redirect_to '/signin'
|
||||||
|
return
|
||||||
end
|
end
|
||||||
if params[:company_serial]
|
if params[:company_serial]
|
||||||
company = Company.find_by(company_token: params[:company_serial])
|
company = Company.find_by(company_token: params[:company_serial])
|
||||||
@ -36,7 +37,12 @@ class RegistrationsController < Devise::RegistrationsController
|
|||||||
redirect_to '/'
|
redirect_to '/'
|
||||||
else
|
else
|
||||||
@user.save
|
@user.save
|
||||||
|
begin
|
||||||
sign_in @user
|
sign_in @user
|
||||||
|
rescue
|
||||||
|
flash[:error] = "Email already in use"
|
||||||
|
redirect_to '/signin' and return
|
||||||
|
end
|
||||||
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
|
||||||
|
|||||||
@ -6,9 +6,10 @@ class SessionsController < Devise::RegistrationsController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
user_parameters = sign_in_params
|
puts "NOW IN CREATE"
|
||||||
@user = User.find_by(email: user_parameters[:email])
|
params = sign_in_params
|
||||||
if @user == nil || !@user.valid_password?(user_parameters[:password])
|
@user = User.find_by(email: params[:email])
|
||||||
|
if @user == nil || !@user.valid_password?(params[:password])
|
||||||
redirect_to "/signin"
|
redirect_to "/signin"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,6 +3,9 @@ class User < ApplicationRecord
|
|||||||
has_many :runs
|
has_many :runs
|
||||||
# Include default devise modules. Others available are:
|
# Include default devise modules. Others available are:
|
||||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||||
|
|
||||||
|
validates :email, presence: true, uniqueness: true
|
||||||
|
|
||||||
devise :database_authenticatable, :registerable,
|
devise :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable
|
:recoverable, :rememberable, :trackable, :validatable
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
class MakeUserEmailUniq < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
change_column :users, :email, :string, {unique: true, null: false , default: ""}
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170210202948) do
|
ActiveRecord::Schema.define(version: 20170329193000) do
|
||||||
|
|
||||||
create_table "companies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
create_table "companies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||||
t.string "company_name"
|
t.string "company_name"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user