spreefinery_core 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/app/controllers/spree/user_passwords_controller.rb +45 -0
- data/app/controllers/spree/user_registrations_controller.rb +65 -0
- data/app/controllers/spree/user_sessions_controller.rb +65 -0
- data/app/controllers/spree/users_controller.rb +51 -0
- data/app/mailers/spree/user_mailer.rb +8 -0
- data/app/overrides/auth_user_login_form.rb +6 -0
- data/app/views/spree/shared/_flashes.html.erb +9 -0
- data/app/views/spree/shared/_login.html.erb +20 -0
- data/app/views/spree/shared/_login_bar.html.erb +6 -0
- data/app/views/spree/shared/_user_form.html.erb +17 -0
- data/app/views/spree/user_mailer/reset_password_instructions.text.erb +10 -0
- data/app/views/spree/user_passwords/edit.html.erb +15 -0
- data/app/views/spree/user_passwords/new.html.erb +15 -0
- data/app/views/spree/user_registrations/new.html.erb +22 -0
- data/app/views/spree/user_sessions/authorization_failure.html.erb +4 -0
- data/app/views/spree/user_sessions/new.html.erb +13 -0
- data/app/views/spree/users/edit.html.erb +11 -0
- data/app/views/spree/users/show.html.erb +43 -0
- data/config/initializers/devise.rb +144 -0
- data/config/initializers/spree.rb +1 -0
- data/config/routes.rb +23 -0
- data/db/migrate/20120830045627_add_spree_fields_to_refinery_users_table.rb +13 -0
- data/lib/spree/authentication_helpers.rb +29 -0
- data/lib/spreefinery_core/engine.rb +30 -0
- data/lib/spreefinery_core.rb +1 -0
- data/spreefinery_core.gemspec +19 -0
- metadata +107 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
[Spree 1.3](http://spreecommerce.com/) has a fantastic pluggable authentication system. This gem configures Spree
|
2
|
+
to use the built in (Devise) authentication in [RefineryCMS](http://refinerycms.com/), and allows you to share
|
3
|
+
authentication between the two engines.
|
4
|
+
|
5
|
+
Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'spreefinery_core', :git => 'git://github.com/shoponrails/spreefinery_core.git'
|
9
|
+
```
|
10
|
+
|
11
|
+
Run bundler, then install Spree
|
12
|
+
|
13
|
+
bundle
|
14
|
+
rails g spree:install
|
15
|
+
|
16
|
+
**Note:** The Spree installer will automatically copy and run a migration from this gem. If you want to copy
|
17
|
+
the migration manually, you can use the following command:
|
18
|
+
|
19
|
+
rake railties:install:migrations FROM=spreefinery_core
|
20
|
+
|
21
|
+
Optionally put this line at the top of config/routes.rb to use RefineryCMS for your home page:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
root :to => "refinery/pages#home"
|
25
|
+
```
|
26
|
+
|
27
|
+
Start your application, and create a RefineryCMS user. You can then make yourself a Spree admin using the Rails console:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
rails console
|
31
|
+
> Refinery::User.first.spree_roles << Spree::Role.find_or_create_by_name("admin")
|
32
|
+
```
|
33
|
+
|
34
|
+
All done! You should now be able to access Refinery at [http://localhost:3000/refinery](http://localhost:3000/refinery) and Spree at [http://localhost:3000/admin](http://localhost:3000/admin).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Spree::UserPasswordsController < Devise::PasswordsController
|
2
|
+
include SslRequirement
|
3
|
+
helper 'spree/base'
|
4
|
+
|
5
|
+
if defined?(Spree::Dash)
|
6
|
+
helper 'spree/analytics'
|
7
|
+
end
|
8
|
+
|
9
|
+
include Spree::Core::ControllerHelpers
|
10
|
+
|
11
|
+
ssl_required
|
12
|
+
|
13
|
+
layout Refinery::Themes::Theme.default_layout
|
14
|
+
|
15
|
+
# Overridden due to bug in Devise.
|
16
|
+
# respond_with resource, :location => new_session_path(resource_name)
|
17
|
+
# is generating bad url /session/new.user
|
18
|
+
#
|
19
|
+
# overridden to:
|
20
|
+
# respond_with resource, :location => spree.login_path
|
21
|
+
#
|
22
|
+
def create
|
23
|
+
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
24
|
+
|
25
|
+
if resource.errors.empty?
|
26
|
+
set_flash_message(:notice, :send_instructions) if is_navigational_format?
|
27
|
+
respond_with resource, :location => spree.login_path
|
28
|
+
else
|
29
|
+
respond_with_navigational(resource) { render :new }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Devise::PasswordsController allows for blank passwords.
|
34
|
+
# Silly Devise::PasswordsController!
|
35
|
+
# Fixes spree/spree#2190.
|
36
|
+
def update
|
37
|
+
if params[:user][:password].blank?
|
38
|
+
set_flash_message(:error, :cannot_be_blank)
|
39
|
+
render :edit
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Spree::UserRegistrationsController < Devise::RegistrationsController
|
2
|
+
include SslRequirement
|
3
|
+
helper 'spree/base'
|
4
|
+
|
5
|
+
if defined?(Spree::Dash)
|
6
|
+
helper 'spree/analytics'
|
7
|
+
end
|
8
|
+
|
9
|
+
include Spree::Core::ControllerHelpers
|
10
|
+
ssl_required
|
11
|
+
before_filter :check_permissions, :only => [:edit, :update]
|
12
|
+
skip_before_filter :require_no_authentication
|
13
|
+
|
14
|
+
layout Refinery::Themes::Theme.default_layout
|
15
|
+
|
16
|
+
# GET /resource/sign_up
|
17
|
+
def new
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
# POST /resource/sign_up
|
22
|
+
def create
|
23
|
+
@user = build_resource(params[:user])
|
24
|
+
if resource.save
|
25
|
+
set_flash_message(:notice, :signed_up)
|
26
|
+
sign_in(:user, @user)
|
27
|
+
session[:spree_user_signup] = true
|
28
|
+
associate_user
|
29
|
+
sign_in_and_redirect(:user, @user)
|
30
|
+
else
|
31
|
+
clean_up_passwords(resource)
|
32
|
+
render :new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# GET /resource/edit
|
37
|
+
def edit
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
# PUT /resource
|
42
|
+
def update
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
# DELETE /resource
|
47
|
+
def destroy
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
# GET /resource/cancel
|
52
|
+
# Forces the session data which is usually expired after sign
|
53
|
+
# in to be expired now. This is useful if the user wants to
|
54
|
+
# cancel oauth signing in/up in the middle of the process,
|
55
|
+
# removing all OAuth session data.
|
56
|
+
def cancel
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
def check_permissions
|
62
|
+
authorize!(:create, resource)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Spree::UserSessionsController < Devise::SessionsController
|
2
|
+
include SslRequirement
|
3
|
+
helper 'spree/base'
|
4
|
+
if defined?(Spree::Dash)
|
5
|
+
helper 'spree/analytics'
|
6
|
+
end
|
7
|
+
|
8
|
+
include Spree::Core::ControllerHelpers
|
9
|
+
|
10
|
+
ssl_required :new, :create, :destroy, :update
|
11
|
+
ssl_allowed :login_bar
|
12
|
+
|
13
|
+
layout Refinery::Themes::Theme.default_layout
|
14
|
+
|
15
|
+
# GET /resource/sign_in
|
16
|
+
def new
|
17
|
+
@user = Refinery::User.new
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
#def create
|
22
|
+
# super
|
23
|
+
#rescue ::BCrypt::Errors::InvalidSalt, ::BCrypt::Errors::InvalidHash
|
24
|
+
# flash[:error] = t('password_encryption', :scope => 'refinery.users.forgot')
|
25
|
+
# redirect_to refinery.new_refinery_user_password_path
|
26
|
+
#end
|
27
|
+
|
28
|
+
|
29
|
+
def create
|
30
|
+
#super
|
31
|
+
authenticate_refinery_user!
|
32
|
+
|
33
|
+
if refinery_user_signed_in?
|
34
|
+
respond_to do |format|
|
35
|
+
format.html {
|
36
|
+
flash[:success] = t(:logged_in_succesfully)
|
37
|
+
redirect_back_or_default(after_sign_in_path_for(current_refinery_user))
|
38
|
+
}
|
39
|
+
format.js {
|
40
|
+
user = resource.record
|
41
|
+
render :json => {:ship_address => user.ship_address, :bill_address => user.bill_address}.to_json
|
42
|
+
}
|
43
|
+
end
|
44
|
+
else
|
45
|
+
flash.now[:error] = t('devise.failure.invalid')
|
46
|
+
render :new
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def destroy
|
51
|
+
cookies.clear
|
52
|
+
session.clear
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def accurate_title
|
58
|
+
t(:login)
|
59
|
+
end
|
60
|
+
|
61
|
+
def redirect_back_or_default(default)
|
62
|
+
redirect_to(session["user_return_to"] || default)
|
63
|
+
session["user_return_to"] = nil
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Spree::UsersController < Spree::StoreController
|
2
|
+
ssl_required
|
3
|
+
skip_before_filter :set_current_order, :only => :show
|
4
|
+
prepend_before_filter :load_object, :only => [:show, :edit, :update]
|
5
|
+
prepend_before_filter :authorize_actions, :only => :new
|
6
|
+
|
7
|
+
def show
|
8
|
+
@orders = @user.orders.complete
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@user = Refinery::User.new(params[:user])
|
13
|
+
if @user.save
|
14
|
+
|
15
|
+
if current_order
|
16
|
+
session[:guest_token] = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
redirect_back_or_default(root_url)
|
20
|
+
else
|
21
|
+
render :new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
if @user.update_attributes(params[:user])
|
27
|
+
if params[:user][:password].present?
|
28
|
+
# this logic needed b/c devise wants to log us out after password changes
|
29
|
+
user = Refinery::User.reset_password_by_token(params[:user])
|
30
|
+
sign_in(@user, :event => :authentication, :bypass => !Spree::Auth::Config[:signout_after_password_change])
|
31
|
+
end
|
32
|
+
redirect_to spree.account_url, :notice => t(:account_updated)
|
33
|
+
else
|
34
|
+
render :edit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def load_object
|
40
|
+
@user ||= current_refinery_user
|
41
|
+
authorize! params[:action].to_sym, @user
|
42
|
+
end
|
43
|
+
|
44
|
+
def authorize_actions
|
45
|
+
authorize! params[:action].to_sym, Refinery::User.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def accurate_title
|
49
|
+
t(:my_account)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Spree::UserMailer < ActionMailer::Base
|
2
|
+
def reset_password_instructions(user)
|
3
|
+
@edit_password_reset_url = spree.edit_user_password_url(:reset_password_token => user.reset_password_token)
|
4
|
+
|
5
|
+
mail(:to => user.email,
|
6
|
+
:subject => Spree::Config[:site_name] + ' ' + I18n.t(:password_reset_instructions))
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Deface::Override.new(:virtual_path => "spree/checkout/registration",
|
2
|
+
:name => "auth_user_login_form",
|
3
|
+
:replace_contents => "[data-hook='registration'] #account, #registration[data-hook] #account",
|
4
|
+
:template => "spree/user_sessions/new",
|
5
|
+
:disabled => false,
|
6
|
+
:original => 'ab20ac9e90baa11b847b30040aef863d2e1af17a')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%= form_for :refinery_user, :url => spree.user_session_path do |f| %>
|
2
|
+
<div id="password-credentials">
|
3
|
+
<p>
|
4
|
+
<%= f.label :login, t(:login) %><br />
|
5
|
+
<%= f.text_field :login, :class => 'title', :tabindex => 1 %>
|
6
|
+
</p>
|
7
|
+
<p>
|
8
|
+
<%= f.label :password, t(:password) %><br />
|
9
|
+
<%= f.password_field :password, :class => 'title', :tabindex => 2 %>
|
10
|
+
</p>
|
11
|
+
</div>
|
12
|
+
<p>
|
13
|
+
<label>
|
14
|
+
<%= f.check_box :remember_me %>
|
15
|
+
<%= f.label :remember_me, t(:remember_me) %>
|
16
|
+
</label>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p><%= f.submit t(:login), :class => 'button primary', :tabindex => 3 %></p>
|
20
|
+
<% end %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<p>
|
2
|
+
<%= f.label :email, t(:email) %><br />
|
3
|
+
<%= f.email_field :email, :class => 'title' %>
|
4
|
+
</p>
|
5
|
+
<div id="password-credentials">
|
6
|
+
<p>
|
7
|
+
<%= f.label :password, t(:password) %><br />
|
8
|
+
<%= f.password_field :password, :class => 'title' %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<%= f.label :password_confirmation, t(:confirm_password) %><br />
|
13
|
+
<%= f.password_field :password_confirmation, :class => 'title' %>
|
14
|
+
</p>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div data-hook="signup_below_password_fields"></div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
A request to reset your password has been made.
|
2
|
+
If you did not make this request, simply ignore this email.
|
3
|
+
|
4
|
+
If you did make this request just click the link below:
|
5
|
+
|
6
|
+
<%= @edit_password_reset_url %>
|
7
|
+
|
8
|
+
If the above URL does not work try copying and pasting it into your browser.
|
9
|
+
If you continue to have problem please feel free to contact us.
|
10
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
|
2
|
+
<h2><%= t(:change_my_password) %></h2>
|
3
|
+
|
4
|
+
<%= form_for @user, :url => spree.user_password_path, :method => :put do |f| %>
|
5
|
+
<p>
|
6
|
+
<%= f.label :password, t(:password) %><br />
|
7
|
+
<%= f.password_field :password %><br />
|
8
|
+
</p>
|
9
|
+
<p>
|
10
|
+
<%= f.label :password_confirmation, t(:password_confirmation) %><br />
|
11
|
+
<%= f.password_field :password_confirmation %><br />
|
12
|
+
</p>
|
13
|
+
<%= f.hidden_field :reset_password_token %>
|
14
|
+
<%= f.submit t(:update_password), :class => 'button primary' %>
|
15
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div id="forgot-password">
|
2
|
+
<h6><%= t(:forgot_password) %></h6>
|
3
|
+
|
4
|
+
<p><%= t(:instructions_to_reset_password) %></p>
|
5
|
+
|
6
|
+
<%= form_for Refinery::User.new, :as => :user, :url => spree.user_password_path do |f| %>
|
7
|
+
<p>
|
8
|
+
<%= f.label :email, t(:email) %><br />
|
9
|
+
<%= f.email_field :email %>
|
10
|
+
</p>
|
11
|
+
<p>
|
12
|
+
<%= f.submit t(:reset_password), :class => 'button primary' %>
|
13
|
+
</p>
|
14
|
+
<% end %>
|
15
|
+
</div>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<% @body_id = 'signup' %>
|
2
|
+
|
3
|
+
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
|
4
|
+
|
5
|
+
<div id="new-customer">
|
6
|
+
<h6><%= t(:new_customer) %></h6>
|
7
|
+
|
8
|
+
<div data-hook="signup">
|
9
|
+
|
10
|
+
<%= form_for :user, :url => spree.user_registration_path(@user) do |f| %>
|
11
|
+
<div data-hook="signup_inside_form">
|
12
|
+
<%= render :partial => 'spree/shared/user_form', :locals => { :f => f } %>
|
13
|
+
<p><%= f.submit t(:create), :class => 'button primary' %></p>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
<%= t(:or) %> <%= link_to t(:login_as_existing), spree.login_path %>
|
17
|
+
|
18
|
+
</div>
|
19
|
+
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div data-hook="login_extras"></div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% if flash[:alert] %>
|
2
|
+
<div class="flash errors"><%= flash[:alert] %></div>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% @body_id = 'login' %>
|
6
|
+
<div id="existing-customer">
|
7
|
+
<h6><%= t(:login_as_existing) %></h6>
|
8
|
+
<div data-hook="login">
|
9
|
+
<%= render :partial => 'spree/shared/login' %>
|
10
|
+
<%= t(:or) %> <%= link_to t(:create_a_new_account), spree.signup_path %> | <%= link_to t(:forgot_password), spree.new_user_password_path %>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
<div data-hook="login_extras"></div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
|
2
|
+
|
3
|
+
<h1><%= t(:editing_user) %></h1>
|
4
|
+
|
5
|
+
<%= form_for @user, :url => spree.user_path(@user), :method => :put do |f| %>
|
6
|
+
<%= render :partial => 'spree/shared/user_form', :locals => { :f => f } %>
|
7
|
+
<p>
|
8
|
+
<%= f.submit t(:update), :class => 'button primary' %>
|
9
|
+
</p>
|
10
|
+
<% end %>
|
11
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<h1><%= accurate_title %></h1>
|
2
|
+
|
3
|
+
<div data-hook="account_summary" class="account-summary">
|
4
|
+
<dl id="user-info">
|
5
|
+
<dt><%= t(:email) %></dt>
|
6
|
+
<dd><%= @user.email %> (<%= link_to t(:edit), spree.edit_account_path %>)</dd>
|
7
|
+
</dl>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div data-hook="account_my_orders" class="account-my-orders">
|
11
|
+
|
12
|
+
<h3><%= t(:my_orders) %></h3>
|
13
|
+
<% if @orders.present? %>
|
14
|
+
<table class="order-summary">
|
15
|
+
<thead>
|
16
|
+
<tr>
|
17
|
+
<th class="order-number"><%= t(:order_number) %></th>
|
18
|
+
<th class="order-date"><%= t(:order_date) %></th>
|
19
|
+
<th class="order-status"><%= t(:status) %></th>
|
20
|
+
<th class="order-payment-state"><%= t(:payment_state) %></th>
|
21
|
+
<th class="order-shipment-state"><%= t(:shipment_state) %></th>
|
22
|
+
<th class="order-total"><%= t(:total) %></th>
|
23
|
+
</tr>
|
24
|
+
</thead>
|
25
|
+
<tbody>
|
26
|
+
<% @orders.each do |order| %>
|
27
|
+
<tr class="<%= cycle('even', 'odd') %>">
|
28
|
+
<td class="order-number"><%= link_to order.number, order_url(order) %></td>
|
29
|
+
<td class="order-date"><%= l order.completed_at.to_date %></td>
|
30
|
+
<td class="order-status"><%= t(order.state).titleize %></td>
|
31
|
+
<td class="order-payment-state"><%= t("payment_states.#{order.payment_state}") if order.payment_state %></td>
|
32
|
+
<td class="order-shipment-state"><%= t("shipment_states.#{order.shipment_state}") if order.shipment_state %></td>
|
33
|
+
<td class="order-total"><%= money order.total %></td>
|
34
|
+
</tr>
|
35
|
+
<% end %>
|
36
|
+
</tbody>
|
37
|
+
</table>
|
38
|
+
<% else %>
|
39
|
+
<p><%= t(:you_have_no_orders_yet) %></p>
|
40
|
+
<% end %>
|
41
|
+
<br />
|
42
|
+
|
43
|
+
</div>
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
2
|
+
# four configuration values can also be set straight in your models.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# ==> Mailer Configuration
|
5
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
6
|
+
config.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
7
|
+
|
8
|
+
# Configure the class responsible to send e-mails.
|
9
|
+
config.mailer = 'Spree::UserMailer'
|
10
|
+
|
11
|
+
# ==> ORM configuration
|
12
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
13
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
14
|
+
# available as additional gems.
|
15
|
+
require 'devise/orm/active_record'
|
16
|
+
|
17
|
+
# ==> Configuration for any authentication mechanism
|
18
|
+
# Configure which keys are used when authenticating an user. By default is
|
19
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
20
|
+
# authenticating an user, both parameters are required. Remember that those
|
21
|
+
# parameters are used only when authenticating and not when retrieving from
|
22
|
+
# session. If you need permissions, you should implement that in a before filter.
|
23
|
+
# config.authentication_keys = [ :email ]
|
24
|
+
|
25
|
+
# Tell if authentication through request.params is enabled. True by default.
|
26
|
+
# config.params_authenticatable = true
|
27
|
+
|
28
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
29
|
+
config.http_authenticatable = true
|
30
|
+
|
31
|
+
# Set this to true to use Basic Auth for AJAX requests. True by default.
|
32
|
+
#config.http_authenticatable_on_xhr = false
|
33
|
+
|
34
|
+
# The realm used in Http Basic Authentication
|
35
|
+
config.http_authentication_realm = 'Spreefinery Application'
|
36
|
+
|
37
|
+
# ==> Configuration for :database_authenticatable
|
38
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
39
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
40
|
+
config.stretches = 20
|
41
|
+
|
42
|
+
# Setup a pepper to generate the encrypted password.
|
43
|
+
config.pepper = Rails.configuration.secret_token
|
44
|
+
|
45
|
+
# ==> Configuration for :confirmable
|
46
|
+
# The time you want to give your user to confirm his account. During this time
|
47
|
+
# he will be able to access your application without confirming. Default is nil.
|
48
|
+
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
49
|
+
# You can use this to let your user access some features of your application
|
50
|
+
# without confirming the account, but blocking it after a certain period
|
51
|
+
# (ie 2 days).
|
52
|
+
# config.confirm_within = 2.days
|
53
|
+
|
54
|
+
# ==> Configuration for :rememberable
|
55
|
+
# The time the user will be remembered without asking for credentials again.
|
56
|
+
# config.remember_for = 2.weeks
|
57
|
+
|
58
|
+
# If true, a valid remember token can be re-used between multiple browsers.
|
59
|
+
# config.remember_across_browsers = true
|
60
|
+
|
61
|
+
# If true, extends the user's remember period when remembered via cookie.
|
62
|
+
# config.extend_remember_period = false
|
63
|
+
|
64
|
+
# ==> Configuration for :validatable
|
65
|
+
# Range for password length
|
66
|
+
# config.password_length = 6..20
|
67
|
+
|
68
|
+
# Regex to use to validate the email address
|
69
|
+
config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
70
|
+
|
71
|
+
# ==> Configuration for :timeoutable
|
72
|
+
# The time you want to timeout the user session without activity. After this
|
73
|
+
# time the user will be asked for credentials again.
|
74
|
+
# config.timeout_in = 10.minutes
|
75
|
+
|
76
|
+
# ==> Configuration for :lockable
|
77
|
+
# Defines which strategy will be used to lock an account.
|
78
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
79
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
80
|
+
# config.lock_strategy = :failed_attempts
|
81
|
+
|
82
|
+
# Defines which strategy will be used to unlock an account.
|
83
|
+
# :email = Sends an unlock link to the user email
|
84
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
85
|
+
# :both = Enables both strategies
|
86
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
87
|
+
# config.unlock_strategy = :both
|
88
|
+
|
89
|
+
# Number of authentication tries before locking an account if lock_strategy
|
90
|
+
# is failed attempts.
|
91
|
+
# config.maximum_attempts = 20
|
92
|
+
|
93
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
94
|
+
# config.unlock_in = 1.hour
|
95
|
+
|
96
|
+
# ==> Configuration for :token_authenticatable
|
97
|
+
# Defines name of the authentication token params key
|
98
|
+
config.token_authentication_key = :auth_token
|
99
|
+
|
100
|
+
# ==> Scopes configuration
|
101
|
+
# Turn scoped views on. Before rendering 'sessions/new', it will first check for
|
102
|
+
# 'users/sessions/new'. It's turned off by default because it's slower if you
|
103
|
+
# are using only default views.
|
104
|
+
# config.scoped_views = true
|
105
|
+
|
106
|
+
# Configure the default scope given to Warden. By default it's the first
|
107
|
+
# devise role declared in your routes.
|
108
|
+
# config.default_scope = :user
|
109
|
+
|
110
|
+
# Configure sign_out behavior.
|
111
|
+
# By default sign_out is scoped (i.e. /users/sign_out affects only :user scope).
|
112
|
+
# In case of sign_out_all_scopes set to true any logout action will sign out all active scopes.
|
113
|
+
# config.sign_out_all_scopes = false
|
114
|
+
|
115
|
+
# ==> Navigation configuration
|
116
|
+
# Lists the formats that should be treated as navigational. Formats like
|
117
|
+
# :html, should redirect to the sign in page when the user does not have
|
118
|
+
# access, but formats like :xml or :json, should return 401.
|
119
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
120
|
+
# should add them to the navigational formats lists. Default is [:html]
|
121
|
+
config.navigational_formats = [:html, :json, :xml]
|
122
|
+
|
123
|
+
# ==> Warden configuration
|
124
|
+
# If you want to use other strategies, that are not (yet) supported by Devise,
|
125
|
+
# you can configure them inside the config.warden block. The example below
|
126
|
+
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
127
|
+
#
|
128
|
+
# config.warden do |manager|
|
129
|
+
# manager.oauth(:twitter) do |twitter|
|
130
|
+
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
|
131
|
+
# twitter.consumer_key = <YOUR CONSUMER KEY>
|
132
|
+
# twitter.options :site => 'http://twitter.com'
|
133
|
+
# end
|
134
|
+
# manager.default_strategies(:scope => :user).unshift :twitter_oauth
|
135
|
+
# end
|
136
|
+
#
|
137
|
+
# Time interval you can reset your password with a reset password key.
|
138
|
+
# Don't put a too small interval or your users won't have the time to
|
139
|
+
# change their passwords.
|
140
|
+
config.reset_password_within = 6.hours
|
141
|
+
config.sign_out_via = :get
|
142
|
+
|
143
|
+
config.case_insensitive_keys = [:email]
|
144
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Spree.user_class = "Refinery::User"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Spree::Core::Engine.routes.draw do
|
2
|
+
devise_for :user,
|
3
|
+
:class_name => 'Refinery::User',
|
4
|
+
:controllers => { :sessions => 'spree/user_sessions',
|
5
|
+
:registrations => 'spree/user_registrations',
|
6
|
+
:passwords => 'spree/user_passwords' },
|
7
|
+
:skip => [:unlocks, :omniauth_callbacks],
|
8
|
+
:path_names => { :sign_out => 'logout' }
|
9
|
+
end
|
10
|
+
|
11
|
+
Spree::Core::Engine.routes.prepend do
|
12
|
+
resources :users, :only => [:edit, :update]
|
13
|
+
|
14
|
+
devise_scope :user do
|
15
|
+
get '/login' => 'user_sessions#new', :as => :login
|
16
|
+
get '/signup' => 'user_registrations#new', :as => :signup
|
17
|
+
end
|
18
|
+
|
19
|
+
match '/checkout/registration' => 'checkout#registration', :via => :get, :as => :checkout_registration
|
20
|
+
match '/checkout/registration' => 'checkout#update_registration', :via => :put, :as => :update_checkout_registration
|
21
|
+
|
22
|
+
resource :account, :controller => 'users'
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class AddSpreeFieldsToRefineryUsersTable < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column(:refinery_users, :spree_api_key, :string, :limit => 48) unless column_exists?(:refinery_users, :spree_api_key)
|
4
|
+
add_column(:refinery_users, :ship_address_id, :integer) unless column_exists?(:refinery_users, :ship_address_id)
|
5
|
+
add_column(:refinery_users, :bill_address_id, :integer) unless column_exists?(:refinery_users, :bill_address_id)
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
remove_column(:refinery_users, :spree_api_key)
|
10
|
+
remove_column(:refinery_users, :ship_address_id)
|
11
|
+
remove_column(:refinery_users, :bill_address_id)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spree
|
2
|
+
module AuthenticationHelpers
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.send :helper_method, :spree_login_path
|
5
|
+
receiver.send :helper_method, :spree_signup_path
|
6
|
+
receiver.send :helper_method, :spree_logout_path
|
7
|
+
receiver.send :helper_method, :spree_current_user
|
8
|
+
|
9
|
+
# ensure refinery_user? helper method is always available
|
10
|
+
receiver.send :helper_method, :refinery_user?
|
11
|
+
end
|
12
|
+
|
13
|
+
def spree_current_user
|
14
|
+
current_refinery_user
|
15
|
+
end
|
16
|
+
|
17
|
+
def spree_login_path
|
18
|
+
refinery.new_refinery_user_session_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def spree_signup_path
|
22
|
+
refinery.new_refinery_user_registration_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def spree_logout_path
|
26
|
+
refinery.destroy_refinery_user_session_path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spree/authentication_helpers"
|
2
|
+
|
3
|
+
module SpreefineryCore
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
require 'spree_core'
|
6
|
+
require 'refinerycms-core'
|
7
|
+
|
8
|
+
isolate_namespace SpreefineryCore::Engine
|
9
|
+
engine_name "spreefinery_core"
|
10
|
+
|
11
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
12
|
+
|
13
|
+
config.to_prepare do
|
14
|
+
Spree.user_class = "Refinery::User"
|
15
|
+
|
16
|
+
WillPaginate::ActiveRecord::RelationMethods.send :alias_method, :per, :per_page
|
17
|
+
WillPaginate::ActiveRecord::RelationMethods.send :alias_method, :num_pages, :total_pages
|
18
|
+
|
19
|
+
ApplicationController.send :include, Spree::AuthenticationHelpers
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.activate
|
23
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
24
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
config.to_prepare &method(:activate).to_proc
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "spreefinery_core/engine"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "spreefinery_core"
|
5
|
+
gem.version = "0.0.1"
|
6
|
+
gem.authors = ["Alexander Negoda, Zee Yang"]
|
7
|
+
gem.email = ["alexander.negoda@gmail.com, zee.yang@gmail.com"]
|
8
|
+
gem.description = "Spree + Refinerycms integration"
|
9
|
+
gem.summary = "Common functionality for Spree + Refinerycms integration"
|
10
|
+
gem.homepage = "https://github.com/shoponrails/spreefinery_core"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($/)
|
13
|
+
gem.test_files = gem.files.grep(%r{^spec/})
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.required_ruby_version = '>= 1.9.3'
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'spree', '>= 1.3.0'
|
18
|
+
gem.add_runtime_dependency 'refinerycms', '>= 2.0.9'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spreefinery_core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Negoda, Zee Yang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: spree
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: refinerycms
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.0.9
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.9
|
46
|
+
description: Spree + Refinerycms integration
|
47
|
+
email:
|
48
|
+
- alexander.negoda@gmail.com, zee.yang@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- app/controllers/spree/user_passwords_controller.rb
|
58
|
+
- app/controllers/spree/user_registrations_controller.rb
|
59
|
+
- app/controllers/spree/user_sessions_controller.rb
|
60
|
+
- app/controllers/spree/users_controller.rb
|
61
|
+
- app/mailers/spree/user_mailer.rb
|
62
|
+
- app/overrides/auth_user_login_form.rb
|
63
|
+
- app/views/spree/shared/_flashes.html.erb
|
64
|
+
- app/views/spree/shared/_login.html.erb
|
65
|
+
- app/views/spree/shared/_login_bar.html.erb
|
66
|
+
- app/views/spree/shared/_user_form.html.erb
|
67
|
+
- app/views/spree/user_mailer/reset_password_instructions.text.erb
|
68
|
+
- app/views/spree/user_passwords/edit.html.erb
|
69
|
+
- app/views/spree/user_passwords/new.html.erb
|
70
|
+
- app/views/spree/user_registrations/new.html.erb
|
71
|
+
- app/views/spree/user_sessions/authorization_failure.html.erb
|
72
|
+
- app/views/spree/user_sessions/new.html.erb
|
73
|
+
- app/views/spree/users/edit.html.erb
|
74
|
+
- app/views/spree/users/show.html.erb
|
75
|
+
- config/initializers/devise.rb
|
76
|
+
- config/initializers/spree.rb
|
77
|
+
- config/routes.rb
|
78
|
+
- db/migrate/20120830045627_add_spree_fields_to_refinery_users_table.rb
|
79
|
+
- lib/spree/authentication_helpers.rb
|
80
|
+
- lib/spreefinery_core.rb
|
81
|
+
- lib/spreefinery_core/engine.rb
|
82
|
+
- spreefinery_core.gemspec
|
83
|
+
homepage: https://github.com/shoponrails/spreefinery_core
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.9.3
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.24
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Common functionality for Spree + Refinerycms integration
|
107
|
+
test_files: []
|