Authorization does not work. Create user:

public function action_create() { $auth = Auth::instance(); $user = ORM::factory('user'); $email = $_POST['email']; $password = $auth->hash_password($_POST['password']); $nickname = $_POST['nickname']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $user->email = $email; $user->password = $password; $user->username = $nickname; $user->birth = $month." ".$day." ".$year; $user->save(); $user = ORM::factory('user'); $role = ORM::factory('roles'); $role->user_id = $user->select('id')->where('email', '=', $email)->find(); $role->role_id = "1"; $role->save(); echo "<div id='create'>Account is created, you can enter now.</div>"; } 

The user is added to the database, it works. The role to the user is added immediately too.

Authorization:

  public function action_login() { if ($_POST){ $username = Arr::get($_POST, 'login', ''); $password = Arr::get($_POST, 'password', ''); $status = Auth::instance()->login($username, $password, TRUE); if($status){ echo 'Ok'; }else{ echo 'Error'; } } 

I do not know what the problem is. Help me please.

In the module returns

 ErrorException [ Notice ]: Undefined index: trane294 MODPATH\auth\classes\kohana\auth\file.php [ 50 ] 43 if (isset($this->_users[$username]) AND $this->_users[$username] === $password) 44 { 45 // Complete the login 46 return $this->complete_login($username); 47 } 48 49 // Login failed 50 return FALSE; 51 } 52 53 /** 54 * Forces a user to be logged in, without specifying a password. 
  • To log in the user must have a role = 2. Roles: admin (1,2) user (2) - Vfvtnjd
  • '1', 'login', 'Login privileges, granted after account confirmation' '2', 'admin', 'Administrative user, has access to everything.' Are you sure? - trane294
  • It seems all right? - trane294

1 answer 1

 $password = $auth->hash_password($_POST['password']); 

No need to hash the password if you inherit / use the built-in User model, since there it is done for you.

In addition. Using the ORM to tie the role can be much more beautiful:

 $user->add('roles', ORM::factory('role', array('name' => 'login'))) 
  • I checked everything correctly with a password, in the module returns "ErrorException [Notice]: Undefined index: trane294" "MODPATH \ auth \ classes \ kohana \ auth \ file.php [50] 45 // Complete the login 46 return $ this-> complete_login ($ username); 47} 48 49 // Login failed 50 return $ this -> _ users [$ username]; 51} 52 53 / ** 54 * - trane294
  • auth\file.php ? driver in modules/auth/config/auth.php which one is specified? - xEdelweiss
  • 'driver' => 'file', - trane294
  • Well, and should be orm, right? - xEdelweiss
  • Thank you very much everything works! - trane294