Skip to content

Instantly share code, notes, and snippets.

@mvidaurre
Created January 26, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidaurre/cc57b34354f0a5871f60 to your computer and use it in GitHub Desktop.
Save mvidaurre/cc57b34354f0a5871f60 to your computer and use it in GitHub Desktop.
class Spree::DistributorRegistrationsController < Devise::RegistrationsController
helper 'spree/base', 'spree/store'
if Spree::Auth::Engine.dash_available?
helper 'spree/analytics'
end
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::Order
include Spree::Core::ControllerHelpers::Store
before_filter :check_permissions, :only => [:edit, :update]
skip_before_filter :require_no_authentication
# GET /resource/sign_up
def new
super
@user = resource
resource.bill_address = Spree::Address.build_default
end
# POST /resource/sign_up
def create
@user = build_resource(spree_user_params)
if resource.save
resource.spree_roles << Spree::Role.find_by(name: 'distributor')
set_flash_message(:notice, :signed_up)
sign_in(:spree_user, @user)
session[:spree_user_signup] = true
associate_user
respond_with resource, location: after_sign_up_path_for(resource)
else
clean_up_passwords(resource)
render :new
end
end
# GET /resource/edit
def edit
super
end
# PUT /resource
def update
super
end
# DELETE /resource
def destroy
super
end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
def cancel
super
end
protected
def check_permissions
authorize!(:create, resource)
end
private
def spree_user_params
params.require(:spree_user).permit(Spree::PermittedAttributes.user_attributes, bill_address_attributes: Spree::PermittedAttributes.address_attributes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment