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