diff --git a/Pearlception/app/controllers/application_controller.rb b/Pearlception/app/controllers/application_controller.rb index 503e8f2..e32a2a1 100644 --- a/Pearlception/app/controllers/application_controller.rb +++ b/Pearlception/app/controllers/application_controller.rb @@ -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 diff --git a/Pearlception/app/controllers/registrations_controller.rb b/Pearlception/app/controllers/registrations_controller.rb index 49b4c31..51ca8db 100644 --- a/Pearlception/app/controllers/registrations_controller.rb +++ b/Pearlception/app/controllers/registrations_controller.rb @@ -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 diff --git a/Pearlception/app/controllers/sessions_controller.rb b/Pearlception/app/controllers/sessions_controller.rb index fdd9dfc..b19f09c 100644 --- a/Pearlception/app/controllers/sessions_controller.rb +++ b/Pearlception/app/controllers/sessions_controller.rb @@ -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 diff --git a/Pearlception/app/models/user.rb b/Pearlception/app/models/user.rb index 1c27f7e..b04846f 100644 --- a/Pearlception/app/models/user.rb +++ b/Pearlception/app/models/user.rb @@ -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 diff --git a/Pearlception/db/migrate/20170329193000_make_user_email_uniq.rb b/Pearlception/db/migrate/20170329193000_make_user_email_uniq.rb new file mode 100644 index 0000000..485f788 --- /dev/null +++ b/Pearlception/db/migrate/20170329193000_make_user_email_uniq.rb @@ -0,0 +1,5 @@ +class MakeUserEmailUniq < ActiveRecord::Migration[5.0] + def change + change_column :users, :email, :string, {unique: true, null: false , default: ""} + end +end diff --git a/Pearlception/db/schema.rb b/Pearlception/db/schema.rb index a2a9051..dcdd10a 100644 --- a/Pearlception/db/schema.rb +++ b/Pearlception/db/schema.rb @@ -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"