spree_auth 0.30.2 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of spree_auth might be problematic. Click here for more details.

Files changed (42) hide show
  1. data/app/controllers/checkout_controller_decorator.rb +2 -2
  2. data/app/controllers/orders_controller_decorator.rb +4 -3
  3. data/app/controllers/resource_controller_decorator.rb +6 -2
  4. data/app/controllers/spree/base_controller_decorator.rb +8 -25
  5. data/app/controllers/user_password_resets_controller.rb +20 -0
  6. data/app/controllers/user_registrations_controller.rb +56 -0
  7. data/app/controllers/user_sessions_controller.rb +21 -82
  8. data/app/controllers/users_controller.rb +1 -13
  9. data/app/helpers/users_helper.rb +13 -0
  10. data/app/models/ability.rb +4 -4
  11. data/app/models/order_decorator.rb +4 -3
  12. data/app/models/spree_current_order_decorator.rb +1 -1
  13. data/app/models/tokenized_permission.rb +3 -0
  14. data/app/models/user.rb +14 -16
  15. data/app/models/user_mailer.rb +2 -3
  16. data/app/views/checkout/registration.html.erb +1 -1
  17. data/app/views/shared/_error_messages.html.erb +1 -1
  18. data/app/views/shared/_login.html.erb +20 -0
  19. data/app/views/shared/_login_bar.html.erb +1 -1
  20. data/app/views/shared/_user_form.html.erb +17 -0
  21. data/app/views/user_mailer/{password_reset_instructions.erb → reset_password_instructions.text.erb} +0 -0
  22. data/app/views/user_password_resets/edit.html.erb +15 -0
  23. data/app/views/{password_resets → user_password_resets}/new.html.erb +4 -4
  24. data/app/views/{users → user_registrations}/new.html.erb +2 -2
  25. data/app/views/user_sessions/new.html.erb +6 -2
  26. data/app/views/users/edit.html.erb +1 -1
  27. data/config/initializers/devise.rb +136 -0
  28. data/config/locales/en.yml +45 -0
  29. data/config/routes.rb +14 -7
  30. data/db/migrate/20101101185116_rename_columns_for_devise.rb +38 -0
  31. data/db/migrate/20101214150824_convert_user_remember_field.rb +11 -0
  32. data/db/migrate/20101217012656_create_tokenized_permissions.rb +18 -0
  33. data/db/migrate/20101219201531_tokens_for_legacy_orders.rb +12 -0
  34. data/db/sample/users.rb +1 -1
  35. data/lib/spree/token_resource.rb +23 -0
  36. data/lib/spree_auth.rb +13 -2
  37. data/lib/tasks/install.rake +0 -1
  38. metadata +35 -23
  39. data/app/models/user_session.rb +0 -3
  40. data/app/views/password_resets/edit.html.erb +0 -12
  41. data/lib/cancan/controller_additions.rb +0 -60
  42. data/lib/spree/auth_user.rb +0 -16
@@ -1,9 +1,8 @@
1
1
  class UserMailer < ActionMailer::Base
2
2
  default_url_options[:host] = Spree::Config[:site_url]
3
- default :from => Spree::Config[:mails_from]
4
3
 
5
- def password_reset_instructions(user)
6
- @edit_password_reset_url = edit_password_reset_url(user.perishable_token)
4
+ def reset_password_instructions(user)
5
+ @edit_password_reset_url = edit_user_password_url(:reset_password_token => user.reset_password_token)
7
6
  mail(:to => user.email,
8
7
  :subject => Spree::Config[:site_name] + ' ' + I18n.t("password_reset_instructions"))
9
8
  end
@@ -2,7 +2,7 @@
2
2
  <h2><%= t("registration")%></h2>
3
3
  <div id="registration">
4
4
  <div id="account">
5
- <%= render :file => 'users/new' %>
5
+ <%= render :file => 'user_sessions/new' %>
6
6
  </div>
7
7
  <% if Spree::Config[:allow_guest_checkout] %>
8
8
  <div id="guest_checkout">
@@ -7,4 +7,4 @@
7
7
  <% end %>
8
8
  </ul>
9
9
  </div>
10
- <% end %>
10
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <%= form_for(:user, :url => user_session_path) do |f| %>
2
+ <div id='password-credentials'>
3
+ <p>
4
+ <%= f.label(:email, t("email")) %><br />
5
+ <%= f.text_field('email', :class => 'title') %>
6
+ </p>
7
+ <p>
8
+ <%= f.label :password, t("password") %><br />
9
+ <%= f.password_field 'password', :class => 'title' %>
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><%= submit_tag t("log_in"), :class => 'button primary'%></p>
20
+ <% end %>
@@ -1,6 +1,6 @@
1
1
  <% if current_user %>
2
2
  <li><%= link_to t('my_account'), account_path %></li>
3
- <li><%= link_to t('logout'), logout_path %></li>
3
+ <li><%= link_to t('logout'), destroy_user_session_path %></li>
4
4
  <% else %>
