Kohana 3: Подлинный модуль

я пытаюсь изучить Подлинный модуль Kohana, но метод входа в систему всегда возвращает false.

Контроллер:

<?php defined('SYSPATH') OR die('No Direct Script Access');
class Controller_Auth extends Controller {
    public function action_index() {
        if($_POST) {
            $this->login();
        }

        $this->template = View::factory('login');
        echo $this->template;
    }

    private function login() {
    $user = ORM::factory('user');

        $data = array('username' => 'wilson', 'password' => '123');
        if(!$user->login($data)) {
            echo 'FAILED!';
        }
    }

    private function logout() {

    }
}    
?>

Модель:

<?php defined('SYSPATH')  or die('No direct script access.');
class Model_User extends Model_Auth_User {
}
?>
1
задан Thomas 9 June 2010 в 18:54
поделиться

2 ответа

Вы делаете это неправильно.

Чтобы войти в систему, сделайте что-то вроде этого:

$auth = Auth::instance();
if ($auth->login($_POST['username'], $_POST['password']))
{
      echo 'hello, '.$auth->$_POST['username'];
}
else
{
      echo 'login failed!';
}

Также раскомментируйте строку модуля auth в начальной загрузке вашего приложения:

'auth'       => MODPATH.'auth',       // Basic authentication
1
ответ дан 2 September 2019 в 23:53
поделиться

Я не добавлял правила для пользователя. Для получения дополнительной информации [см. Эту ссылку] [1].

Спасибо, ребята, и прошу прощения за это :)

http://webcache.googleusercontent.com/search?q=cache:kXKFWswjDogJ:kerkness.ca/kowiki/doku.php%3Fid%3Dusing_the_auth_module_in_your_controllers+&cd=1 = en & ct = clnk & gl = us

public function action_signin()
{
    #If user already signed-in
    if(Auth::instance()->logged_in()!= 0){
        #redirect to the user account
        Request::instance()->redirect('account/myaccount');     
    }

    $content = $this->template->content = View::factory('signin');  

    #If there is a post and $_POST is not empty
    if ($_POST)
    {
        #Instantiate a new user
        $user = ORM::factory('user');

        #Check Auth
        $status = $user->login($_POST);

        #If the post data validates using the rules setup in the user model
        if ($status)
        {       
            #redirect to the user account
            Request::instance()->redirect('account/myaccount');
        }else
        {
                            #Get errors for display in view
            $content->errors = $_POST->errors('signin');
        }

    }
}
1
ответ дан 2 September 2019 в 23:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: