This commit is contained in:
James Cole
2016-12-12 15:24:47 +01:00
parent 06ff450d31
commit 3e3c48314f
7 changed files with 105 additions and 31 deletions

View File

@@ -15,9 +15,9 @@ namespace FireflyIII\Http\Controllers;
use FireflyIII\Http\Requests\DeleteAccountFormRequest;
use FireflyIII\Http\Requests\ProfileFormRequest;
use FireflyIII\User;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Hash;
use Preferences;
use Log;
use Session;
use View;
@@ -112,12 +112,12 @@ class ProfileController extends Controller
}
/**
* @param UserRepositoryInterface $repository
* @param DeleteAccountFormRequest $request
*
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function postDeleteAccount(DeleteAccountFormRequest $request)
public function postDeleteAccount(UserRepositoryInterface $repository, DeleteAccountFormRequest $request)
{
// old, new1, new2
if (!Hash::check($request->get('password'), auth()->user()->password)) {
@@ -125,34 +125,16 @@ class ProfileController extends Controller
return redirect(route('profile.delete-account'));
}
// store some stuff for the future:
$registration = Preferences::get('registration_ip_address')->data;
$confirmation = Preferences::get('confirmation_ip_address')->data;
// DELETE!
$email = auth()->user()->email;
auth()->user()->delete();
$user = auth()->user();
Log::info(sprintf('User #%d has opted to delete their account', auth()->user()->id));
// make repository delete user:
auth()->logout();
Session::flush();
$repository->destroy($user);
Session::flash('gaEventCategory', 'user');
Session::flash('gaEventAction', 'delete-account');
// create a new user with the same email address so re-registration is blocked.
$newUser = User::create(
[
'email' => $email,
'password' => 'deleted',
'blocked' => 1,
'blocked_code' => 'deleted',
]
);
if (strlen($registration) > 0) {
Preferences::setForUser($newUser, 'registration_ip_address', $registration);
}
if (strlen($confirmation) > 0) {
Preferences::setForUser($newUser, 'confirmation_ip_address', $confirmation);
}
return redirect(route('index'));
}