Class: RegistrationsController

Inherits:
Devise::RegistrationsController
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/controllers/registrations_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#devise_mapping, #resource, #resource_name

Instance Method Details

#createObject

Method to create a new User



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/registrations_controller.rb', line 10

def create
  user_params = 
  @user = User.new(user_params)
  if user_params[:password] == "" || user_params[:password_confirmation] == ""
      puts "NO PASSWORD ERROR"
      flash[:error] = "Need a password to sign up"
      redirect_to '/signin'
      return 
  end
  if params[:company_serial]
    company = Company.find_by(company_token: params[:company_serial])
    if company
      @user.company_id = company.id
      if company.company_name == "IVA"
        @user.admin = true
      end
    else
      flash[:alert] = "The serial key provided was invalid."
      redirect_to '/signin'
    end
  else
    flash[:alert] = "A company serial key must be provided to register."
    redirect_to '/signin'
  end

  if @user == ""
    flash[:alert] = "Please provide a password to register with."
    redirect_to '/signin'
  else
    @user.save
    begin
       @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
    redirect_to "/pearlception" and return
  end
  
end

#newObject

protected



5
6
7
# File 'app/controllers/registrations_controller.rb', line 5

def new
    Apartment::Tenant.switch!
end