Created
March 8, 2014 13:03
-
-
Save axilaris/9430268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Users::RegistrationsController < Devise::RegistrationsController | |
def create | |
logger.info "XXX Users::RegistrationsController create #{params[:company_name]}" | |
build_resource(sign_up_params) | |
if resource.save | |
logger.info "saved user id:#{resource.id}" | |
#xxx check if company name exist | |
@findcompany = Company.where(:name => params[:company_name]) | |
if @findcompany.count(true) > 0 | |
logger.info "found company name:#{params[:company_name]} id:#{@findcompany.first.id}" | |
companyid = @findcompany.first.id | |
roleid = ROLE_USER # user | |
verified_value = false; | |
else | |
@company = Company.new | |
@company.name = params[:company_name] | |
@company.country_id = sign_up_params[:country_id] | |
@company.save | |
companyid = @company.id | |
roleid = ROLE_ADMIN # admin | |
verified_value = true; | |
logger.info "not found company name:#{params[:company_name]} new id:#{companyid}" | |
end | |
@company_user_assoc = CompanyUserAssoc.new | |
@company_user_assoc.user_id = resource.id | |
@company_user_assoc.company_id = companyid | |
@company_user_assoc.role_id = roleid | |
@company_user_assoc.verified = verified_value | |
@company_user_assoc.save | |
#xxx | |
yield resource if block_given? | |
if resource.active_for_authentication? | |
set_flash_message :notice, :signed_up if is_flashing_format? | |
sign_up(resource_name, resource) | |
respond_with resource, location: after_sign_up_path_for(resource) | |
else | |
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? | |
expire_data_after_sign_in! | |
respond_with resource, location: after_inactive_sign_up_path_for(resource) | |
end | |
else | |
clean_up_passwords resource | |
respond_with resource | |
end | |
end | |
def update | |
logger.info "XXX Users::RegistrationsController update" | |
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) | |
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email) | |
if update_resource(resource, account_update_params) | |
yield resource if block_given? | |
if is_flashing_format? | |
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ? | |
:update_needs_confirmation : :updated | |
set_flash_message :notice, flash_key | |
end | |
sign_in resource_name, resource, bypass: true | |
respond_with resource, location: after_update_path_for(resource) | |
else | |
clean_up_passwords resource | |
respond_with resource | |
end | |
end | |
# GET /resource/edit | |
def edit | |
logger.info "XXX Users::RegistrationsController edit" | |
@user = current_user | |
render :edit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment