3 namespace Org\Mxchange\CoreFramework\Command\Guest;
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;
17 * A command class for resending the confirmation link
19 * @author Roland Haeder <webmaster@shipsimu.org>
21 <<<<<<< HEAD:framework/main/classes/commands/html/class_HtmlResendLinkCommand.php
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
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
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.
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.
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/>.
42 class HtmlResendLinkCommand extends BaseCommand implements Commandable {
44 * Protected constructor
48 protected function __construct () {
49 // Call parent constructor
50 parent::__construct(__CLASS__);
54 * Creates an instance of this class
56 * @param $resolverInstance An instance of a command resolver class
57 * @return $commandInstance An instance a prepared command class
59 public static final function createHtmlResendLinkCommand (CommandResolver $resolverInstance) {
61 $commandInstance = new HtmlResendLinkCommand();
63 // Set the application instance
64 $commandInstance->setResolverInstance($resolverInstance);
66 // Return the prepared instance
67 return $commandInstance;
71 * Executes the given command with given request and response objects
73 * @param $requestInstance An instance of a class with an Requestable interface
74 * @param $responseInstance An instance of a class with an Responseable interface
77 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
78 // Get user instance from registry
79 $userInstance = Registry::getRegistry()->getInstance('user');
81 // Get an application instance
82 $applicationInstance = Registry::getRegistry()->getInstance('app');
84 // Get a RNG instance (Random Number Generator)
85 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
87 // Generate a pseudo-random string
88 $randomString = $rngInstance->randomString(255);
90 // Get a crypto instance
91 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
93 // Hash and encrypt the string
94 $hashedString = $cryptoInstance->hashString($cryptoInstance->encryptString($randomString));
96 // Update the user class
97 $userInstance->updateDatabaseField(UserDatabaseWrapper::DB_COLUMN_CONFIRM_HASH, $hashedString);
99 // Re-set config entry to mailer engine
100 $this->getConfigInstance()->setConfigEntry('html_template_class', $this->getConfigInstance()->getConfigEntry('mail_template_class'));
102 // Prepare the template engine
103 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
105 // Assign the application data with the template engine
106 $templateInstance->assignApplicationData($applicationInstance);
108 // Get a mailer class
109 $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance, $applicationInstance, 'resend_link'));
111 // Set this mailer in our template engine
112 $templateInstance->setMailerInstance($mailerInstance);
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');
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);
127 $mailerInstance->addRecipientByUserInstance($userInstance);
129 // Use subject line from template
130 $mailerInstance->useSubjectFromTemplate();
132 // Send the email out
133 $mailerInstance->deliverEmail($responseInstance);
135 // Send out notification to admin (depends on settings)
136 $mailerInstance->sendAdminNotification($responseInstance);
140 * Adds extra filters to the given controller instance
142 * @param $controllerInstance A controller instance
143 * @param $requestInstance An instance of a class with an Requestable interface
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'));