added a password field before account closure
This commit is contained in:
parent
9bdde0d9af
commit
ecd2a52553
3 changed files with 24 additions and 10 deletions
|
|
@ -80,11 +80,15 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
if params[:user][:current_password] && current_user.valid_password?(params[:user][:current_password])
|
||||||
Resque.enqueue(Jobs::DeleteAccount, current_user.id)
|
Resque.enqueue(Jobs::DeleteAccount, current_user.id)
|
||||||
current_user.lock_access!
|
current_user.lock_access!
|
||||||
sign_out current_user
|
sign_out current_user
|
||||||
flash[:notice] = I18n.t 'users.destroy'
|
flash[:notice] = I18n.t 'users.destroy'
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
|
else
|
||||||
|
redirect_to :back
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def public
|
def public
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,11 @@
|
||||||
.span-5.last
|
.span-5.last
|
||||||
%h3
|
%h3
|
||||||
= t('.close_account')
|
= t('.close_account')
|
||||||
= link_to t('.close_account'), user_path,
|
= form_for 'user', :url => user_path, :html => { :method => :delete } do |f|
|
||||||
:confirm => t('are_you_sure'), :method => :delete,
|
= f.error_messages
|
||||||
:class => "button"
|
|
||||||
|
%p
|
||||||
|
= f.label :current_password, t('.current_password')
|
||||||
|
= f.password_field :current_password
|
||||||
|
%p
|
||||||
|
= f.submit t('.close_account'), :confirm => t('are_you_sure')
|
||||||
|
|
|
||||||
|
|
@ -187,13 +187,18 @@ describe UsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#destroy' do
|
||||||
|
it 'does nothing if the password does not match' do
|
||||||
|
Resque.should_not_receive(:enqueue)
|
||||||
|
delete :destroy, :password => "stuff"
|
||||||
|
end
|
||||||
|
|
||||||
it 'enqueues a delete job' do
|
it 'enqueues a delete job' do
|
||||||
Resque.should_receive(:enqueue).with(Jobs::DeleteAccount, alice.id)
|
Resque.should_receive(:enqueue).with(Jobs::DeleteAccount, alice.id)
|
||||||
delete :destroy
|
delete :destroy, :password => "bluepin7"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'locks the user out' do
|
it 'locks the user out' do
|
||||||
delete :destroy
|
delete :destroy, :password => "bluepin7"
|
||||||
alice.reload.access_locked?.should be_true
|
alice.reload.access_locked?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue