Usermodel exists in is already a Spree application.
User, but for the purposes of this guide the model we will be referring to will be called
User. If your model is called something else, do some mental substitution wherever you see
Userclass, you must first edit Spree's initializer located at
config/initializers/spree.rbby changing this line:
lib/spree/authentication_helpers.rb) to the
Spree::Core::AuthenticationHelpersmodule inside of Spree.
Userclass as the class that represents users in Spree. Run the new migration by running this:
lib/spree/authentication_helpers.rbcontains the following code to help you do that:
ApplicationControlleradd these lines:
spree_current_userUsed to tell Spree what the current user
spree_login_pathThe location of the login/sign in form in
spree_signup_pathThe location of the sign up form in your
spree_logout_pathThe location of the logout feature of your
logout_pathroutes yourself, by using code like this inside your application's
config/routes.rbif you're using Devise:
devise_scopemethod and change the controllers and actions for these routes.
lib/spree/authentication_helpers.rbto use the routing helper methods already provided by the authentication setup you have, if you wish.
spree_roles. This association will retrieve all the roles that a user has for Spree.
spree_ordersassociation. This will return all orders associated with the user in Spree. There's also a
last_incomplete_spree_ordermethod which will return the last incomplete spree order for the user. This is used internal to Spree to persist order data across a user's login sessions.
has_spree_role?which can be used to check if a user has a specific role. This method is used internally to Spree to check if the user is authorized to perform specific actions, such as accessing the admin section. Admin users of your system should be assigned the Spree admin role, like this:
has_spree_role?method, like this:
true, then the user has admin permissions within Spree.
spree_auth_devisegem is not needed when using an existing application authentication unless the goal is to have two separate authentication methods.