Skip to content
Snippets Groups Projects
Authentication.php 3.95 KiB
Newer Older
<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Authentication extends Controller {
        
        public function before() {
            parent::before();
PavelBegunkov's avatar
PavelBegunkov committed
            if(UTF8::strcasecmp($this->request->action(), 'logout')) {
                $user = User::instance();
                if($user->isSignedIn()) {
                    $request = $user->Type . '/index';
PavelBegunkov's avatar
PavelBegunkov committed
                    $page = Request::factory($request)->execute();
                    $this->response->body($page);
                }
            }
        }
        protected function getUpdates()
PavelBegunkov's avatar
PavelBegunkov committed
        {
            $fp = fopen(APPPATH.'updates.txt', 'r');
PavelBegunkov's avatar
PavelBegunkov committed
            $updates['Date'] = fgets($fp, 999);
            $text = '<ol>';
            if ($fp) {
                while (!feof($fp)) {
                    $text .= '<li>'.fgets($fp, 999).'</li>';
PavelBegunkov's avatar
PavelBegunkov committed
            }
            $text .= '</ol>';
            $updates['Text'] = $text;
            return $updates;
RomanSteinberg's avatar
RomanSteinberg committed

        private function sign()
        {
            if(!User::instance()->isSignedIn())
            {
                $type = $this->request->param('type');
                $type = empty($type)? 'in': $type;
                $twig = Twig::factory('sign/'.$type);
                
                $twig->Updates = Model_System::getChangeLog();
                $this->response->body($twig);
            }
        }
RomanSteinberg's avatar
RomanSteinberg committed

        public function action_enter_backdoor()
        {
            $this->sign();
        }

        public function action_enter_frontdoor()
        {
            $admission = true;
RomanSteinberg's avatar
RomanSteinberg committed
            $isNotSigned = !User::instance()->isSignedIn();
            $isNotAdmin = !User::instance()->isAdmin();
            if($isNotSigned || $isNotAdmin)
RomanSteinberg's avatar
RomanSteinberg committed
            {
                $admission = !$this->check_maintenance();
RomanSteinberg's avatar
RomanSteinberg committed
                $this->sign();
            } else
                User::instance()->signOut();
        public function action_remind()
        {
            {
                $twig = Twig::factory('sign/remindpass');
PavelBegunkov's avatar
PavelBegunkov committed
                $twig->Updates = self::getUpdates();
                $this->response->body($twig);
            }
        }
        
        public function action_endremind()
        {
PavelBegunkov's avatar
PavelBegunkov committed
            if (!Account::instance()->checkToken($token)) {
                $message = "Данная ссылка для восстановления пароля более не действительна!\n" .
                    "Либо истекло время действия ссылки, либо она уже была использована.";
                throw HTTP_Exception::factory(403, $message);
PavelBegunkov's avatar
PavelBegunkov committed
            }

            if (!User::instance()->isSignedIn()) {
                $twig = Twig::factory('sign/changepass');
                $twig->Updates = self::getUpdates();
                $this->response->body($twig);
            }
        }
        
        public function action_logout()
        {
            $this->redirect('sign', 302);
RomanSteinberg's avatar
RomanSteinberg committed
        private function check_maintenance()
        {
            $maintenance_info = Model_Account::getMaintenanceInfo();
RomanSteinberg's avatar
RomanSteinberg committed
            if ($maintenance_info['active']) {
                $this->response->status(503);
                $twig = Twig::factory('errors/http');
                $twig->title = 'Закрыто на техобслуживание!';
                $twig->code = 503;
                $twig->message = "Восстановление работы сервиса: " . $maintenance_info['return'];
                $this->response->body($twig);
                return true;
            }
            else
                return false;
        }

        public function action_check_maintenance()
        {
            $this->check_maintenance();
        }

} // End Welcome