nash-ye /
ebloodbank
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Activate users page controller class file |
||||||
| 4 | * |
||||||
| 5 | * @package EBloodBank |
||||||
| 6 | * @subpackage Controllers |
||||||
| 7 | * @since 1.1 |
||||||
| 8 | */ |
||||||
| 9 | namespace EBloodBank\Controllers; |
||||||
| 10 | |||||||
| 11 | use EBloodBank as EBB; |
||||||
| 12 | |||||||
| 13 | /** |
||||||
| 14 | * Activate users page controller class |
||||||
| 15 | * |
||||||
| 16 | * @since 1.1 |
||||||
| 17 | */ |
||||||
| 18 | class ActivateUsers extends Controller |
||||||
| 19 | { |
||||||
| 20 | /** |
||||||
| 21 | * @var \EBloodBank\Models\User[] |
||||||
| 22 | * @since 1.1 |
||||||
| 23 | */ |
||||||
| 24 | protected $users = []; |
||||||
| 25 | |||||||
| 26 | /** |
||||||
| 27 | * @return void |
||||||
| 28 | * @since 1.1 |
||||||
| 29 | */ |
||||||
| 30 | public function __invoke() |
||||||
| 31 | { |
||||||
| 32 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'User', 'activate')) { |
||||||
| 33 | $this->viewFactory->displayView('error-403'); |
||||||
| 34 | return; |
||||||
| 35 | } |
||||||
| 36 | |||||||
| 37 | if (filter_has_var(INPUT_POST, 'users')) { |
||||||
| 38 | $usersIDs = filter_input(INPUT_POST, 'users', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY); |
||||||
| 39 | if (! empty($usersIDs) && is_array($usersIDs)) { |
||||||
| 40 | $this->users = $this->getUserRepository()->findBy(['id' => $usersIDs]); |
||||||
| 41 | } |
||||||
| 42 | } |
||||||
| 43 | |||||||
| 44 | $this->doActions(); |
||||||
| 45 | $this->viewFactory->displayView( |
||||||
| 46 | 'activate-users', |
||||||
| 47 | [ |
||||||
| 48 | 'users' => $this->users, |
||||||
| 49 | ] |
||||||
| 50 | ); |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | /** |
||||||
| 54 | * @return void |
||||||
| 55 | * @since 1.1 |
||||||
| 56 | */ |
||||||
| 57 | protected function doActions() |
||||||
| 58 | { |
||||||
| 59 | switch (filter_input(INPUT_POST, 'action')) { |
||||||
| 60 | case 'activate_users': |
||||||
| 61 | $this->doActivateAction(); |
||||||
| 62 | break; |
||||||
| 63 | } |
||||||
| 64 | } |
||||||
| 65 | |||||||
| 66 | /** |
||||||
| 67 | * @return void |
||||||
| 68 | * @since 1.1 |
||||||
| 69 | */ |
||||||
| 70 | protected function doActivateAction() |
||||||
| 71 | { |
||||||
| 72 | // Double check |
||||||
| 73 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'User', 'activate')) { |
||||||
| 74 | return; |
||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | $actionToken = filter_input(INPUT_POST, 'token'); |
||||||
| 78 | $sessionToken = $this->getSession()->getCsrfToken(); |
||||||
| 79 | |||||||
| 80 | if (! $actionToken || ! $sessionToken->isValid($actionToken)) { |
||||||
| 81 | return; |
||||||
| 82 | } |
||||||
| 83 | |||||||
| 84 | if (empty($this->users)) { |
||||||
| 85 | return; |
||||||
| 86 | } |
||||||
| 87 | |||||||
| 88 | $activatedUsersCount = 0; |
||||||
| 89 | |||||||
| 90 | foreach ($this->users as $user) { |
||||||
| 91 | if (! $user->isPending()) { |
||||||
| 92 | continue; |
||||||
| 93 | } |
||||||
| 94 | if ($this->getAcl()->canActivateUser($this->getAuthenticatedUser(), $user)) { |
||||||
| 95 | $user->set('status', 'activated'); |
||||||
| 96 | $activatedUsersCount++; |
||||||
| 97 | } |
||||||
| 98 | } |
||||||
| 99 | |||||||
| 100 | $this->getEntityManager()->flush(); |
||||||
| 101 | |||||||
| 102 | EBB\redirect( |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 103 | EBB\addQueryArgs( |
||||||
|
0 ignored issues
–
show
The function
addQueryArgs was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 104 | EBB\getEditUsersURL(), |
||||||
|
0 ignored issues
–
show
The function
getEditUsersURL was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 105 | ['flag-activated' => $activatedUsersCount] |
||||||
| 106 | ) |
||||||
| 107 | ); |
||||||
| 108 | } |
||||||
| 109 | } |
||||||
| 110 |