3 namespace Org\Mxchange\City\Command;
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\UserDatabaseFrontend;
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;
18 * A command class for resending the confirmation link
20 * @author Roland Haeder <webmaster@shipsimu.org>
22 * @copyright Copyright (c) 2015, 2016 City Developer Team
23 * @license GNU GPL 3.0 or any newer version
24 * @link http://www.shipsimu.org
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.
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.
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/>.
39 class CityHtmlResendLinkCommand extends BaseCommand implements Commandable {
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
51 * Creates an instance of this class
53 * @param $resolverInstance An instance of a command resolver class
54 * @return $commandInstance An instance a prepared command class
56 public static final function createCityHtmlResendLinkCommand (CommandResolver $resolverInstance) {
58 $commandInstance = new CityHtmlResendLinkCommand();
60 // Set the application instance
61 $commandInstance->setResolverInstance($resolverInstance);
63 // Return the prepared instance
64 return $commandInstance;
68 * Executes the given command with given request and response objects
70 * @param $requestInstance An instance of a class with an Requestable interface
71 * @param $responseInstance An instance of a class with an Responseable interface
74 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
75 // Get user instance from registry
76 $userInstance = GenericRegistry::getRegistry()->getInstance('user');
78 // Get an application instance
79 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
81 // Get a RNG instance (Random Number Generator)
82 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
84 // Generate a pseudo-random string
85 $randomString = $rngInstance->randomString(255);
87 // Get a crypto instance
88 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
90 // Hash and encrypt the string
91 $hashedString = $cryptoInstance->hashString($cryptoInstance->encryptString($randomString));
93 // Update the user class
94 $userInstance->updateDatabaseField(UserDatabaseFrontend::DB_COLUMN_CONFIRM_HASH, $hashedString);
96 // Re-set config entry to mailer engine
97 FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('html_template_class', FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('mail_template_class'));
99 // Prepare the template engine
100 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
102 // Assign the application data with the template engine
103 $templateInstance->assignApplicationData();
105 // Get a mailer class
106 $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance, 'resend_link'));
108 // Set this mailer in our template engine
109 $templateInstance->setMailerInstance($mailerInstance);
111 // Add template variables we shall get
112 $mailerInstance->addConfigTemplateVariable('base_url');
113 $mailerInstance->addConfigTemplateVariable('admin_email');
114 $mailerInstance->addValueTemplateVariable('confirm_hash');
115 $mailerInstance->addValueTemplateVariable('username');
116 $mailerInstance->addValueTemplateVariable('email');
118 // Add the value instance for the confirmation hash
119 $mailerInstance->addValueInstance('confirm_hash', $userInstance);
120 $mailerInstance->addValueInstance('username', $userInstance);
121 $mailerInstance->addValueInstance('email', $userInstance);
124 $mailerInstance->addRecipientByUserInstance($userInstance);
126 // Use subject line from template
127 $mailerInstance->useSubjectFromTemplate();
129 // Send the email out
130 $mailerInstance->deliverEmail($responseInstance);
132 // Send out notification to admin (depends on settings)
133 $mailerInstance->sendAdminNotification($responseInstance);
137 * Adds extra filters to the given controller instance
139 * @param $controllerInstance A controller instance
140 * @param $requestInstance An instance of a class with an Requestable interface
143 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
144 // Filter for checking if account is unconfirmed
145 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_unconfirmed_filter_class'));