|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace app\controllers; |
| 4 | + |
| 5 | +use app\core\Application; |
| 6 | +use app\core\Controller; |
| 7 | +use app\core\Request; |
| 8 | +use app\core\Response; |
| 9 | +use app\models\Admin; |
| 10 | +use app\models\Customer; |
| 11 | +use app\models\CustomerLoginForm; |
| 12 | + |
| 13 | +//use app\core\Response; |
| 14 | +use app\models\CustomerRegisterModel; |
| 15 | +use app\models\ServiceCenter; |
| 16 | +use app\models\ServiceCenterLogin; |
| 17 | +use app\models\Technician; |
| 18 | +use app\models\ServiceCentre; |
| 19 | +use app\models\TechnicianLogin; |
| 20 | + |
| 21 | +class AuthController extends Controller |
| 22 | +{ |
| 23 | + /* customer sign up method */ |
| 24 | + public function customerSignUp(Request $request) |
| 25 | + { |
| 26 | + $customer = new Customer(); |
| 27 | + if ($request->isPost()) { |
| 28 | + |
| 29 | + $customer->loadData($request->getBody()); |
| 30 | + if ($customer->validate() && $customer->save()) { |
| 31 | + Application::$app->session->setFlash('success', 'You have been registered successfully!'); |
| 32 | + Application::$app->response->redirect('/customer-login'); |
| 33 | + } |
| 34 | + $this->setLayout('auth'); |
| 35 | + return $this->render('/customer/customer-sign-up', [ |
| 36 | + 'model' => $customer |
| 37 | + ]); |
| 38 | + } |
| 39 | + $this->setLayout('auth'); |
| 40 | + return $this->render('/customer/customer-sign-up', [ |
| 41 | + 'model' => $customer |
| 42 | + ]); |
| 43 | + } |
| 44 | + |
| 45 | + /* customer login method */ |
| 46 | + public function customerLogin(Request $request, Response $response) |
| 47 | + { |
| 48 | + $loginForm = new CustomerLoginForm(); |
| 49 | + if ($request->isPost()) { |
| 50 | + $loginForm->loadData($request->getBody()); |
| 51 | + if ($loginForm->validate() && $loginForm->login()) { |
| 52 | + $response->redirect('/customer-dashboard'); // later will change this to customer dashboard |
| 53 | + $customer = new Customer(); |
| 54 | + $customer->customerAddressGeocoding(); |
| 55 | + return; |
| 56 | + } |
| 57 | + } |
| 58 | + $this->setLayout('auth'); |
| 59 | + return $this->render('/customer/customer-login', [ |
| 60 | + 'model' => $loginForm |
| 61 | + ]); |
| 62 | + } |
| 63 | + |
| 64 | + /* customer logout method */ |
| 65 | + public function customerLogout(Request $request, Response $response) |
| 66 | + { |
| 67 | + Application::$app->logoutCustomer(); |
| 68 | + $response->redirect('/'); |
| 69 | + } |
| 70 | + |
| 71 | + /* technician sign up method */ |
| 72 | + public function technicianSignUp(Request $request) |
| 73 | + { |
| 74 | + $technician = new Technician(); |
| 75 | + if ($request->isPost()) { |
| 76 | + $technician->loadData($request->getBody()); |
| 77 | + |
| 78 | + if ($technician->validate() && $technician->save()) { |
| 79 | + Application::$app->session->setFlash('success', 'You have been registered successfully!'); |
| 80 | + Application::$app->response->redirect('/technician-login'); |
| 81 | + } |
| 82 | + $this->setLayout('auth'); |
| 83 | + return $this->render('/technician/technician-sign-up', [ |
| 84 | + 'model' => $technician |
| 85 | + ]); |
| 86 | + } |
| 87 | + $this->setLayout('auth'); |
| 88 | + return $this->render('/technician/technician-sign-up', [ |
| 89 | + 'model' => $technician |
| 90 | + ]); |
| 91 | + } |
| 92 | + |
| 93 | + // technician login method |
| 94 | + public function technicianLogin(Request $request, Response $response) |
| 95 | + { |
| 96 | + $technicianLogin = new TechnicianLogin(); |
| 97 | + if ($request->isPost()) { |
| 98 | + $technicianLogin->loadData($request->getBody()); |
| 99 | + if ($technicianLogin->validate() && $technicianLogin->loginTechnician()) { |
| 100 | + $response->redirect('/technician-dashboard'); |
| 101 | + $technician = new Technician(); |
| 102 | + $technician->technicianAddressGeocoding(); |
| 103 | + return; |
| 104 | + } |
| 105 | + } |
| 106 | + $this->setLayout('auth'); |
| 107 | + return $this->render('/technician/technician-login', ['model' => $technicianLogin]); |
| 108 | + } |
| 109 | + |
| 110 | + public function technicianLogOut(Request $request, Response $response) |
| 111 | + { |
| 112 | + Application::$app->logoutTechnician(); |
| 113 | + $response->redirect('/'); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + /* service centre sign up method */ |
| 118 | + |
| 119 | + public function serviceCentreSignup(Request $request) |
| 120 | + { |
| 121 | + $registerModel = new ServiceCenter(); |
| 122 | + if ($request->isPost()) { |
| 123 | + $registerModel->loadData($request->getBody()); |
| 124 | + |
| 125 | + if ($registerModel->validate() && $registerModel->save()) { |
| 126 | + Application::$app->session->setFlash('success', 'You have been registered successfully!'); |
| 127 | + Application::$app->response->redirect('/service-centre-login'); |
| 128 | + } |
| 129 | + $this->setLayout('auth'); |
| 130 | + return $this->render('/service-centre/service-centre-sign-up', [ |
| 131 | + 'model' => $registerModel |
| 132 | + ]); |
| 133 | + } |
| 134 | + $this->setLayout('auth'); |
| 135 | + return $this->render('/service-centre/service-centre-sign-up', [ |
| 136 | + 'model' => $registerModel |
| 137 | + ]); |
| 138 | + } |
| 139 | + |
| 140 | + /* service centre login method */ |
| 141 | +// public function serviceCentreLogin(Request $request) |
| 142 | + // service centre login method |
| 143 | + public function serviceCentreLogin(Request $request, Response $response) |
| 144 | + { |
| 145 | + $serviceCenterLogin = new ServiceCenterLogin(); |
| 146 | + if ($request->isPost()) { |
| 147 | + $serviceCenterLogin->loadData($request->getBody()); |
| 148 | + if ($serviceCenterLogin->validate() && $serviceCenterLogin->loginServiceCenter()) { |
| 149 | + $response->redirect('/service-centre-dashboard'); |
| 150 | + $service_centre = new ServiceCenter(); |
| 151 | + $service_centre->serviceCentreAddressGeocoding(); |
| 152 | + return; |
| 153 | + } |
| 154 | + } |
| 155 | + $this->setLayout('auth'); |
| 156 | + return $this->render('/service-centre/service-centre-login', [ |
| 157 | + 'model' => $serviceCenterLogin |
| 158 | + ]); |
| 159 | + } |
| 160 | + |
| 161 | + public function serviceCenterLogout(Request $request, Response $response) |
| 162 | + { |
| 163 | + Application::$app->logoutServiceCenter(); |
| 164 | + $response->redirect('/service-centre-landing'); |
| 165 | + } |
| 166 | + |
| 167 | + /* admin sign up method */ |
| 168 | + public function adminSignUp(Request $request) |
| 169 | + { |
| 170 | + $admin = new Admin(); |
| 171 | + if ($request->isPost()) { |
| 172 | + |
| 173 | + $admin->loadData($request->getBody()); |
| 174 | + if ($admin->validate() && $admin->save()) { |
| 175 | + Application::$app->session->setFlash('success', 'You have been registered successfully!'); |
| 176 | + Application::$app->response->redirect('/admin-login'); |
| 177 | + } |
| 178 | + $this->setLayout('auth'); |
| 179 | + return $this->render('/admin/admin-sign-up', [ |
| 180 | + 'model' => $admin |
| 181 | + ]); |
| 182 | + } |
| 183 | + $this->setLayout('auth'); |
| 184 | + return $this->render('/admin/admin-sign-up', [ |
| 185 | + 'model' => $admin |
| 186 | + ]); |
| 187 | + } |
| 188 | + |
| 189 | +} |
0 commit comments