mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
More code for #857
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user