开发者

kohana2 auth - login problem

开发者 https://www.devze.com 2023-03-16 01:34 出处:网络
I\'m trying to make a login form for my kohana2 app using ORM example presented in kohana2 docs ( http://docs.kohanaphp开发者_如何学Go.com/addons/auth ). I\'ve done everything like in the wiki but aft

I'm trying to make a login form for my kohana2 app using ORM example presented in kohana2 docs ( http://docs.kohanaphp开发者_如何学Go.com/addons/auth ). I've done everything like in the wiki but after providing username, password and sending a form, nothing happens. No error, no exception, nothing! just the same form without any errors.

Here is the controller action, the only thing i've changed was adding a template functionality: http://pastebin.com/jEc4nqSP

There is a die() function in line 42, it's there for debug purposes. After sending a form, it displays Array ( [username] => invalid ) 1. I'm sure i have that user data in database and i'm providing a proper username and password. Roles are set to login. Have you any idea what am i doing wrong ?

Thanks.


On line 39 you are creating an empty ORM user object. At a minimum, surely you want:

ORM::factory('user', $post['username'])

Although you probably want to refactor that, so it actually checks that the username value is set.


Ok problem solved! All we need to do is to create a new user with this code (registration controller from kohana2 docs):

<?php
// grab relevant $_POST data
$username = $this->input->post('username');
$password = $this->input->post('password');

// instantiate User_Model and set attributes to the $_POST data
$user = ORM::factory('user');
$user->username = $username;
$user->password = Auth::instance()->hash_password($password);

// if the user was successfully created...
if ($user->add(ORM::factory('role', 'login')) AND $user->save()) {

    // login using the collected data
    Auth::instance()->login($username, $password);

    // redirect to somewhere         
    url::redirect('user/profile');
}

The previous admin login data was not working cause the password was not hashed properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号