Ejemplo n.º 1
0
 public function login($username = '', $password = '', $remember = '')
 {
     $user = $this->find($username);
     if (!$username && !$password && $this->exists()) {
         Session::put($this->_sessionName, $this->data()->id);
     } else {
         $this->find($username);
         if ($user) {
             if ($this->data()->password === Hash::make($password)) {
                 Session::put($this->_sessionName, $this->data()->id);
                 if ($remember) {
                     $hash = Hash::unique();
                     $hashCheck = $this->_db->get('users_session', ['user_id', '=', $this->data()->id]);
                     if (!$hashCheck->count()) {
                         $this->_db->insert('users_session', ['user_id' => $this->data()->id, 'hash' => $hash]);
                     } else {
                         $hash = $hashCheck->first()->hash;
                     }
                     Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
                 }
                 return true;
             }
         }
     }
     return false;
 }