]> git.mxchange.org Git - core.git/blob - inc/main/classes/commands/html/class_HtmlResendLinkCommand.php
Moved back out of "Generic" namespace, really no need
[core.git] / inc / main / classes / commands / html / class_HtmlResendLinkCommand.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Command\Guest;
4
5 // Import framework stuff
6 use CoreFramework\Command\BaseCommand;
7 use CoreFramework\Factory\ObjectFactory;
8 use CoreFramework\Registry\Registry;
9 use CoreFramework\Request\Requestable;
10 use CoreFramework\Response\Responseable;
11
12 /**
13  * A command class for resending the confirmation link
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
17  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
18  * @license             GNU GPL 3.0 or any newer version
19  * @link                http://www.shipsimu.org
20  *
21  * This program is free software: you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation, either version 3 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program. If not, see <http://www.gnu.org/licenses/>.
33  */
34 class HtmlResendLinkCommand extends BaseCommand implements Commandable {
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         protected function __construct () {
41                 // Call parent constructor
42                 parent::__construct(__CLASS__);
43         }
44
45         /**
46          * Creates an instance of this class
47          *
48          * @param       $resolverInstance       An instance of a command resolver class
49          * @return      $commandInstance        An instance a prepared command class
50          */
51         public static final function createHtmlResendLinkCommand (CommandResolver $resolverInstance) {
52                 // Get new instance
53                 $commandInstance = new HtmlResendLinkCommand();
54
55                 // Set the application instance
56                 $commandInstance->setResolverInstance($resolverInstance);
57
58                 // Return the prepared instance
59                 return $commandInstance;
60         }
61
62         /**
63          * Executes the given command with given request and response objects
64          *
65          * @param       $requestInstance        An instance of a class with an Requestable interface
66          * @param       $responseInstance       An instance of a class with an Responseable interface
67          * @return      void
68          */
69         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
70                 // Get user instance from registry
71                 $userInstance = Registry::getRegistry()->getInstance('user');
72
73                 // Get an application instance
74                 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
75
76                 // Get a RNG instance (Random Number Generator)
77                 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
78
79                 // Generate a pseudo-random string
80                 $randomString = $rngInstance->randomString(255);
81
82                 // Get a crypto instance
83                 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
84
85                 // Hash and encrypt the string
86                 $hashedString = $cryptoInstance->hashString($cryptoInstance->encryptString($randomString));
87
88                 // Update the user class
89                 $userInstance->updateDatabaseField(UserDatabaseWrapper::DB_COLUMN_CONFIRM_HASH, $hashedString);
90
91                 // Re-set config entry to mailer engine
92                 $this->getConfigInstance()->setConfigEntry('html_template_class', $this->getConfigInstance()->getConfigEntry('mail_template_class'));
93
94                 // Prepare the template engine
95                 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
96
97                 // Assign the application data with the template engine
98                 $templateInstance->assignApplicationData($applicationInstance);
99
100                 // Get a mailer class
101                 $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance, $applicationInstance, 'resend_link'));
102
103                 // Set this mailer in our template engine
104                 $templateInstance->setMailerInstance($mailerInstance);
105
106                 // Add template variables we shall get
107                 $mailerInstance->addConfigTemplateVariable('base_url');
108                 $mailerInstance->addConfigTemplateVariable('admin_email');
109                 $mailerInstance->addValueTemplateVariable('confirm_hash');
110                 $mailerInstance->addValueTemplateVariable('username');
111                 $mailerInstance->addValueTemplateVariable('email');
112
113                 // Add the value instance for the confirmation hash
114                 $mailerInstance->addValueInstance('confirm_hash', $userInstance);
115                 $mailerInstance->addValueInstance('username', $userInstance);
116                 $mailerInstance->addValueInstance('email', $userInstance);
117
118                 // Add the recipient
119                 $mailerInstance->addRecipientByUserInstance($userInstance);
120
121                 // Use subject line from template
122                 $mailerInstance->useSubjectFromTemplate();
123
124                 // Send the email out
125                 $mailerInstance->deliverEmail($responseInstance);
126
127                 // Send out notification to admin (depends on settings)
128                 $mailerInstance->sendAdminNotification($responseInstance);
129         }
130
131         /**
132          * Adds extra filters to the given controller instance
133          *
134          * @param       $controllerInstance             A controller instance
135          * @param       $requestInstance                An instance of a class with an Requestable interface
136          * @return      void
137          */
138         public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
139                 // Filter for checking if account is unconfirmed
140                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_unconfirmed_filter'));
141         }
142
143 }