spree_auth_devise 4.1.0 → 4.3.3
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_devise might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gem_release.yml +2 -0
- data/.travis.yml +32 -23
- data/Appraisals +1 -1
- data/Gemfile +1 -0
- data/Rakefile +9 -3
- data/app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb +20 -0
- data/app/controllers/spree/api/v2/storefront/passwords_controller.rb +35 -0
- data/app/controllers/spree/user_confirmations_controller.rb +22 -0
- data/app/controllers/spree/user_passwords_controller.rb +15 -1
- data/app/controllers/spree/user_registrations_controller.rb +15 -0
- data/app/controllers/spree/user_sessions_controller.rb +8 -0
- data/app/mailers/spree/user_mailer.rb +11 -4
- data/app/models/spree/user.rb +46 -0
- data/app/services/spree/account/create.rb +19 -0
- data/app/services/spree/account/update.rb +17 -0
- data/app/views/spree/user_mailer/confirmation_instructions.html.erb +20 -0
- data/app/views/spree/user_mailer/confirmation_instructions.text.erb +8 -5
- data/app/views/spree/user_mailer/reset_password_instructions.html.erb +20 -0
- data/app/views/spree/user_mailer/reset_password_instructions.text.erb +7 -5
- data/config/initializers/warden.rb +1 -1
- data/config/locales/de.yml +16 -0
- data/config/locales/en.yml +18 -5
- data/config/locales/zh-TW.yml +58 -0
- data/config/routes.rb +13 -1
- data/gemfiles/spree_4_1.gemfile +1 -1
- data/lib/controllers/api/spree/api/v2/storefront/account_controller_decorator.rb +41 -0
- data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +16 -0
- data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +2 -1
- data/lib/spree/auth/engine.rb +15 -10
- data/lib/spree/auth/version.rb +9 -0
- data/lib/spree_auth_devise.rb +0 -1
- data/lib/views/backend/spree/admin/user_sessions/new.html.erb +1 -1
- data/spec/controllers/spree/api/v2/storefront/passwords_controller_spec.rb +63 -0
- data/spec/features/admin/sign_in_spec.rb +10 -3
- data/spec/features/checkout_spec.rb +3 -3
- data/spec/features/confirmation_spec.rb +2 -5
- data/spec/features/sign_in_spec.rb +15 -8
- data/spec/features/sign_out_spec.rb +1 -3
- data/spec/mailers/user_mailer_spec.rb +3 -3
- data/spec/models/user_spec.rb +43 -10
- data/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +48 -0
- data/spec/requests/spree/api/v2/storefront/account_spec.rb +101 -0
- data/spec/spec_helper.rb +7 -38
- data/spec/support/confirm_helpers.rb +21 -8
- data/spree_auth_devise.gemspec +16 -29
- metadata +32 -362
- data/app/overrides/spree/admin/shared/_header/auth_admin_login_navigation_bar.html.erb.deface +0 -4
- data/spec/support/add_to_cart.rb +0 -22
- data/spec/support/authentication_helpers.rb +0 -14
- data/spec/support/cache_helpers.rb +0 -5
- data/spec/support/capybara.rb +0 -23
- data/spec/support/database_cleaner.rb +0 -17
- data/spec/support/factory_girl.rb +0 -5
- data/spec/support/spree.rb +0 -10
- data/spec/support/user_helper.rb +0 -11
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
<%= @confirmation_url %>
|
1
|
+
<%= Spree.t('user_mailer.confirmation_instructions.welcome', email: @email) %>
|
2
|
+
<%= Spree.t('user_mailer.confirmation_instructions.instructions_1', { store_name: @current_store.name }) %>
|
3
|
+
<%= Spree.t('user_mailer.confirmation_instructions.instructions_2') %>
|
4
|
+
<%= Spree.t('user_mailer.confirmation_instructions.button') %>
|
5
|
+
<%= @confirmation_url %>
|
6
|
+
<%= Spree.t('user_mailer.confirmation_instructions.instructions_3') %>
|
7
|
+
<%= Spree.t('user_mailer.confirmation_instructions.thanks') %>
|
8
|
+
<%= Spree.t('user_mailer.confirmation_instructions.store_team', { store_name: @current_store.name }) %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<h1>
|
2
|
+
<%= Spree.t('user_mailer.reset_password_instructions.welcome', email: @user.email) %>
|
3
|
+
</h1>
|
4
|
+
<p>
|
5
|
+
<%= Spree.t('user_mailer.reset_password_instructions.instructions_1', { store_name: @current_store.name }) %>
|
6
|
+
</p>
|
7
|
+
<p>
|
8
|
+
<%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %>
|
9
|
+
</p>
|
10
|
+
<p class="body-action">
|
11
|
+
<a href="<%= @edit_password_reset_url %>" class="button button--green"><%= Spree.t('user_mailer.reset_password_instructions.button') %></a>
|
12
|
+
</p>
|
13
|
+
<p>
|
14
|
+
<%= Spree.t('user_mailer.reset_password_instructions.instructions_3') %>
|
15
|
+
</p>
|
16
|
+
<p>
|
17
|
+
<%= Spree.t('user_mailer.reset_password_instructions.thanks') %>
|
18
|
+
<br />
|
19
|
+
<%= Spree.t('user_mailer.reset_password_instructions.store_team', { store_name: @current_store.name }) %>
|
20
|
+
</p>
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
If you did not make this request, simply ignore this email.
|
1
|
+
<%= Spree.t('user_mailer.reset_password_instructions.welcome', email: @user.email) %>
|
3
2
|
|
4
|
-
|
3
|
+
<%= Spree.t('user_mailer.reset_password_instructions.instructions_1', { store_name: @current_store.name }) %>
|
4
|
+
<%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %>
|
5
5
|
|
6
|
+
<%= Spree.t('user_mailer.reset_password_instructions.button') %>
|
6
7
|
<%= @edit_password_reset_url %>
|
7
8
|
|
8
|
-
|
9
|
-
If you continue to have problems please feel free to contact us.
|
9
|
+
<%= Spree.t('user_mailer.reset_password_instructions.instructions_3') %>
|
10
10
|
|
11
|
+
<%= Spree.t('user_mailer.reset_password_instructions.thanks') %>
|
12
|
+
<%= Spree.t('user_mailer.reset_password_instructions.store_team', { store_name: @current_store.name }) %>
|
@@ -3,7 +3,7 @@ Warden::Manager.after_set_user except: :fetch do |user, auth, _opts|
|
|
3
3
|
token = auth.cookies.signed[:guest_token] || auth.cookies.signed[:token]
|
4
4
|
token_attr = Spree::Order.has_attribute?(:token) ? :token : :guest_token
|
5
5
|
|
6
|
-
if token.present? && user.is_a?(Spree
|
6
|
+
if token.present? && user.is_a?(Spree.user_class)
|
7
7
|
Spree::Order.incomplete.where(token_attr => token, user_id: nil).each do |order|
|
8
8
|
order.associate_user!(user)
|
9
9
|
end
|
data/config/locales/de.yml
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
---
|
2
2
|
de:
|
3
|
+
spree:
|
4
|
+
admin_login: Admin Login
|
5
|
+
change_your_password: Kennwort zurücksetzen
|
6
|
+
user_mailer:
|
7
|
+
reset_password_instructions:
|
8
|
+
instructions_1: "Es wurde eine Anfrage zum Zurücksetzen Ihres Passworts gestellt.\nWenn Sie diese Anfrage nicht gestellt haben, ignorieren Sie diese E-Mail.\n\nWenn Sie diese Anfrage gestellt haben, klicken Sie bitte auf den folgenden Link:"
|
9
|
+
instructions_2: "Falls die obige URL nicht funktioniert, bitte URL kopieren und in Ihren Browser einfügen\nWenn Sie weiterhin Probleme haben, können Sie sich gerne an uns wenden."
|
10
|
+
confirmation_instructions:
|
11
|
+
welcome: "Schön, dass Sie hier sind %{email}"
|
12
|
+
confirm: "Sie können Ihre Konto-E-Mail-Adresse über die folgende URL bestätigen:"
|
3
13
|
devise:
|
4
14
|
confirmations:
|
5
15
|
confirmed: Ihr Konto wurde erfolgreich aktiviert.
|
6
16
|
send_instructions: 'In ein paar Minuten erhalten Sie eine E-Mail mit Anweisungen, um Ihr Konto zu aktivieren.'
|
17
|
+
spree_user:
|
18
|
+
already_confirmed: Ihre E-Mail wurde bereits bestätigt. Bitte versuchen Sie erneut, sich anzumelden.
|
7
19
|
failure:
|
8
20
|
inactive: Ihr Konto wurde noch nicht aktiviert.
|
9
21
|
invalid: Ungültige E-Mail-Adresse oder Passwort.
|
@@ -28,16 +40,20 @@ de:
|
|
28
40
|
user_passwords:
|
29
41
|
spree_user:
|
30
42
|
cannot_be_blank: Ihr Passwort darf nicht leer sein.
|
43
|
+
no_token: Sie können nicht auf diese Seite zugreifen, wenn Sie den Link aus einer E-Mail zum Zurücksetzen des Kennworts nicht verwenden. Wenn Sie den Link aus einer E-Mail zum Zurücksetzen des Passworts verwenden, stellen Sie bitte sicher, dass Sie die vollständige URL verwendet haben.
|
31
44
|
send_instructions: In ein paar Minuten erhalten Sie eine E-Mail mit Anweisungen um Ihr Passwort zurücksetzen.
|
32
45
|
updated: Ihr Passwort wurde erfolgreich geändert.
|
33
46
|
user_registrations:
|
34
47
|
destroyed: Ihr Konto wurde erfolgreich gelöscht. Auf Wiedersehen!
|
35
48
|
inactive_signed_up: 'Sie haben sich erfolgreich registriert. Wir konnten Sie jedoch nicht anmelden, da Ihr Konto %{reason} ist.'
|
49
|
+
signed_up_but_unconfirmed: Eine Nachricht mit einem Bestätigungslink wurde an Ihre E-Mail-Adresse gesendet. Bitte folgen Sie dem Link, um Ihr Konto zu aktivieren.
|
36
50
|
signed_up: Herzlich Willkommen! Sie haben sich erfolgreich registriert.
|
37
51
|
updated: Sie haben Ihr Konto erfolgreich aktualisiert.
|
38
52
|
user_sessions:
|
39
53
|
signed_in: Erfolgreich angemeldet.
|
40
54
|
signed_out: Erfolgreich abgemeldet.
|
55
|
+
already_signed_in: Bereits angemeldet.
|
56
|
+
already_signed_out: Bereits abgemeldet.
|
41
57
|
errors:
|
42
58
|
messages:
|
43
59
|
already_confirmed: wurde bereits bestätigt
|
data/config/locales/en.yml
CHANGED
@@ -3,11 +3,26 @@ en:
|
|
3
3
|
spree:
|
4
4
|
admin_login: "Admin Login"
|
5
5
|
change_your_password: "Change your password"
|
6
|
-
|
7
|
-
|
6
|
+
user_mailer:
|
7
|
+
reset_password_instructions:
|
8
|
+
welcome: "Hi %{email}"
|
9
|
+
instructions_1: "A request to reset the password for your %{store_name} account has been made."
|
10
|
+
instructions_2: Click the button below to reset it.
|
11
|
+
instructions_3: If you did not request a password change ignore this email or contact us.
|
12
|
+
button: Reset your password
|
13
|
+
thanks: Thank you,
|
14
|
+
store_team: "%{store_name} Team"
|
15
|
+
confirmation_instructions:
|
16
|
+
welcome: "Welcome %{email}!"
|
17
|
+
instructions_1: "Thanks for registering at %{store_name}."
|
18
|
+
instructions_2: "Click the button below to confirm your account:"
|
19
|
+
instructions_3: If you have any questions, feel free to simply reply to this email.
|
20
|
+
button: Confirm email address
|
21
|
+
thanks: Thank you,
|
22
|
+
store_team: "%{store_name} Team"
|
8
23
|
devise:
|
9
24
|
confirmations:
|
10
|
-
confirmed: Your account was successfully confirmed. You
|
25
|
+
confirmed: Your account was successfully confirmed. You can now log in.
|
11
26
|
send_instructions: You will receive an email with instructions about how to confirm your account in a few minutes.
|
12
27
|
spree_user:
|
13
28
|
already_confirmed: Email was already confirmed, please try signing in.
|
@@ -26,8 +41,6 @@ en:
|
|
26
41
|
subject: Reset password instructions
|
27
42
|
unlock_instructions:
|
28
43
|
subject: Unlock Instructions
|
29
|
-
confirmation_instructions:
|
30
|
-
subject: Confirmation instructions
|
31
44
|
oauth_callbacks:
|
32
45
|
failure: 'Could not authorize you from %{kind} because %{reason}.'
|
33
46
|
success: 'Successfully authorized from %{kind} account.'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
zh-TW:
|
3
|
+
spree:
|
4
|
+
admin_login: "管理員登入"
|
5
|
+
change_your_password: "更改密碼"
|
6
|
+
devise:
|
7
|
+
confirmations:
|
8
|
+
confirmed: 你的帳號已經確認完成,現在你已經登入網站了。
|
9
|
+
send_instructions: 你會在幾分鐘內收到一封帳號確認信來確認你的帳號。
|
10
|
+
spree_user:
|
11
|
+
already_confirmed: Email 已確認,請登入。
|
12
|
+
failure:
|
13
|
+
inactive: 你的帳號尚未啟用。
|
14
|
+
invalid: 帳號或密碼有誤。
|
15
|
+
invalid_token: 錯誤的認證代碼。
|
16
|
+
locked: 你的帳號已經被停權,請聯絡客服人員。
|
17
|
+
timeout: 你的登入已經逾時,請重新登入。
|
18
|
+
unauthenticated: 你需要登入來繼續。
|
19
|
+
unconfirmed: 你的帳號需要確認來繼續。
|
20
|
+
mailer:
|
21
|
+
confirmation_instructions:
|
22
|
+
subject: 帳號確認教學
|
23
|
+
reset_password_instructions:
|
24
|
+
subject: 重設密碼教學
|
25
|
+
unlock_instructions:
|
26
|
+
subject: 帳號解鎖教學
|
27
|
+
oauth_callbacks:
|
28
|
+
failure: '由於%{reason},無法透過%{kind}確認你的帳號。'
|
29
|
+
success: '成功的由%{kind}認證你的帳號。'
|
30
|
+
unlocks:
|
31
|
+
send_instructions: 你在幾分鐘後會收到一封 Email 教你如何解鎖帳號。
|
32
|
+
unlocked: 你的帳號已經解鎖,現在你已經登入網站了。
|
33
|
+
user_passwords:
|
34
|
+
spree_user:
|
35
|
+
cannot_be_blank: 密碼不能為空白。
|
36
|
+
no_token: "你只能透過重新設定密碼的 Email 內的連結來訪問此頁面。如果你真的是透過那封 Email 來此頁面,請確定你是透過完整的網址過來的。"
|
37
|
+
send_instructions: 你在幾分鐘後會收到一封 Email 教你如何更改密碼。
|
38
|
+
updated: 你的密碼已經更改成功,你已成功登入。
|
39
|
+
user_registrations:
|
40
|
+
destroyed: 再見!你的帳號已經被取消了,但我們希望能再服務你。
|
41
|
+
inactive_signed_up: '你已經成功註冊,但由於%{reason}的原因,導致帳號無法登入。'
|
42
|
+
signed_up_but_unconfirmed: 確認信件已經寄到您的信箱,請按照上面的教學完成您的註冊。
|
43
|
+
signed_up: 歡迎!你已經成功註冊了。
|
44
|
+
updated: 你的帳號已經成功更新。
|
45
|
+
user_sessions:
|
46
|
+
signed_in: 登入成功
|
47
|
+
signed_out: 登出成功
|
48
|
+
already_signed_in: 已經登入
|
49
|
+
already_signed_out: 已經登入
|
50
|
+
errors:
|
51
|
+
messages:
|
52
|
+
already_confirmed: 已確認
|
53
|
+
email_is_invalid: Email 不能為空值
|
54
|
+
not_found: 找不到
|
55
|
+
not_locked: 沒有被鎖住
|
56
|
+
not_saved:
|
57
|
+
one: '%{resource}由於以下的一個錯誤導致無法被儲存:'
|
58
|
+
other: '%{resource}由於以下的%{count}個錯誤導致無法被儲存:'
|
data/config/routes.rb
CHANGED
@@ -21,7 +21,7 @@ Spree::Core::Engine.add_routes do
|
|
21
21
|
post '/password/recover' => 'user_passwords#create', :as => :reset_password
|
22
22
|
get '/password/change' => 'user_passwords#edit', :as => :edit_password
|
23
23
|
put '/password/change' => 'user_passwords#update', :as => :update_password
|
24
|
-
get '/confirm' => 'user_confirmations#show', :as => :confirmation
|
24
|
+
get '/confirm' => 'user_confirmations#show', :as => :confirmation
|
25
25
|
end
|
26
26
|
|
27
27
|
get '/checkout/registration' => 'checkout#registration', :as => :checkout_registration
|
@@ -42,6 +42,18 @@ Spree::Core::Engine.add_routes do
|
|
42
42
|
get '/login' => 'user_sessions#new', :as => :login
|
43
43
|
post '/login' => 'user_sessions#create', :as => :create_new_session
|
44
44
|
get '/logout' => 'user_sessions#destroy', :as => :logout
|
45
|
+
get '/password/recover' => 'user_passwords#new', :as => :recover_password
|
46
|
+
post '/password/recover' => 'user_passwords#create', :as => :reset_password
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
namespace :api, defaults: { format: 'json' } do
|
51
|
+
namespace :v2 do
|
52
|
+
namespace :storefront do
|
53
|
+
resource :account, controller: :account, only: %i[show create update]
|
54
|
+
resources :account_confirmations, only: %i[show]
|
55
|
+
resources :passwords, controller: :passwords, only: %i[create update]
|
56
|
+
end
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
data/gemfiles/spree_4_1.gemfile
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
module AccountControllerDecorator
|
6
|
+
def self.prepended(base)
|
7
|
+
base.skip_before_action :require_spree_current_user, only: [:create]
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
result = Spree::Account::Create.call(user_params: spree_user_params)
|
12
|
+
|
13
|
+
render_payload(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
result = Spree::Account::Update.call(user: spree_current_user, user_params: spree_user_params)
|
18
|
+
|
19
|
+
render_payload(result)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def render_payload(result)
|
25
|
+
if result.success?
|
26
|
+
render_serialized_payload { serialize_resource(result.value) }
|
27
|
+
else
|
28
|
+
render_error_payload(result.error)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def spree_user_params
|
33
|
+
params.require(:user).permit(Spree::PermittedAttributes.user_attributes)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
::Spree::Api::V2::Storefront::AccountController.prepend(Spree::Api::V2::Storefront::AccountControllerDecorator)
|
@@ -59,4 +59,20 @@ class Spree::Admin::UserSessionsController < Devise::SessionsController
|
|
59
59
|
"spree/layouts/admin"
|
60
60
|
end
|
61
61
|
end
|
62
|
+
|
63
|
+
def respond_to_on_destroy
|
64
|
+
# We actually need to hardcode this as Rails default responder doesn't
|
65
|
+
# support returning empty response on GET request
|
66
|
+
respond_to do |format|
|
67
|
+
format.all { head :no_content }
|
68
|
+
format.any(*navigational_formats) { redirect_to after_sign_out_redirect(resource_name) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def after_sign_out_redirect(resource_or_scope)
|
73
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
74
|
+
router_name = Devise.mappings[scope].router_name
|
75
|
+
context = router_name ? send(router_name) : self
|
76
|
+
context.respond_to?(:admin_login_path) ? context.admin_login_path : "/"
|
77
|
+
end
|
62
78
|
end
|
data/lib/spree/auth/engine.rb
CHANGED
@@ -12,7 +12,7 @@ module Spree
|
|
12
12
|
end
|
13
13
|
|
14
14
|
initializer "spree_auth_devise.set_user_class", after: :load_config_initializers do
|
15
|
-
Spree.user_class =
|
15
|
+
Spree.user_class = 'Spree::User' if Spree.user_class.blank? || Spree.user_class.to_s == 'Spree::LegacyUser'
|
16
16
|
end
|
17
17
|
|
18
18
|
initializer "spree_auth_devise.check_secret_token" do
|
@@ -29,20 +29,17 @@ module Spree
|
|
29
29
|
Rails.configuration.cache_classes ? require(c) : load(c)
|
30
30
|
end
|
31
31
|
if Spree::Auth::Engine.backend_available?
|
32
|
-
Rails.application.config.assets.precompile += [
|
33
|
-
'lib/assets/javascripts/spree/backend/spree_auth.js',
|
34
|
-
'lib/assets/javascripts/spree/backend/spree_auth.css'
|
35
|
-
]
|
36
32
|
Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/*/*/*_decorator*.rb")) do |c|
|
37
33
|
Rails.configuration.cache_classes ? require(c) : load(c)
|
38
34
|
end
|
39
35
|
end
|
40
36
|
if Spree::Auth::Engine.frontend_available?
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/**/*_decorator*.rb")) do |c|
|
38
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
if Spree::Auth::Engine.api_available?
|
42
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/api/**/*_decorator*.rb")) do |c|
|
46
43
|
Rails.configuration.cache_classes ? require(c) : load(c)
|
47
44
|
end
|
48
45
|
end
|
@@ -61,6 +58,10 @@ module Spree
|
|
61
58
|
@@frontend_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Frontend::Engine')
|
62
59
|
end
|
63
60
|
|
61
|
+
def self.api_available?
|
62
|
+
@@api_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Api::Engine')
|
63
|
+
end
|
64
|
+
|
64
65
|
if backend_available?
|
65
66
|
paths["app/controllers"] << "lib/controllers/backend"
|
66
67
|
paths["app/views"] << "lib/views/backend"
|
@@ -71,6 +72,10 @@ module Spree
|
|
71
72
|
paths["app/views"] << "lib/views/frontend"
|
72
73
|
end
|
73
74
|
|
75
|
+
if api_available?
|
76
|
+
paths["app/controllers"] << "lib/controllers/api"
|
77
|
+
end
|
78
|
+
|
74
79
|
config.to_prepare &method(:activate).to_proc
|
75
80
|
end
|
76
81
|
end
|
data/lib/spree_auth_devise.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
RSpec.describe Spree::Api::V2::Storefront::PasswordsController, type: :controller do
|
2
|
+
let(:user) { create(:user) }
|
3
|
+
let(:password) { 'new_password' }
|
4
|
+
let(:store) { create(:store) }
|
5
|
+
|
6
|
+
describe 'POST create' do
|
7
|
+
before { post :create, params: params }
|
8
|
+
|
9
|
+
context 'when the user email has not been specified' do
|
10
|
+
let(:params) { { user: { email: '' } } }
|
11
|
+
it 'responds with not found status' do
|
12
|
+
expect(response.code).to eq('404')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when the user email not found' do
|
17
|
+
let(:params) { { user: { email: 'dummy_email@example.com' } } }
|
18
|
+
it 'responds with not found status' do
|
19
|
+
expect(response.code).to eq('404')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when the user email has been specified' do
|
24
|
+
let(:params) { { user: { email: user.email } } }
|
25
|
+
it_behaves_like 'returns 200 HTTP status'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'PATCH update' do
|
30
|
+
before { patch :update, params: params }
|
31
|
+
|
32
|
+
context 'when updating password with blank password' do
|
33
|
+
let(:params) {
|
34
|
+
{
|
35
|
+
id: user.send_reset_password_instructions(Spree::Store.current),
|
36
|
+
user: {
|
37
|
+
password: '',
|
38
|
+
password_confirmation: ''
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
it 'responds with error' do
|
44
|
+
expect(response.code).to eq('422')
|
45
|
+
expect(JSON.parse(response.body)['error']).to eq("Password can't be blank")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when updating password with specified password' do
|
50
|
+
let(:params) {
|
51
|
+
{
|
52
|
+
id: user.send_reset_password_instructions(Spree::Store.current),
|
53
|
+
user: {
|
54
|
+
password: password,
|
55
|
+
password_confirmation: password
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
it_behaves_like 'returns 200 HTTP status'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|