Created
December 11, 2011 16:50
-
-
Save drakmail/1461507 to your computer and use it in GitHub Desktop.
Авторизация в toodle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use toodle\core\BasicController; | |
| /** | |
| * Controller for main part | |
| */ | |
| class MainController extends BasicController | |
| { | |
| /** | |
| * @var $logged string Does user logged in? | |
| */ | |
| private $logged; | |
| public function initRoutes() | |
| { | |
| if ($this->logged) | |
| { | |
| return array ( | |
| '^/$'=>'run__index', | |
| '^/login/$'=>'run__login', | |
| '^/login/check/$'=>'run__login_check', | |
| '^/logout/$'=>'run__logout', | |
| ); | |
| } else { | |
| return array ( | |
| '/'=>'run__login', | |
| '^/login/$'=>'run__login', | |
| '^/login/check/$'=>'run__login_check', | |
| ); | |
| } | |
| } | |
| public function init() | |
| { | |
| $auth = $this->loadModel('auth/auth'); | |
| $this->setVar('base_path','/contrib/main/resources'); | |
| $this->logged = $auth->checkCookie(); | |
| $this->setVar('user',$auth->getUser()); | |
| } | |
| public function run__login() | |
| { | |
| $params = array(); | |
| return $this->loadView('login.html',$params); | |
| } | |
| public function run__login_check() | |
| { | |
| $auth = $this->loadModel('auth/auth'); | |
| $user = $auth->checkAuth($_POST['login'],$_POST['password']); | |
| if ($user != null) { | |
| $auth->setCookie($user); | |
| header('Location: /'); | |
| } else { | |
| $params = array('error'=>'Неверный логин или пароль'); | |
| return $this->loadView('login.html',$params); | |
| } | |
| } | |
| public function run__logout() | |
| { | |
| $auth = $this->loadModel('auth/auth'); | |
| $auth->clearCookie(); | |
| $params = array(); | |
| return $this->loadView('login.html',$params); | |
| } | |
| public function run__index() | |
| { | |
| $params = array(); | |
| return $this->loadView('index.html',$params); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment