Class: Milia::RegistrationsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



TODO: options if non-standard path for new signups view


create – intercept the POST create action upon new sign-up new tenant account is vetted, then created, then proceed with devise create user CALLBACK: Tenant.create_new_tenant – prior to completing user account CALLBACK: Tenant.tenant_signup – after completing user account



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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/registrations_controller.rb', line 16

def create
    # have a working copy of the params in case Tenant callbacks
    # make any changes
  tenant_params = 
  user_params   = 
  coupon_params = 

  sign_out_session!
     # next two lines prep signup view parameters
  ( tenant_params, user_params, coupon_params )

     # validate recaptcha first unless not enabled
  if !::Milia.use_recaptcha  ||  verify_recaptcha

    Tenant.transaction  do
      @tenant = Tenant.create_new_tenant( tenant_params, user_params, coupon_params)
      if @tenant.errors.empty?   # tenant created

        initiate_tenant( @tenant )    # first time stuff for new tenant

        devise_create( user_params )   # devise resource(user) creation; sets resource

        if resource.errors.empty?   #  SUCCESS!

          log_action( "signup user/tenant success", resource )
            # do any needed tenant initial setup
          Tenant.(resource, @tenant, coupon_params)

        else  # user creation failed; force tenant rollback
          log_action( "signup user create failed", resource )
          raise ActiveRecord::Rollback   # force the tenant transaction to be rolled back
        end  # if..then..else for valid user creation

      else
        resource.valid?
        log_action( "tenant create failed", @tenant )
        render :new
      end # if .. then .. else no tenant errors

    end  #  wrap tenant/user creation in a transaction

  else
    flash[:error] = "Recaptcha codes didn't match; please try again"
       # all validation errors are passed when the sign_up form is re-rendered
    resource.valid?
    @tenant.valid?
    log_action( "recaptcha failed", resource )
    render :new
  end

end