Exemple #1
0
 /**
  * Validates login information from an array, and optionally redirects
  * after a successful login.
  *
  * @param  array    values to check
  * @param  string   URI or URL to redirect to
  * @return boolean
  */
 public function login(array &$array, $redirect = false)
 {
     // Login starts out invalid
     $status = false;
     // Log login attempt
     $login = new Login_Model();
     $login->password = !empty($array['password']);
     $login->username = $array['username'];
     if ($this->validate($array, false, array(), array(), array('rules' => 'login'))) {
         // Attempt to load the user
         $this->find_user($array['username']);
         if ($this->loaded()) {
             $login->uid = $this->id;
             $login->username = $this->username;
             if (Visitor::instance()->login($this, $array['password'])) {
                 $login->success = 1;
                 // Redirect after a successful login
                 if (is_string($redirect)) {
                     $login->save();
                     url::redirect($redirect);
                 }
                 // Login is successful
                 $status = true;
             } else {
                 $array->add_error('username', 'invalid');
             }
         }
     }
     $login->save();
     return $status;
 }