nash-ye /
ebloodbank
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Activate user page controller class file |
||||||
| 4 | * |
||||||
| 5 | * @package EBloodBank |
||||||
| 6 | * @subpackage Controllers |
||||||
| 7 | * @since 1.0 |
||||||
| 8 | */ |
||||||
| 9 | namespace EBloodBank\Controllers; |
||||||
| 10 | |||||||
| 11 | use EBloodBank as EBB; |
||||||
| 12 | use Psr\Container\ContainerInterface; |
||||||
| 13 | |||||||
| 14 | /** |
||||||
| 15 | * Activate user page controller class |
||||||
| 16 | * |
||||||
| 17 | * @since 1.0 |
||||||
| 18 | */ |
||||||
| 19 | class ActivateUser extends Controller |
||||||
| 20 | { |
||||||
| 21 | /** |
||||||
| 22 | * @var int |
||||||
| 23 | * @since 1.6 |
||||||
| 24 | */ |
||||||
| 25 | protected $userId = 0; |
||||||
| 26 | |||||||
| 27 | /** |
||||||
| 28 | * @var \EBloodBank\Models\User|null |
||||||
| 29 | * @since 1.0 |
||||||
| 30 | */ |
||||||
| 31 | protected $user; |
||||||
| 32 | |||||||
| 33 | /** |
||||||
| 34 | * @since 1.0 |
||||||
| 35 | */ |
||||||
| 36 | public function __construct(ContainerInterface $container, $userID) |
||||||
| 37 | { |
||||||
| 38 | parent::__construct($container); |
||||||
| 39 | if (EBB\isValidID($userID)) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 40 | $this->userId = (int) $userID; |
||||||
| 41 | } |
||||||
| 42 | } |
||||||
| 43 | |||||||
| 44 | /** |
||||||
| 45 | * @return void |
||||||
| 46 | * @since 1.0 |
||||||
| 47 | */ |
||||||
| 48 | public function __invoke() |
||||||
| 49 | { |
||||||
| 50 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'User', 'activate')) { |
||||||
| 51 | $this->viewFactory->displayView('error-403'); |
||||||
| 52 | return; |
||||||
| 53 | } |
||||||
| 54 | |||||||
| 55 | if ($this->userID) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 56 | $this->user = $this->getUserRepository()->find($this->userID); |
||||||
| 57 | } |
||||||
| 58 | |||||||
| 59 | if (! $this->user) { |
||||||
| 60 | $this->viewFactory->displayView('error-404'); |
||||||
| 61 | return; |
||||||
| 62 | } |
||||||
| 63 | |||||||
| 64 | if (! $this->getAcl()->canActivateUser($this->getAuthenticatedUser(), $this->user)) { |
||||||
| 65 | $this->viewFactory->displayView('error-403'); |
||||||
| 66 | return; |
||||||
| 67 | } |
||||||
| 68 | |||||||
| 69 | $this->doActions(); |
||||||
| 70 | $this->viewFactory->displayView( |
||||||
| 71 | 'activate-user', |
||||||
| 72 | [ |
||||||
| 73 | 'user' => $this->user, |
||||||
| 74 | ] |
||||||
| 75 | ); |
||||||
| 76 | } |
||||||
| 77 | |||||||
| 78 | /** |
||||||
| 79 | * @return void |
||||||
| 80 | * @since 1.0 |
||||||
| 81 | */ |
||||||
| 82 | protected function doActions() |
||||||
| 83 | { |
||||||
| 84 | switch (filter_input(INPUT_POST, 'action')) { |
||||||
| 85 | case 'activate_user': |
||||||
| 86 | $this->doActivateAction(); |
||||||
| 87 | break; |
||||||
| 88 | } |
||||||
| 89 | } |
||||||
| 90 | |||||||
| 91 | /** |
||||||
| 92 | * @return void |
||||||
| 93 | * @since 1.0 |
||||||
| 94 | */ |
||||||
| 95 | protected function doActivateAction() |
||||||
| 96 | { |
||||||
| 97 | $actionToken = filter_input(INPUT_POST, 'token'); |
||||||
| 98 | $sessionToken = $this->getSession()->getCsrfToken(); |
||||||
| 99 | |||||||
| 100 | if (! $actionToken || ! $sessionToken->isValid($actionToken)) { |
||||||
| 101 | return; |
||||||
| 102 | } |
||||||
| 103 | |||||||
| 104 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->canActivateUser($this->getAuthenticatedUser(), $this->user)) { |
||||||
|
0 ignored issues
–
show
It seems like
$this->user can also be of type null; however, parameter $user of EBloodBank\AclInterface::canActivateUser() does only seem to accept EBloodBank\Models\User, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 105 | return; |
||||||
| 106 | } |
||||||
| 107 | |||||||
| 108 | if (! $this->user->isPending()) { |
||||||
|
0 ignored issues
–
show
The method
isPending() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 109 | return; |
||||||
| 110 | } |
||||||
| 111 | |||||||
| 112 | $this->user->set('status', 'activated'); |
||||||
| 113 | $this->getEntityManager()->flush($this->user); |
||||||
| 114 | |||||||
| 115 | EBB\redirect( |
||||||
|
0 ignored issues
–
show
The function
redirect 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...
|
|||||||
| 116 | 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...
|
|||||||
| 117 | 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...
|
|||||||
| 118 | ['flag-activated' => 1] |
||||||
| 119 | ) |
||||||
| 120 | ); |
||||||
| 121 | } |
||||||
| 122 | } |
||||||
| 123 |