File indexing completed on 2024-05-12 05:58:41

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  *
0023  * Created: 02.05.2018
0024  */
0025 class VerifyController extends Local_Controller_Action_DomainSwitch
0026 {
0027 
0028     public function resendAction()
0029     {
0030         $session = new Zend_Session_Namespace();
0031         $member_id = (int)$session->mail_verify_member_id;
0032         if (empty($member_id)) {
0033             throw new Zend_Controller_Action_Exception('missing member id parameter');
0034         }
0035 
0036         if ($this->_request->isGet()) {
0037             return;
0038         }
0039 
0040         $crsf_token = $this->getParam('crsf_token');
0041         if (false == Default_Model_CsrfProtection::validateCsrfToken($crsf_token)) {
0042             return;
0043         }
0044 
0045         $modelMember = new Default_Model_Member();
0046         $memberData = $modelMember->fetchMemberData($member_id);
0047 
0048         if (count($memberData->toArray()) == 0) {
0049             throw new Zend_Controller_Action_Exception('could not found data for member_id: ' . print_r($member_id, true));
0050         }
0051 
0052         $modelEmail = new Default_Model_MemberEmail();
0053         $primaryEmail = $modelEmail->fetchMemberPrimaryMail($member_id);
0054         $mailValidationValue = $primaryEmail['email_verification_value'];
0055         $memberEmail = $primaryEmail['email_address'];
0056 
0057         Zend_Registry::get('logger')->info(__METHOD__ . ' - resend of verification mail requested by user id: '
0058             . $memberData->member_id)
0059         ;
0060 
0061         $this->resendVerificationMail($memberData, $memberEmail, $mailValidationValue);
0062 
0063         Zend_Registry::get('logger')->info(__METHOD__ . ' - verification mail successfully transmitted to mail server for user id: '
0064             . $memberData->member_id)
0065         ;
0066 
0067         $session->mail_verify_member_id = null;
0068 
0069         $this->_helper->flashMessenger->addMessage('<p class="text-info">We have send a new verification mail to the stored mail address. </p>');
0070         $this->forward('index', 'explore', 'default');
0071     }
0072 
0073     /**
0074      * @param Zend_Db_Table_Row $memberData
0075      * @param                   $memberEmail
0076      * @param string            $verificationVal
0077      *
0078      * @throws Zend_Exception
0079      */
0080     private function resendVerificationMail($memberData, $memberEmail, $verificationVal)
0081     {
0082         $config = Zend_Registry::get('config');
0083         $fromEmailAddress = $config->resources->mail->defaultFrom->email;
0084 
0085         $confirmMail = new Default_Plugin_SendMail('tpl_verify_user');
0086         $confirmMail->setTemplateVar('servername', $this->getServerName());
0087         $confirmMail->setTemplateVar('username', $memberData->username);
0088         $confirmMail->setTemplateVar('verificationlinktext',
0089             '<a href="https://' . $this->getServerName() . '/verification/' . $verificationVal
0090             . '">Click here to verify your email address</a>');
0091         $confirmMail->setTemplateVar('verificationlink',
0092             '<a href="https://' . $this->getServerName() . '/verification/' . $verificationVal . '">https://' . $this->getServerName()
0093             . '/verification/' . $verificationVal . '</a>');
0094         $confirmMail->setTemplateVar('verificationurl', 'https://' . $this->getServerName() . '/verification/' . $verificationVal);
0095         $confirmMail->setReceiverMail($memberEmail);
0096         $confirmMail->setFromMail($fromEmailAddress);
0097         $confirmMail->send();
0098     }
0099 
0100     /**
0101      * @return mixed
0102      */
0103     protected function getServerName()
0104     {
0105         /** @var Zend_Controller_Request_Http $request */
0106         $request = $this->getRequest();
0107 
0108         return $request->getHttpHost();
0109     }
0110 
0111     public function requestAction()
0112     {
0113         $this->_helper->viewRenderer('resend');
0114         $member_id = (int)$this->getParam('i', null);
0115 
0116         $modelMember = new Default_Model_Member();
0117         $memberData = $modelMember->fetchMemberData($member_id);
0118 
0119         if (count($memberData->toArray()) == 0) {
0120             throw new Zend_Controller_Action_Exception('could not found data for member_id: ' . print_r($member_id, true));
0121         }
0122 
0123         $modelEmail = new Default_Model_MemberEmail();
0124         $primaryEmail = $modelEmail->fetchMemberPrimaryMail($member_id);
0125         $mailValidationValue = $primaryEmail['email_verification_value'];
0126         $memberEmail = $primaryEmail['email_address'];
0127 
0128         Zend_Registry::get('logger')->info(__METHOD__ . ' - resend of verification mail requested by user id: '. $this->_authMember->member_id)
0129         ;
0130 
0131         $this->resendVerificationMail($memberData, $memberEmail, $mailValidationValue);
0132 
0133         Zend_Registry::get('logger')->info(__METHOD__ . ' - verification mail successfully transmitted to mail server for user id: '
0134                                            . $memberData->member_id)
0135         ;
0136 
0137         $this->_helper->flashMessenger->addMessage('<p class="text-info">We have send a new verification mail to the stored mail address. </p>');
0138         $this->redirect('/');
0139     }
0140 
0141 }