0

New to kohana here. I have a task from my internship to make login system with kohana framework 3.2 . I also did it to insert,update and delete stuff with auto modeler ORM. I have some trouble now with kohana auth. I already have the database structure Imported and inserted an user in the 'users' table and give him a role in the 'roles_user' table.

Also created an Auth.php file in APP/config/ :

return array(

    'driver'       => 'AutoModeler_ORM',
    'hash_method'  => 'sha256',
    'hash_key'     => 'Somebiglonghaskeyofmixedcharacters102345567709',
    'lifetime'     => 1209600,
    'session_type' => Session::$default,
    'session_key'  => 'auth_user',
);

In my controller , I have a login function with the following code:

if ($_POST)
{
$post = $this->request->post();
$success = Auth::instance()->login($post['email'], $post['password']);

if ($success)
{
echo "Welcome!";
}
else
{
echo "Something goes wrong...";
}

}

I already have activated the modules in the bootstrap.

pastebin link to my role model : http://pastebin.com/bQYReETh pastebin link to my user model : http://pastebin.com/ufzvKjmA

The problem is that I always come in the else.

Does somebody have an idea whats going on? Do I miss something?

woodle
  • 59
  • 5
  • What is the error that you are experiencing? It's not clear from the question exactly what the issue you are having is. – jcern Oct 30 '12 at 14:19
  • 1
    The error is that I always come in the else statement by $succes . Thanks for saying it. I have edited my question. – woodle Oct 30 '12 at 14:44
  • When Auth calls `$this->_login()`, it's likely not finding the user in it's query from the model. – wesside Oct 30 '12 at 17:52
  • Also, does that user have the ability to login? $can_login = `Auto_Modeler_ORM::factory('user', 'Foo')->has('role', 'login');` – wesside Oct 30 '12 at 17:58
  • 1
    Thanks for your comment bigman! I also found some information here : http://dev.kohanaframework.org/projects/automodeler/wiki/Auth . I don't understand what $can_login for function has? If I'm right, I create a model and check for his role? But where can I use it? I only create a variable that is unused? I hope somebody can answer it – woodle Oct 31 '12 at 11:07

1 Answers1

2

@Woodle,

Maybe adding a _constructor can help.

public function __construct($id = NULL)
    {
        if ($id !== NULL)
        {
            $this->load(db::select_array($this->fields())->where($this->_table_name.'.username', '=', $id));
        }
        elseif ($this->id) // We loaded this via mysql_result_object
        {
            parent::__construct($id);
        }
    }
Findi
  • 36
  • 1
  • @woodle did fix your problem becuz i'm have the same – Findi Nov 07 '12 at 11:09
  • My kohana Auth with auto-modeler_orm works fine now. My other problem was that I set relationships in ORM style and not in auto-modeler_ORM style. What kind of problems do you have ? – woodle Nov 07 '12 at 12:43