commit 1ad0345441c7eb0baf4b7880f62449b4c794f325 from: Tracey Emery date: Thu May 12 16:50:06 2022 UTC finish up employee authorization request and response code commit - 993c0b7bf80797b107f5ca43ccb42f2c012634fb commit + 1ad0345441c7eb0baf4b7880f62449b4c794f325 blob - 0a362d8c5283516f5ec5988da73b282c86e0e768 blob + f0a7a31c4f00823625bb0dd9bea18d74851fbf7e --- module/Securitx/config/module.config.php +++ module/Securitx/config/module.config.php @@ -57,8 +57,6 @@ return [ 'securitx/securitx/user' => __DIR__ . '/../view/securitx/user/user.phtml', 'securitx/securitx/twofa' => __DIR__ . '/../view/securitx/twofa/twofa.phtml', 'securitx/securitx/forgot' => __DIR__ . '/../view/securitx/forgot/forgot.phtml', - 'securitx/securitx/requestadmin' => __DIR__ . '/../view/securitx/requestadmin/requestadmin.phtml', - 'securitx/securitx/requesteditor' => __DIR__ . '/../view/securitx/requesteditor/requesteditor.phtml', ], 'template_path_stack' => [ __DIR__ . '/../view/securitx', blob - c20696d45ab25f3bf424bdd66170aec79aa50537 blob + 5a9ecf0169ef60623e147cd113fb959cdb63b511 --- module/Securitx/src/Controller/SecuritxController.php +++ module/Securitx/src/Controller/SecuritxController.php @@ -95,6 +95,58 @@ class SecuritxController extends AbstractActionControl } return 0; } + public function authempAction() { + if (!$this->checkAnyAdmin()) + return $this->redirect()->toRoute('securitx'); + $admin = $this->getMember(); + if (!$admin->is_admin) + goto ret; + if ($_GET) { + if (array_key_exists('member', $_GET)) + $member = $this->member_table->getVMember( + $_GET['member']); + else + goto ret; + if (!$member) + goto ret; + if (array_key_exists('type', $_GET)) + $type = $_GET['type']; + else + goto ret; + if (array_key_exists('action', $_GET)) + $action = $_GET['action']; + else + goto ret; + if ($action == "allow") { + if ($type == "admin") + $member->is_admin = 1; + else + $member->is_editor = 1; + } else { + if ($type == "admin") + $member->is_admin = 2; + else + $member->is_editor = 2; + } + $company = + $this->company_table->getCompany($member->company_id); + $member->r_admin = 0; + $member->r_editor = 0; + $this->member_table->saveMember($member); + + $emailer = new Emailer($this->email_host); + $emailer->sendAuthEmail($member->email, $member->first, + $member->last, $action, $type, + $company->name, $this->hipaa['notice']); + } +ret: + return $this->redirect()->toRoute('securitx', + array( + 'action' => 'home', + 'id' => $admin->u_key, + ) + ); + } public function companiesAction() { if (!$this->checkAnyAdmin()) return $this->redirect()->toRoute('securitx'); @@ -499,8 +551,6 @@ class SecuritxController extends AbstractActionControl if (!$member || !$member->verified) return $this->redirect()->toRoute('securitx'); - $this->member_table->saveMember($member); - /* check member domain */ $company = $this->company_table->getCompany($member->company_id); @@ -511,6 +561,68 @@ class SecuritxController extends AbstractActionControl else $has_domain = 0; + if ($_GET && $has_domain) { + $admins = $this->member_table->getAllAdmins(); + if (array_key_exists('r_admin', $_GET)) { + $type = "admin"; + if ($member->is_admin > 0) + goto skip; + $member->r_admin = 1; + } + if (array_key_exists('r_editor', $_GET)) { + $type = "editor"; + if ($member->is_editor > 0) + goto skip; + $member->r_editor = 1; + } + $emailer = new Emailer($this->email_host); + foreach ($admins as $admin) { + $url1 = $this->url()->fromRoute( + 'securitx', + [ + 'action' => 'authemp', + 'id' => $admin->u_key, + ], + [ + 'query' => [ + 'member' => $member->u_key, + 'type' => $type, + 'action' => 'allow', + ], + ], + [ + 'force_canonical' => true, + ] + ); + $url2 = $this->url()->fromRoute( + 'securitx', + [ + 'action' => 'authemp', + 'id' => $admin->u_key, + ], + [ + 'query' => [ + 'member' => $member->u_key, + 'type' => $type, + 'action' => 'deny', + ], + ], + [ + 'force_canonical' => true, + ] + ); + $url1 = "https://" . $_SERVER['SERVER_NAME'] . + $url1; + $url2 = "https://" . $_SERVER['SERVER_NAME'] . + $url2; + $emailer->sendAdminRequest($admin, $member, + $url1, $url2, $this->hipaa['notice'], + $type); + } + } +skip: + $this->member_table->saveMember($member); + $inviter = ""; if ($member->inviter) { $admin = @@ -768,7 +880,7 @@ class SecuritxController extends AbstractActionControl 'id' => $member->v_key, ], [ - 'force_canonical' => true, + 'force_canonical' => true, ] ); $emailer = new Emailer($this->email_host); blob - be9bdf845ec75c46dc4d5bcbd1e2de821539f255 blob + a727cf3dd102e4a87b3056ddcf578521adb0cfe0 --- module/Securitx/src/Model/Emailer.php +++ module/Securitx/src/Model/Emailer.php @@ -13,6 +13,60 @@ class Emailer { $this->ip = $email_host['ip']; } + public function sendAuthEmail($email, $first, $last, $action, $type, + $company, $hipaa) { + if ($action == "allow") + $auth = "authorized"; + else + $auth = "denied"; + if ($type == "admin") + $thetype = "administrator"; + else + $thetype = "editor"; + + $message = new Message(); + $message->addFrom('no-reply@' . $this->hostname, 'SecuritX'); + $message->addTo("$email", "$first $last"); + $message->addReplyTo('no-reply@' . $this->hostname, 'SecuritX'); + $message->setSubject('Your SecuritX Employee Request'); + $message->setBody( + "Hello $first,\r\n\r\nAn administrator has $auth your " . + "request to become an $thetype of $company. Please see ". + "your administrator for more details. Thanks!" . + "\r\n\r\n--\r\n\r\n$hipaa" + ); + + $transport = new SmtpTransport(); + $options = new SmtpOptions([ + 'name' => $this->hostname, + 'host' => $this->ip, + ]); + $transport->setOptions($options); + $transport->send($message); + } + public function sendAdminRequest($admin, $member, $url1, $url2, $hipaa, + $type) { + $message = new Message(); + $message->addFrom('no-reply@' . $this->hostname, 'SecuritX'); + $message->addTo("$admin->email", "$admin->first $admin->last"); + $message->addReplyTo('no-reply@' . $this->hostname, 'SecuritX'); + $message->setSubject('SecuritX Employee Request'); + $message->setBody( + "Hello $admin->first,\r\n\r\n$member->first " . + "$member->last has requested $type rights.\r\n" . + "\r\nApprove\r\n$url1\r\n\r\n" . + "\r\nDeny\r\n$url2\r\n\r\n" . + "--\r\n\r\n$hipaa" + ); + + $transport = new SmtpTransport(); + $options = new SmtpOptions([ + 'name' => $this->hostname, + 'host' => $this->ip, + ]); + $transport->setOptions($options); + $transport->send($message); + } public function sendTwofa($email, $first, $last, $url, $hipaa, $code) { $message = new Message(); $message->addFrom('no-reply@' . $this->hostname, 'SecuritX'); blob - f48aee4c1adf8f2c1fe9ff39873d73a1bc68426b blob + 47270ede993e8f42563fe2adb83515f13eb86229 --- module/Securitx/src/Model/MemberTable.php +++ module/Securitx/src/Model/MemberTable.php @@ -22,6 +22,9 @@ class MemberTable { $row = $rowset->current(); return $row; } + public function getAllAdmins() { + return $this->tableGateway->select(['is_admin' => 1]); + } public function getAnyAdmin() { $rowset = $this->tableGateway->select([ 'is_admin' => 1, blob - ea243b9c8111572072235ebedeb7ab6077303f55 blob + 92918a116b45c2139e8828cd33136d294a6886f6 --- module/Securitx/view/securitx/home/home.phtml +++ module/Securitx/view/securitx/home/home.phtml @@ -7,13 +7,13 @@

SecuritX home of first ?> last ?>


-is_admin) { ?> +is_admin == 1) { ?>

Edit companies »

-is_admin || $member->is_editor) { ?> +is_admin == 1 || $member->is_editor == 1) { ?>

Invite a member »

is_admin || $member->is_editor) { ?> + if ($member->is_admin == 1 || $member->is_editor == 1) { ?>

Send files to a member »

@@ -26,13 +26,13 @@ if ($member->inviter) { ?>

Send files to »

r_admin && !$member->r_editor && !$member->is_admin && !$member->is_editor) { + if ($has_domain && !$member->r_admin && !$member->r_editor && $member->is_admin == 0 && $member->is_editor == 0) { echo "You are an employee of the company. Please request an action below."; } - if ($has_domain && !$member->is_admin && !$member->is_editor && ($member->r_admin || $member->r_editor)) { + if ($has_domain && $member->is_admin == 0 && $member->is_editor == 0 && ($member->r_admin || $member->r_editor)) { echo "
Please wait for an administrator to review your request"; } - if (!$member->is_admin && !$member->is_editor && !$has_domain) { ?> + if ($member->is_admin == 0 && $member->is_editor == 0 && !$has_domain) { ?>

Upload files to »

@@ -43,20 +43,20 @@

is_admin) { - if ($member->r_admin && !$member->is_admin) { + if ($has_domain && $member->is_admin == 0) { + if ($member->r_admin && $member->is_admin == 0) { echo "Administrator rights have been requested"; } else if (!$member->r_admin && !$member->is_admin) { ?> - Request administration rights + Request administrator rights r_editor && !$member->r_admin) { + if (!$member->r_editor && !$member->r_admin && $member->is_editor != 2) { ?> - | Request editor rights + | Request editor rights r_editor && !$member->is_editor && !$member->is_admin) { + } else if ($member->r_editor && $member->is_editor == 0 && $member->is_admin == 0) { echo "|Editor rights have been requested"; } } blob - 8c29d19e0f28e6516ec9c70ead6223a9ed7d063f (mode 644) blob + /dev/null --- module/Securitx/view/securitx/requestadmin/requestadmin.phtml +++ /dev/null @@ -1,10 +0,0 @@ -headTitle('SecuritX: Request Administration Right'); -?> -

-

Welcome to SecuritX

- -

Congratulations! You've reached your SecuritX admin reqester!

- -
-
blob - 13c0b0ec02405d68cb4f6fc0e71a74d623b5fd36 (mode 644) blob + /dev/null --- module/Securitx/view/securitx/requesteditor/requesteditor.phtml +++ /dev/null @@ -1,10 +0,0 @@ -headTitle('SecuritX: Request Editor Right'); -?> -
-

Welcome to SecuritX

- -

Congratulations! You've reached your SecuritX editor reqester!

- -
-