5
5
  <li><%= link_to t('log_in'), login_path %></li>
6
6
  <% end %>
@@ -0,0 +1,17 @@
1
+ <p>
2
+ <%= f.label :email, t("email") %><br />
3
+ <%= f.text_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
+ <%= hook :signup_below_password_fields %>
@@ -0,0 +1,15 @@
1
+ <%= render "shared/error_messages", :target => @user %>
2
+ <h1><%= t(:change_my_password) %></h1>
3
+
4
+ <%= form_for @user, :url => user_password_path, :html => {:method => :put} do |f| %>
5
+ <p>
6
+ <%= f.label :password %><br />
7
+ <%= f.password_field :password %><br />
8
+ </p>
9
+ <p>
10
+ <%= f.label :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") %>
15
+ <% end %>
@@ -1,13 +1,13 @@
1
1
  <h1><%= t(:forgot_password) %></h1>
2
2
 
3
3
  <p><%= t(:instructions_to_reset_password) %></p>
4
-
5
- <%= form_tag password_resets_path do %>
4
+
5
+ <%= form_for User.new, :as => :user, :url => user_password_path do |f| %>
6
6
  <p>
7
7
  <label><%= t(:email) %>:</label><br />
8
- <%= text_field_tag "email", params[:email], :size => 30 %>
8
+ <%= f.email_field :email %>
9
9
  </p>
10
10
  <p>
11
- <%= submit_tag t("reset_password") %>
11
+ <%= f.submit t("reset_password") %>
12
12
  </p>
13
13
  <% end %>
@@ -7,7 +7,7 @@
7
7
 
8
8
  <%= hook :signup do %>
9
9
 
10
- <%= form_for(@user) do |f| %>
10
+ <%= form_for(:user, :url => registration_path(@user)) do |f| %>
11
11
 
12
12
  <%= hook :signup_inside_form do %>
13
13
  <%= render 'shared/user_form', :f => f %>
@@ -16,8 +16,8 @@
16
16
 
17
17
  <% end %>
18
18
  <%= t("or") %> <%= link_to t("login_as_existing"), login_path %>
19
-
20
19
  <% end %>
21
20
 
22
21
  </div>
23
22
 
23
+ <%= hook :login_extras %>
@@ -1,9 +1,13 @@
1
+ <% if flash[:alert] %>
2
+ <div class="flash errors"><%= flash[:alert] %></div>
3
+ <% end %>
4
+
1
5
  <% @body_id = 'login' %>
2
6
  <div id="existing-customer">
3
7
  <h2><%= t("login_as_existing") %></h2>
4
8
  <%= hook :login do %>
5
9
  <%= render :partial => 'shared/login' %>
6
- <%= t("or") %> <%= link_to t("create_a_new_account"), signup_path %> | <%= link_to t("forgot_password"), new_password_reset_path %>
10
+ <%= t("or") %> <%= link_to t("create_a_new_account"), signup_path %> | <%= link_to t("forgot_password"), new_user_password_path %>
7
11
  <% end %>
8
12
  </div>
9
-
13
+ <%= hook :login_extras %>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <h1><%= t("editing_user") %></h1>
4
4
 
5
- <% form_for(:user, :url => object_url, :html => { :method => :put }) do |f| %>
5
+ <%= form_for(:user, :url => object_url, :html => { :method => :put }) do |f| %>
6
6
  <%= render 'shared/user_form', :f => f %>
7
7
  <p>
8
8
  <%=submit_tag t("update") %>
@@ -0,0 +1,136 @@
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 = "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 = "Spree 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 = "0bfa9e2cb4a5efd0d976518a3d82e345060547913d2fd1dd2f32b0c8dbbbb5d3dc20b86d0fed31aca9513bccdf51643700ea277d9c64d9ce8ef886bf39293453"
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
+ end
@@ -0,0 +1,45 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ not_found: "not found"
5
+ already_confirmed: "was already confirmed"
6
+ not_locked: "was not locked"
7
+ not_saved:
8
+ one: "1 error prohibited this %{resource} from being saved:"
9
+ other: "%{count} errors prohibited this %{resource} from being saved:"
10
+ devise:
11
+ failure:
12
+ unauthenticated: 'You need to sign in or sign up before continuing.'
13
+ unconfirmed: 'You have to confirm your account before continuing.'
14
+ locked: 'Your account is locked.'
15
+ invalid: 'Invalid email or password.'
16
+ invalid_token: 'Invalid authentication token.'
17
+ timeout: 'Your session expired, please sign in again to continue.'
18
+ inactive: 'Your account was not activated yet.'
19
+ user_password_resets:
20
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
21
+ updated: 'Your password was changed successfully. You are now signed in.'
22
+ confirmations:
23
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
24
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
25
+ user_registrations:
26
+ signed_up: 'Welcome! You have signed up successfully.'
27
+ inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
28
+ updated: 'You updated your account successfully.'
29
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
30
+ user_sessions:
31
+ signed_in: 'Signed in successfully.'
32
+ signed_out: 'Signed out successfully.'
33
+ unlocks:
34
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
35
+ unlocked: 'Your account was successfully unlocked. You are now signed in.'
36
+ oauth_callbacks:
37
+ success: 'Successfully authorized from %{kind} account.'
38
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
39
+ mailer:
40
+ confirmation_instructions:
41
+ subject: 'Confirmation instructions'
42
+ reset_password_instructions:
43
+ subject: 'Reset password instructions'
44
+ unlock_instructions:
45
+ subject: 'Unlock Instructions'
data/config/routes.rb CHANGED
@@ -1,21 +1,28 @@
1
1
  Rails.application.routes.draw do
