lithium\security\Auth::check PHP Method

check() public static method

Performs an authentication check against the specified configuration, and writes the resulting user information to the session such that credentials are not required for subsequent authentication checks, and user information is returned directly from the session.
public static check ( string $name, mixed $credentials = null, array $options = [] ) : array
$name string The name of the `Auth` configuration/adapter to check against.
$credentials mixed A container for the authentication credentials used in this check. This will vary by adapter, but generally will be an object or array containing a user name and password. In the case of the `Form` adapter, it contains a `Request` object containing `POST` data with user login information.
$options array Additional options used when performing the authentication check. The options available will vary by adapter, please consult the documentation for the `check()` method of the adapter you intend to use. The global options for this method are: - `'checkSession'` _boolean_: By default, the session store configured for the adapter will always be queried first, to see if an authentication check has already been performed during the current user session. If yes, then the session data will be returned. By setting `'checkSession'` to `false`, session checks are bypassed and the credentials provided are always checked against the adapter directly. - `'writeSession'` _boolean_: Upon a successful credentials check, the returned user information is, by default, written to the session. Set this to `false` to disable session writing for this authentication check. - `'persist'` _array_: A list of fields that should be stored in the session. If no list is provided will store all fields in the session except the `'password'` field.
return array After a successful credential check against the adapter (or a successful lookup against the current session), returns an array of user information from the storage backend used by the configured adapter.
    public static function check($name, $credentials = null, array $options = array())
    {
        $config = static::config($name);
        $defaults = array('checkSession' => true, 'writeSession' => true, 'persist' => $config['session']['persist'] ?: static::_config('persist'));
        $options += $defaults;
        $params = compact('name', 'credentials', 'options');
        return static::_filter(__FUNCTION__, $params, function ($self, $params) {
            extract($params);
            $config = $self::invokeMethod('_config', array($name));
            if ($config === null) {
                throw new ConfigException("Configuration `{$name}` has not been defined.");
            }
            $session = $config['session'];
            if ($options['checkSession']) {
                if ($data = $session['class']::read($session['key'], $session['options'])) {
                    return $data;
                }
            }
            if ($credentials && ($data = $self::adapter($name)->check($credentials, $options))) {
                if ($options['persist'] && is_array($data)) {
                    $data = array_intersect_key($data, array_fill_keys($options['persist'], true));
                } elseif (is_array($data)) {
                    unset($data['password']);
                }
                return $options['writeSession'] ? $self::set($name, $data) : $data;
            }
            return false;
        });
    }

Usage Example

 public function add()
 {
     $login = Auth::check('member');
     if ($this->request->data) {
         $software = Software::create($this->request->data);
         if ($software->save()) {
             $file = File::create();
             foreach ($this->request->data['myfile'] as $key => $value) {
                 $size = $this->request->data['myfile'][$key]['size'];
                 if ($size >= 600000001) {
                     $chunksize = $size / 20;
                 } else {
                     if ($size <= 600000000 && $size >= 100000000) {
                         $chunksize = $size / 10;
                     } else {
                         if ($size <= 100000000 && $size >= 10000000) {
                             $chunksize = 10000000;
                         } else {
                             $chunksize = 1000000;
                         }
                     }
                 }
                 $save = $file->save(array('file' => $value, 'software_id' => (string) $software->_id, 'chunkSize' => 10000000));
                 if (!$save) {
                     return compact('save');
                 }
             }
         }
     }
     $software = Software::create();
     return compact('login', 'software');
 }
All Usage Examples Of lithium\security\Auth::check