module Milia class RegistrationsController < Devise::RegistrationsController # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ # TODO: options if using recaptcha # 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 # ------------------------------------------------------------------------------ def create sign_out_session! # if verify_recaptcha # ?? does this need: :model => resource ?? Tenant.transaction do @tenant = Tenant.create_new_tenant(params) if @tenant.errors.empty? # tenant created initiate_tenant( @tenant ) # first time stuff for new tenant super # devise resource(user) creation; sets resource if resource.errors.empty? Tenant.tenant_signup(resource, @tenant, params[:coupon]) else # user creation failed; force tenant rollback raise ActiveRecord::Rollback # force the tenant transaction to be rolled back prep_signup_view( @tenant, resource ) render :new end # if..then..else for valid user creation else prep_signup_view( @tenant, params[:user] ) render :new end # if .. then .. else no tenant errors end # wrap tenant/user creation in a transaction # else # flash[:error] = "Recaptcha code error; please re-enter the code and click submit again" # prep_signup_view( params[:tenant], params[:user] ) # render :new # end end # def create # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ private # ------------------------------------------------------------------------------ # sign_out_session! -- force the devise session signout # ------------------------------------------------------------------------------ def sign_out_session!() Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) if user_signed_in? end # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ end # class Registrations end # module Milia