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