More code for #857

This commit is contained in:
James Cole
2017-09-26 09:15:21 +02:00
parent 91e96aa4b9
commit d99adb515a
10 changed files with 137 additions and 4 deletions

View File

@@ -48,6 +48,32 @@ class UserController extends Controller
);
}
/**
* @param User $user
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function delete(User $user)
{
$subTitle = trans('firefly.delete_user', ['email' => $user->email]);
return view('admin.users.delete', compact('user', 'subTitle'));
}
/**
* @param User $user
* @param UserRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroy(User $user, UserRepositoryInterface $repository)
{
$repository->destroy($user);
Session::flash('success', strval(trans('firefly.user_deleted')));
return redirect(route('admin.users'));
}
/**
* @param User $user
*
@@ -64,9 +90,10 @@ class UserController extends Controller
$subTitle = strval(trans('firefly.edit_user', ['email' => $user->email]));
$subTitleIcon = 'fa-user-o';
$codes = [
'' => strval(trans('firefly.no_block_code')),
'bounced' => strval(trans('firefly.block_code_bounced')),
'expired' => strval(trans('firefly.block_code_expired')),
'' => strval(trans('firefly.no_block_code')),
'bounced' => strval(trans('firefly.block_code_bounced')),
'expired' => strval(trans('firefly.block_code_expired')),
'email_changed' => strval(trans('firefly.block_code_email_changed')),
];
return view('admin.users.edit', compact('user', 'subTitle', 'subTitleIcon', 'codes'));
@@ -143,6 +170,7 @@ class UserController extends Controller
}
$repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
$repository->updateEmail($user, $data['email']);
Session::flash('success', strval(trans('firefly.updated_user', ['email' => $user->email])));
Preferences::mark();

View File

@@ -138,6 +138,12 @@ Breadcrumbs::register(
$breadcrumbs->push(trans('firefly.edit_user', ['email' => $user->email]), route('admin.users.edit', [$user->id]));
}
);
Breadcrumbs::register(
'admin.users.delete', function (BreadCrumbGenerator $breadcrumbs, User $user) {
$breadcrumbs->parent('admin.users');
$breadcrumbs->push(trans('firefly.delete_user', ['email' => $user->email]), route('admin.users.delete', [$user->id]));
}
);
Breadcrumbs::register(
'admin.users.domains', function (BreadCrumbGenerator $breadcrumbs) {

View File

@@ -53,9 +53,14 @@ class UserRepository implements UserRepositoryInterface
}
/**
* This updates the users email address and records some things so it can be confirmed or undone later.
* The user is blocked until the change is confirmed.
*
* @param User $user
* @param string $newEmail
*
* @see updateEmail
*
* @return bool
*/
public function changeEmail(User $user, string $newEmail): bool
@@ -212,4 +217,29 @@ class UserRepository implements UserRepositoryInterface
{
return $user->hasRole($role);
}
/**
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one.
* The user is NOT blocked.
*
* @param User $user
* @param string $newEmail
*
* @see changeEmail
*
* @return bool
*/
public function updateEmail(User $user, string $newEmail): bool
{
$oldEmail = $user->email;
// save old email as pref
Preferences::setForUser($user, 'admin_previous_email_latest', $oldEmail);
Preferences::setForUser($user, 'admin_previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
$user->email = $newEmail;
$user->save();
return true;
}
}

View File

@@ -43,9 +43,14 @@ interface UserRepositoryInterface
public function attachRole(User $user, string $role): bool;
/**
* This updates the users email address and records some things so it can be confirmed or undone later.
* The user is blocked until the change is confirmed.
*
* @param User $user
* @param string $newEmail
*
* @see updateEmail
*
* @return bool
*/
public function changeEmail(User $user, string $newEmail): bool;
@@ -111,4 +116,17 @@ interface UserRepositoryInterface
* @return bool
*/
public function hasRole(User $user, string $role): bool;
/**
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one.
* The user is NOT blocked.
*
* @param User $user
* @param string $newEmail
*
* @see changeEmail
*
* @return bool
*/
public function updateEmail(User $user, string $newEmail): bool;
}