2
+ devise_for :users,
3
+ :controllers => { :sessions => 'user_sessions',
4
+ :registrations => 'user_registrations',
5
+ :passwords => "user_password_resets"},
6
+ :skip => [:unlocks, :omniauth_callbacks],
7
+ :path_names => { :sign_out => 'logout'}
8
+ resources :users, :only => [:edit, :update]
9
+
10
+ devise_scope :user do
11
+ get "/login" => "user_sessions#new", :as => :login
12
+ get "/signup" => "user_registrations#new", :as => :signup
13
+ end
14
+
2
15
 
3
16
  match '/checkout/registration' => 'checkout#registration', :via => :get, :as => :checkout_registration
4
17
  match '/checkout/registration' => 'checkout#update_registration', :via => :put, :as => :update_checkout_registration
5
18
 
6
- match '/login', :to => 'user_sessions#new', :as => :login
7
- match '/logout', :to => 'user_sessions#destroy', :as => :logout
8
- match '/signup', :to => 'users#new', :as => :signup
9
-
10
19
  match '/orders/:id/token/:token' => 'orders#show', :via => :get, :as => :token_order
11
20
 
12
- resource :user_session do
21
+ resource :session do
13
22
  member do
14
23
  get :nav_bar
15
24
  end
16
25
  end
17
26
  resource :account, :controller => "users"
18
- resources :password_resets
19
- resources :users
20
27
 
21
28
  end
@@ -0,0 +1,38 @@
1
+ class RenameColumnsForDevise < ActiveRecord::Migration
2
+ def self.up
3
+ rename_column :users, :crypted_password, :encrypted_password
4
+ rename_column :users, :salt, :password_salt
5
+ rename_column :users, :remember_token_expires_at, :remember_created_at
6
+ rename_column :users, :login_count, :sign_in_count
7
+ rename_column :users, :failed_login_count, :failed_attempts
8
+ rename_column :users, :single_access_token, :reset_password_token
9
+ rename_column :users, :current_login_at, :current_sign_in_at
10
+ rename_column :users, :last_login_at, :last_sign_in_at
11
+ rename_column :users, :current_login_ip, :current_sign_in_ip
12
+ rename_column :users, :last_login_ip, :last_sign_in_ip
13
+ add_column :users, :authentication_token, :string
14
+ add_column :users, :unlock_token, :string
15
+ add_column :users, :locked_at, :datetime
16
+ remove_column :users, :api_key
17
+ remove_column :users, :openid_identifier
18
+ end
19
+
20
+ def self.down
21
+ remove_column :users, :authentication_token
22
+ remove_column :users, :locked_at
23
+ remove_column :users, :unlock_token
24
+ rename_column :table_name, :new_column_name, :column_name
25
+ rename_column :users, :last_sign_in_ip, :last_login_ip
26
+ rename_column :users, :current_sign_in_ip, :current_login_ip
27
+ rename_column :users, :last_sign_in_at, :last_login_at
28
+ rename_column :users, :current_sign_in_at, :current_login_at
29
+ rename_column :users, :reset_password_token, :single_access_token
30
+ rename_column :users, :failed_attempts, :failed_login_count
31
+ rename_column :users, :sign_in_count, :login_count
32
+ rename_column :users, :remember_created_at, :remember_token_expires_at
33
+ rename_column :users, :password_salt, :salt
34
+ rename_column :users, :encrypted_password, :crypted_password
35
+ add_column :users, :unlock_token, :string
36
+ add_column :users, :openid_identifier, :string
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ class ConvertUserRememberField < ActiveRecord::Migration
2
+ def self.up
3
+ remove_column :users, :remember_created_at
4
+ add_column :users, :remember_created_at, :datetime
5
+ end
6
+
7
+ def self.down
8
+ remove_column :users, :remember_created_at
9
+ add_column :users, :remember_created_at, :string
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ class CreateTokenizedPermissions < ActiveRecord::Migration
2
+
3
+ def self.up
4
+
5
+ create_table :tokenized_permissions do |t|
6
+ t.integer :permissable_id
7
+ t.string :permissable_type
8
+ t.string :token
9
+ t.timestamps
10
+ end
11
+
12
+ add_index "tokenized_permissions", ["permissable_id", "permissable_type"], :name => "index_tokenized_name_and_type"
13
+ end
14
+
15
+ def self.down
16
+ drop_table :tokenized_permissions
17
+ end
18
+ end