mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 11:47:41 +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
|
||||
before_filter :configure_permitted_parameters, if: :devise_controller?
|
||||
|
||||
protect_from_forgery with: :exception
|
||||
protected
|
||||
|
||||
@ -24,11 +22,4 @@ protected
|
||||
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
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
class RegistrationsController < Devise::RegistrationsController
|
||||
include ApplicationHelper
|
||||
|
||||
#protected
|
||||
def new
|
||||
Apartment::Tenant.switch!
|
||||
@ -9,11 +10,11 @@ class RegistrationsController < Devise::RegistrationsController
|
||||
def create
|
||||
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
|
||||
if user_params[:password] == "" || user_params[:password_confirmation] == ""
|
||||
puts "NO PASSWORD ERROR"
|
||||
flash[:error] = "Need a password to sign up"
|
||||
redirect_to '/signin' and return
|
||||
redirect_to '/signin'
|
||||
return
|
||||
end
|
||||
if params[:company_serial]
|
||||
company = Company.find_by(company_token: params[:company_serial])
|
||||
@ -36,7 +37,12 @@ class RegistrationsController < Devise::RegistrationsController
|
||||
redirect_to '/'
|
||||
else
|
||||
@user.save
|
||||
begin
|
||||
sign_in @user
|
||||
rescue
|
||||
flash[:error] = "Email already in use"
|
||||
redirect_to '/signin' and return
|
||||
end
|
||||
if !@user.admin
|
||||
Apartment::Tenant.switch(Company.find(@user.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
|
||||
end
|
||||
|
||||
@ -6,9 +6,10 @@ class SessionsController < Devise::RegistrationsController
|
||||
end
|
||||
|
||||
def create
|
||||
user_parameters = sign_in_params
|
||||
@user = User.find_by(email: user_parameters[:email])
|
||||
if @user == nil || !@user.valid_password?(user_parameters[:password])
|
||||
puts "NOW IN CREATE"
|
||||
params = sign_in_params
|
||||
@user = User.find_by(email: params[:email])
|
||||
if @user == nil || !@user.valid_password?(params[:password])
|
||||
redirect_to "/signin"
|
||||
return
|
||||
end
|
||||
|
||||
@ -3,6 +3,9 @@ class User < ApplicationRecord
|
||||
has_many :runs
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
|
||||
validates :email, presence: true, uniqueness: true
|
||||
|
||||
devise :database_authenticatable, :registerable,
|
||||
: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.
|
||||
|
||||
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|
|
||||
t.string "company_name"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user