-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow admins to reset an user's password through the admin panel
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/overrides/spree/admin/users/edit/_add_reset_password_form.html.erb.deface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- | ||
insert_before "fieldset#admin_user_edit_api_key" | ||
original "904c52ff702412d1dc8d55ff44d87d7f581f6675" | ||
--> | ||
|
||
<% if @user != try_spree_current_user %> | ||
<fieldset class="no-border-bottom" data-hook="admin_user_reset_password"> | ||
<legend><%= I18n.t(:'spree.forgot_password') %></legend> | ||
|
||
<%= form_for [:admin, @user], as: :spree_user, url: admin_reset_password_path, method: :post do |f| %> | ||
<%= f.hidden_field :email, value: @user.email %> | ||
|
||
<% if can?(:update, @user) %> | ||
<div class="align-center"> | ||
<%= f.submit Spree.user_class.human_attribute_name(:reset_password), class: "button primary" %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</fieldset> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,43 @@ | |
click_button 'Reset my password' | ||
expect(page).to have_text "Email can't be blank" | ||
end | ||
|
||
context 'password management' do | ||
let!(:admin) do | ||
create(:admin_user, | ||
email: '[email protected]', | ||
password: 'secret', | ||
password_confirmation: 'secret' | ||
) | ||
end | ||
|
||
let!(:user) do | ||
create(:user, | ||
email: '[email protected]', | ||
password: 'test123', | ||
password_confirmation: 'test123' | ||
) | ||
end | ||
|
||
before do | ||
visit spree.admin_login_path | ||
fill_in 'Email', with: admin.email | ||
fill_in 'Password', with: admin.password | ||
click_button 'Login' | ||
visit spree.admin_users_path | ||
end | ||
|
||
context 'if currently logged-in admin' do | ||
context "clicks on an user's page" do | ||
it 'can reset its password' do | ||
within("#spree_user_#{user.id}") do | ||
click_link user.email | ||
end | ||
|
||
click_button 'Reset password' | ||
expect(page).to have_content 'You will receive an email with instructions on how to reset your password in a few minutes.' | ||
end | ||
end | ||
end | ||
end | ||
end |