3 namespace CoreFramework\Command\Guest;
5 // Import framework stuff
6 use CoreFramework\Command\BaseCommand;
7 use CoreFramework\Factory\ObjectFactory;
8 use CoreFramework\Registry\Generic\Registry;
9 use CoreFramework\Request\Requestable;
10 use CoreFramework\Response\Responseable;
13 * A command class for resending the confirmation link
15 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
34 class HtmlResendLinkCommand extends BaseCommand implements Commandable {
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
46 * Creates an instance of this class
48 * @param $resolverInstance An instance of a command resolver class
49 * @return $commandInstance An instance a prepared command class
51 public static final function createHtmlResendLinkCommand (CommandResolver $resolverInstance) {
53 $commandInstance = new HtmlResendLinkCommand();
55 // Set the application instance
56 $commandInstance->setResolverInstance($resolverInstance);
58 // Return the prepared instance
59 return $commandInstance;
63 * Executes the given command with given request and response objects
65 * @param $requestInstance An instance of a class with an Requestable interface
66 * @param $responseInstance An instance of a class with an Responseable interface
69 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
70 // Get user instance from registry
71 $userInstance = Registry::getRegistry()->getInstance('user');
73 // Get an application instance
74 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
76 // Get a RNG instance (Random Number Generator)
77 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
79 // Generate a pseudo-random string
80 $randomString = $rngInstance->randomString(255);
82 // Get a crypto instance
83 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
85 // Hash and encrypt the string
86 $hashedString = $cryptoInstance->hashString($cryptoInstance->encryptString($randomString));
88 // Update the user class
89 $userInstance->updateDatabaseField(UserDatabaseWrapper::DB_COLUMN_CONFIRM_HASH, $hashedString);
91 // Re-set config entry to mailer engine
92 $this->getConfigInstance()->setConfigEntry('html_template_class', $this->getConfigInstance()->getConfigEntry('mail_template_class'));
94 // Prepare the template engine
95 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
97 // Assign the application data with the template engine
98 $templateInstance->assignApplicationData($applicationInstance);
100 // Get a mailer class
101 $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance, $applicationInstance, 'resend_link'));
103 // Set this mailer in our template engine
104 $templateInstance->setMailerInstance($mailerInstance);
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');
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);
119 $mailerInstance->addRecipientByUserInstance($userInstance);
121 // Use subject line from template
122 $mailerInstance->useSubjectFromTemplate();
124 // Send the email out
125 $mailerInstance->deliverEmail($responseInstance);
127 // Send out notification to admin (depends on settings)
128 $mailerInstance->sendAdminNotification($responseInstance);
132 * Adds extra filters to the given controller instance
134 * @param $controllerInstance A controller instance
135 * @param $requestInstance An instance of a class with an Requestable interface
138 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
139 // Filter for checking if account is unconfirmed
140 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_unconfirmed_filter'));