Вопрос

I’d like to build a stateless system with Kohana, so I don’t want to use sessions. I’d like to send a username and password with every request (how those credentials are transferred is irrelevant at this point), check that the credentials are correct with Kohana, and respond with the relevant data or a 401.

I understand I’ll probably need to extend the Auth module, but for some reason I keep getting 500s. Here’s what I’m trying:

classes/Auth.php

<?php defined('SYSPATH') OR die('No direct access allowed');

class Auth extends Kohana_Auth {

    public static function checkCredentials($username, $password) {
        return TRUE;
    }

    public function password($username) {
        parent::password($username);
    }

    public function check_password($password) {
        parent::check_password($password);
    }

    protected function _login($username, $password) {
        parent::_login($username, $password);
    }

}

classes/Controller/Frontdesk.php

<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller_Frontdesk extends Kohana_Controller {

    public function before() {
        parent::before();

        // If not logged in, throw exception
        if (!Auth::checkCredentials('john@acme.com','fido')) throw new HTTP_Exception_401();

    }

}
Это было полезно?

Решение

As it turned out, I had incorrectly declared a method of a class that I was extending.

The Auth class in Kohana defines this method:

abstract protected functin _login($username, $password, $remember);

Since I didn’t need passwords to be remembered, I thought it would be alright to declare the method as:

protected function _login($username, $password) {};

I was wrong.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top