Example #1
0
 /**
  * Действие для авторизации пользователя
  */
 public function action_login()
 {
     // Already logged in
     \Auth::check() and \Response::redirect('admin/articles');
     $val = \Validation::forge();
     if (\Input::method() == 'POST') {
         $val->add('email', 'Логин')->add_rule('required');
         $val->add('password', 'Пароль')->add_rule('required');
         if ($val->run()) {
             $auth = \Auth::instance();
             // check the credentials. This assumes that you have the previous table created
             if (\Auth::check() or $auth->login(\Input::post('email'), \Input::post('password'))) {
                 // credentials ok, go right in
                 if (\Config::get('auth.driver', 'Simpleauth') == 'Ormauth') {
                     $current_user = \Model\Auth_User::find_by_username(\Auth::get_screen_name());
                 } else {
                     $current_user = \Model_User::find_by_username(\Auth::get_screen_name());
                 }
                 \Session::set_flash('success', 'Добро пожаловать, <b>' . $current_user->username . '</b>');
                 \Response::redirect('admin/articles');
             } else {
                 \Session::set_flash('error', 'Неверная комбинация логина и пароля.');
             }
         }
     }
     $this->template->title = 'Авторизация';
     $this->template->content = \View::forge('login', array('val' => $val), false);
 }
Example #2
0
 public function before()
 {
     parent::before();
     \Config::load('Admin::config');
     // Assign current_user to the instance so controllers can use it
     if (\Config::get('auth.driver', 'Simpleauth') == 'Ormauth') {
         $this->current_user = \Auth::check() ? \Model\Auth_User::find_by_username(\Auth::get_screen_name()) : null;
     } else {
         $this->current_user = \Auth::check() ? \Model_User::find_by_username(\Auth::get_screen_name()) : null;
     }
     // Set a global variable so views can use it
     \View::set_global('current_user', $this->current_user);
 }