Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace controller;
- require_once("model/LoginModel.php");
- require_once("view/LoginView.php");
- class LoginController {
- private $model;
- private $view;
- public function __construct(\model\LoginModel $model, \view\LoginView $view) {
- $this->model = $model;
- $this->view = $view;
- }
- public function doToggleLoginState() {
- $userClient = $this->view->getUserClientInfo(); //Browser etc
- if ($this->model->isLoggedIn($userClient)) { //To check session-steal
- $this->whenLoggedIn();
- } else {
- $this->whenLoggedOut();
- }
- $this->model->renewTemporaryPasswords($userClient);
- }
- private function whenLoggedIn() {
- if ($this->view->userWantsToLogout()) {
- $this->model->doLogout();
- $this->view->setUserLogout();
- }
- }
- private function whenLoggedOut() {
- if ($this->view->userWantsToLogin()) {
- try {
- $uc = $this->view->getCredentials();
- if ($this->model->doLogin($uc) == true) {
- $this->view->setLoginSucceeded();
- } else {
- $this->view->setLoginFailed();
- }
- } catch (\Exception $e) {
- var_dump($e); //debug
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement