Download
Version 1.0

Coda 2 Theme, Kaleidoscope

<?php namespace zenangst\Auth\Drivers; use zenangst\Hash, zenangst\Config;

class Eloquent extends Driver {
  /**
   * Get the current user of the application
   *
   * If the user is a guest, null should be returned
   *
   * @param int $id
   * @return mixed|null
   */

  public function retrieve($id) {
    if (filter_var($id, FILTER_VALIDATE_INT) !== false) {
      return $this->model()->find($id);
    }
  }
  
  /**
   * Attempt to log a user into application.
   *
   * @param array $arguments
   * @return void
   */

   public function attempt($arguments = array()) {
    $username = Config::get('auth.username');
    
    $user = $this->model()->where($username, '=', $arguments['username'])->first();
    
    // This driver uses basic username and password authentication scheme
    // so if the credentials match what is in the database we will just
    // log the user info the application and remember them if asked.
    $password = $arguments['password'];
    
    if ( ! is_null($user) and Hash::check($password, $user->password)) {
      return $this->login($user->id, array_get($arguments, 'remember'));
    }
    
    return false;
   }
}

?>