]> git.mxchange.org Git - city.git/blob - application/city/classes/commands/html/class_CityHtmlCityGuestLoginCommand.php
bb444a4180c395146889cde6fbeff9285d717540
[city.git] / application / city / classes / commands / html / class_CityHtmlCityGuestLoginCommand.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\City\Command;
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\Factory\ObjectFactory;
10 use Org\Mxchange\CoreFramework\Request\Requestable;
11 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
12 use Org\Mxchange\CoreFramework\Response\Responseable;
13
14 /**
15  * A command for guest logins
16  *
17  * @author              Roland Haeder <webmaster@shipsimu.org>
18  * @version             0.0.0
19  * @copyright   Copyright (c) 2015, 2016 City Developer Team
20  * @license             GNU GPL 3.0 or any newer version
21  * @link                http://www.shipsimu.org
22  *
23  * This program is free software: you can redistribute it and/or modify
24  * it under the terms of the GNU General Public License as published by
25  * the Free Software Foundation, either version 3 of the License, or
26  * (at your option) any later version.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this program. If not, see <http://www.gnu.org/licenses/>.
35  */
36 class CityHtmlCityGuestLoginCommand extends BaseCommand implements Commandable {
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45         }
46
47         /**
48          * Creates an instance of this command and sets the resolver instance
49          *
50          * @param       $resolverInstance       An instance of a command resolver
51          * @return      $commandInstance        The created command instance
52          */
53         public static final function createCityHtmlCityGuestLoginCommand (CommandResolver $resolverInstance) {
54                 // Get a new instance
55                 $commandInstance = new CityHtmlCityGuestLoginCommand();
56
57                 // Set the resolver instance
58                 $commandInstance->setResolverInstance($resolverInstance);
59
60                 // Return the prepared instance
61                 return $commandInstance;
62         }
63
64         /**
65          * Executes the command with given request and response objects
66          *
67          * @param       $requestInstance        An instance of a class with an Requestable interface
68          * @param       $responseInstance       An instance of a class with an Responseable interface
69          * @return      void
70          */
71         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
72                 // First get a GuestLogin instance
73                 $loginInstance = ObjectFactory::createObjectByConfiguredName('guest_login_class');
74
75                 // First set request and response instance
76                 $loginInstance->setRequestInstance($requestInstance);
77
78                 // Encrypt the password
79                 $loginInstance->encryptPassword('passwd');
80
81                 // Do the login here
82                 $loginInstance->doLogin($requestInstance, $responseInstance);
83
84                 // Was the login fine? Then redirect here
85                 if ($loginInstance->ifLoginWasSuccessfull()) {
86                         // Try to redirect here
87                         try {
88                                 // Redirect...
89                                 $responseInstance->redirectToConfiguredUrl('app_login');
90
91                                 // Exit here
92                                 exit();
93                         } catch (FrameworkException $e) {
94                                 // Something went wrong here!
95                                 $responseInstance->addFatalMessage($e->getMessage());
96                         }
97                 } else {
98                         // Attach error message to the response
99                         $responseInstance->addFatalMessage('failed_user_login');
100                 }
101         }
102
103         /**
104          * Adds extra filters to the given controller instance
105          *
106          * @param       $controllerInstance             A controller instance
107          * @param       $requestInstance                An instance of a class with an Requestable interface
108          * @return      void
109          * @todo        Add more filters
110          */
111         public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
112                 // Add username verifier filter
113                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_guest_verifier_filter'));
114
115                 // Add password verifier filter
116                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('passwd_guest_verifier_filter'));
117
118                 // Add CAPTCHA verifier code
119                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('captcha_guest_verifier_filter'));
120         }
121 }