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 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');
 }
Ejemplo n.º 2
0
 public function add()
 {
     if ($this->request->data && Auth::check('default', $this->request)) {
         return $this->redirect('/');
     } else {
     }
 }
 public function index()
 {
     $login = Auth::check('member');
     $actief = self::$actief;
     $breadcrumb = self::$breadcrumb;
     return compact('login', 'actief', 'breadcrumb');
 }
Ejemplo n.º 4
0
 public function testManualSessionFail()
 {
     $this->assertFalse(Auth::check('test'));
     $user = array('id' => 13, 'user' => 'bob');
     $this->assertFalse(Auth::set('test', $user, array('fail' => true)));
     $this->assertFalse(Auth::check('test'));
 }
Ejemplo n.º 5
0
 public function testAuthPersist()
 {
     Auth::reset();
     Auth::config(array('test' => array('adapter' => $this->_classes['mockAuthAdapter'])));
     $config = Auth::config();
     $this->assertTrue(isset($config['test']['session']['persist']));
     $this->assertTrue(empty($config['test']['session']['persist']));
     $user = array('username' => 'foo', 'password' => 'bar');
     $result = Auth::check('test', $user, array('success' => true));
     $this->assertTrue(isset($result['username']));
     $this->assertFalse(isset($result['password']));
     Auth::reset();
     Auth::config(array('test' => array('adapter' => $this->_classes['mockAuthAdapter'], 'session' => array('persist' => array('username', 'email')))));
     $user = array('username' => 'foobar', 'password' => 'not!important', 'email' => '*****@*****.**', 'insuranceNumer' => 1234567);
     $expected = array('username' => 'foobar', 'email' => '*****@*****.**');
     $result = Auth::check('test', $user, array('success' => true, 'checkSession' => false));
     $this->assertEqual($expected, $result);
     $this->assertEqual($expected, Session::read('test'));
     Auth::reset();
     Auth::config(array('test' => array('adapter' => $this->_classes['mockAuthAdapter'])));
     $user = array('id' => '123', 'username' => 'foobar', 'password' => 'not!important', 'email' => '*****@*****.**', 'insuranceNumer' => 1234567);
     $expected = 123;
     $result = Auth::check('test', $user, array('keyOnly' => true, 'checkSession' => false));
     $this->assertEqual($expected, $result);
     $this->assertEqual($expected, Session::read('test'));
 }
 public function index()
 {
     $login = Auth::check('member');
     $actief = array('start' => 'active', 'lijsten' => '', 'beheren' => '');
     $breadcrumb = array(array('naam' => 'Start'));
     return compact('login', 'actief', 'breadcrumb');
 }
Ejemplo n.º 7
0
 public function testNoConfigurations()
 {
     Auth::reset();
     $this->assertIdentical(array(), Auth::config());
     $this->expectException("Configuration `user` has not been defined.");
     Auth::check('user');
 }
 /**
  * List all users, if accessor is authed
  *
  * @return array
  */
 public function index()
 {
     if (Auth::check('default', $this->request)) {
         return array('users' => Users::all());
     }
     return array('error' => 'Not authed');
 }
Ejemplo n.º 9
0
 public function add()
 {
     $logintest = false;
     //if (Auth::check('default', $this->request)) {
     if ($this->request->data && Auth::check('default', $this->request)) {
         //$success = true;
         return $this->redirect('Posts');
     }
     return compact('logintest');
     // Handle failed authentication attempts
 }
 public function add($ajax = null)
 {
     $login = Auth::check('member');
     $location = Locations::create($this->request->data);
     $actief = self::$actief;
     $breadcrumb = self::$breadcrumb;
     if ($this->request->data && $location->save()) {
         return compact('login', 'location', 'actief', 'breadcrumb');
     }
     return compact('login', 'location', 'product', 'actief', 'breadcrumb');
 }
 public function add()
 {
     $error = false;
     if ($this->request->data) {
         if (Auth::check('openid', $this->request)) {
             return $this->redirect('/');
         }
         $error = true;
     }
     return compact('error');
 }
Ejemplo n.º 12
0
 public function add()
 {
     if (!Auth::check('default')) {
         return $this->redirect('Sessions::add');
     }
     $success = false;
     if ($this->request->data) {
         $post = Posts::create($this->request->data);
         $success = $post->save();
     }
     return compact('success');
 }
Ejemplo n.º 13
0
 public function add()
 {
     if ($this->request->data) {
         $logged = Auth::check('default', $this->request);
         if ($logged) {
             $this->message('You are successfully login.');
             $this->redirect('Users::index');
         } else {
             $this->message('Your username/password is not valid, please try again!');
             $this->redirect('Sessions::add');
         }
     }
 }
Ejemplo n.º 14
0
 protected static function _isAuthedBy(array $names, array $params)
 {
     if ($names === array('*')) {
         return true;
     }
     $names = array_intersect(array_keys(Auth::config()), $names);
     foreach ($names as $name) {
         if (Auth::check($name, $params['request'], array('writeSession' => false))) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 15
0
 public function check($credentials, array $options = array())
 {
     foreach (Auth::config() as $name => $auth) {
         if ($auth['adapter'] === $this->_config['adapter'] or in_array($name, $this->_exclude)) {
             continue;
         }
         $result = Auth::check($name);
         if ($result) {
             return $result;
         }
     }
     return false;
 }
Ejemplo n.º 16
0
 /**
  * Check if the user is connected. If no $name is given, check for each authentication
  * registered configuration.
  *
  * @param  string 	$name        Name of config, if specified
  * @param  mixed 	$credentials Credentials
  * @param  array  	$options     Options
  * @return array                 Current user, if authenticated
  */
 public static function check($name = null, $credentials = null, array $options = array())
 {
     if (!isset($name)) {
         foreach (static::$_configurations as $name => $config) {
             $results = parent::check($name, $credentials, $options);
             if ($results) {
                 return $results;
             }
         }
         return false;
     }
     return parent::check($name, $credentials, $options);
 }
Ejemplo n.º 17
0
 /**
  * Import Auth data and fetch user group data
  */
 protected function _init()
 {
     parent::_init();
     if ($this->_user = Auth::check('default')) {
         $this->_guest = false;
     }
     if ($this->_acl) {
         $this->_prepareAcl();
         if (!$this->_checkAccess()) {
             throw new AccessDeniedException('You dont\'t have permissions to access here!');
         }
     }
 }
Ejemplo n.º 18
0
 public function delete()
 {
     // Check Author authentication Session
     if (!Auth::check('default')) {
         return $this->redirect('Authors::login');
     }
     $book = Books::find($this->request->id);
     if ($book && $book->delete()) {
         Session::write('message', 'Book deleted');
         $this->redirect(array('Authors::dashboard'));
     } else {
         Session::write('message', 'Book can not be deleted');
     }
 }
Ejemplo n.º 19
0
 /**
  * Check posted data against database and create session - log in user
  */
 public function create()
 {
     $this->_rejectLogged();
     $this->_viewAs('partial-component');
     $inactive = false;
     if ($this->request->data) {
         if (Auth::check('default', $this->request)) {
             return $this->redirect('li3_usermanager.Users::index');
         } elseif (Auth::check('inactive', $this->request)) {
             $inactive = true;
             Auth::clear('inactive');
         }
     }
     return compact('inactive');
 }
 public function add()
 {
     $noauth = false;
     $login = Auth::check('member');
     if (Auth::check('member', $this->request)) {
         return $this->redirect('/');
     }
     // Handle failed authentication attempts
     if ($this->request->data) {
         //Login failed, trigger the error message
         $noauth = true;
     }
     //Return noauth status
     $actief = self::$actief;
     $breadcrumb = self::$breadcrumb;
     return compact('noauth', 'login', 'actief', 'breadcrumb');
 }
Ejemplo n.º 21
0
 public function login()
 {
     //assume there's no problem with authentication
     $noauth = false;
     print_r(Auth::check('default', $this->request));
     //perform the authentication check and redirect on success
     if (Auth::check('default', $this->request)) {
         //Redirect on successful login
         return $this->redirect('/');
     }
     //if theres still post data, and we weren't redirected above, then login failed
     if ($this->request->data) {
         //Login failed, trigger the error message
         $noauth = true;
     }
     //Return noauth status
     return compact('noauth');
 }
Ejemplo n.º 22
0
 protected function _init()
 {
     parent::_init();
     # Check CSRF forgery signature
     if ($this->request->data and !RequestToken::check($this->request)) {
         throw new \Exception('Invalid request token.');
     }
     if (isset($this->request->data['security']['token'])) {
         unset($this->request->data['security']);
     }
     # Load active user
     $current_identity = Auth::check('any');
     if (is_object($current_identity)) {
         $u = $current_identity->getUser();
         $this->CURRENT_USER = $u;
     }
     $this->set(array('CURRENT_USER' => $this->CURRENT_USER));
 }
Ejemplo n.º 23
0
 public function login()
 {
     $result = Auth::check($this->request->adapter, $this->request);
     $redirectUrl = $this->request->env('HTTP_REFERER') ?: '/';
     if ($result) {
         # Convert array to identity object
         if ($this->request->adapter === 'password') {
             $result = Identities::find($result['_id']);
         }
         $session_data = array();
         $new_session = uniqid();
         if (isset($result['session']['id'])) {
             $session_data['id'] = (array) $result['session']['id']->data();
         } else {
             $session_data['id'] = array();
         }
         // Remember users for two weeks
         $session_data['expires'] = time() + \app\util\Config::get('session_length', 7) * 24 * 60 * 60;
         array_push($session_data['id'], $new_session);
         setcookie('session.id', $new_session, $session_data['expires'], '/', $_SERVER['HTTP_HOST']);
         $result->save(array('session' => $session_data));
         Auth::set('any', $result);
     } else {
         $addendum = '';
         // Adapter-specific error messages
         if ($this->request->adapter == 'phpbb') {
             if (Session::read('non_linked_phpbb_login')) {
                 Session::delete('non_linked_phpbb_login');
                 $addendum = 'You are logged into the forums, but there is no leagues account associated with with your forum account.';
             } else {
                 $addendum = 'Please ensure that you are logged into the <a href="http://www.afdc.com/forum/">forums</a>.';
             }
         } else {
             Logger::debug("Failed login for " . $this->request->data['email'] . " with password " . $this->request->data["password"]);
         }
         $error_message = 'Your login was unsuccessful. ';
         if (isset($addendum) and !empty($addendum)) {
             $error_message .= "<br />{$addendum}`<br />";
         }
         $error_message .= 'If you\'re having trouble, checkout the <a href="/help/login">login instructions</a>.';
         $this->flashMessage($error_message, array('alertType' => 'error'));
     }
     return $this->redirect($redirectUrl);
 }
Ejemplo n.º 24
0
 public function viewedit($id = null)
 {
     if (!Auth::check('default')) {
         return $this->redirect('Sessions::add');
     } else {
         $success = false;
         if (!is_null($id)) {
             $post = Posts::find('first', array('conditions' => array('_id' => $id)));
         }
         if ($this->request->data) {
             $success = $post->save($this->request->data);
             Posts::remove(array('title' => ''));
         }
     }
     // elseif($this->request->data) {
     //$success = Posts::update($this->request->data);
     //$success = $post->delete();
     //return compact('success');
     // }
     return compact('post', 'success');
 }
Ejemplo n.º 25
0
 public function isUserAuth()
 {
     return Auth::check('default') ? true : false;
 }
Ejemplo n.º 26
0
 /**
  * The default method here is changed. First off, the Router class now uses this view method if the URL is /page/{:args}
  * It changes the URL convention from pluralized controller, but since we're talking about static pages, I felt that was ok.
  * Especially since URLs are for humans first and foremost.
  * "/pages/view/home" still works if needed to be used in array fashion like the Html helper's link method.
  * This leaves us in need of a new method though that returns dynamic pages from a datasource. That's the "read" method below.
  *
 */
 public function view() {
     $path = func_get_args();
     
     // If route has the "admin" key set to true then render template from Minerva's views/pages/static folder
     if((isset($this->request->params['admin'])) && ($this->request->params['admin'] === true)) {
         // todo: make rule and check access class
         $user = Auth::check('minerva_user');
         // obviously this needs to be somewhere controllable
         if(!in_array($user['role'], array('administrator', 'content_editor'))) {
         $this->redirect('/users/login');
         }
     } 
     
     if (empty($path)) {
         $path = array('home');
     }
     
     // this doesn't get any documents, it just checks access. the false "find_type" key is preventing a db query
     $this->getDocument(array('action' => __METHOD__, 'request' => $this->request, 'find_type' => false));
     
     $this->render(array('template' => join('/', $path)));
 }	
Ejemplo n.º 27
0
        if ($name === 'lithium') {
            continue;
        }
        $file = "{$config['path']}/config/routes.php";
        file_exists($file) ? include $file : null;
    }
    return $chain->next($self, $params, $chain);
});
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
    $ctrl = $chain->next($self, $params, $chain);
    $request = isset($params['request']) ? $params['request'] : null;
    $action = $params['params']['action'];
    if ($request->args) {
        $arguments = array();
        foreach ($request->args as $value) {
            $param = explode(":", $value);
            $arguments[$param[0]] = isset($param[1]) ? $param[1] : null;
        }
        $request->args = $arguments;
    }
    if (Auth::check('default') || preg_match('|test.*|', $request->url)) {
        return $ctrl;
    }
    if (isset($ctrl->publicActions) && in_array($action, $ctrl->publicActions)) {
        return $ctrl;
    }
    return function () use($request) {
        Session::write('message', 'You need to login to access that page.');
        return new Response(compact('request') + array('location' => 'Sessions::add'));
    };
});
Ejemplo n.º 28
0
 public static function __init()
 {
     /*
      * Some special validation rules
      */
     Validator::add('uniqueEmail', function ($value) {
         $current_user = Auth::check('li3b_user');
         if (!empty($current_user)) {
             $user = User::find('first', array('fields' => array('_id'), 'conditions' => array('email' => $value, '_id' => array('$ne' => new MongoId($current_user['_id'])))));
         } else {
             $user = User::find('first', array('fields' => array('_id'), 'conditions' => array('email' => $value)));
         }
         if (!empty($user)) {
             return false;
         }
         return true;
     });
     Validator::add('notEmptyHash', function ($value) {
         if ($value == Password::hash('')) {
             return false;
         }
         return true;
     });
     Validator::add('moreThanFive', function ($value) {
         if (strlen($value) < 5) {
             return false;
         }
         return true;
     });
     Validator::add('notTooLarge', function ($value) {
         if ($value == 'TOO_LARGE.jpg') {
             return false;
         }
         return true;
     });
     Validator::add('invalidFileType', function ($value) {
         if ($value == 'INVALID_FILE_TYPE.jpg') {
             return false;
         }
         return true;
     });
     parent::__init();
     /*
      * If told to ues a specific connection, do so.
      * Otherwise, use the default li3b_users connection.
      * Note: This model requires MongoDB.
      * Also note: This must be called AFTER parent::__init()
      *
      * This is useful if the main application also uses MongoDB
      * and wishes everything to use the same database...Be it
      * local or on something like MongoLab or wherever.
      *
      * In fact, when gluing together libraries, one may choose
      * all libraries that use the same database and kinda go
      * with each other. That way it'll end up looking like a single
      * cohesive application from the database's point of view.
      * Of course the it's difficult to avoid conflicts in the MongoDB
      * collection names. In this case, this model is prefixing the
      * library name to the collection in order to ensure there are
      * no conflicts.
      */
     $libConfig = Libraries::get('li3b_users');
     $connection = isset($libConfig['useConnection']) ? $libConfig['useConnection'] : 'li3b_users';
     static::meta('connection', $connection);
 }
Ejemplo n.º 29
0
 /**
  * Enables/disables the user.
  * This method should be called via AJAX.
  *
  * @param string $id The user's MongoId
  * @param mixed $active What to set the active field to. 1 = true and 0 = false, 'false' = false too
  * @return boolean Success
  */
 public function admin_set_status($id = null, $active = true)
 {
     $this->_render['layout'] = 'admin';
     // Do our best here
     if ($active == 'false') {
         $active = false;
     } else {
         $active = (bool) $active;
     }
     // Only allow this method to be called via JSON
     if (!$this->request->is('json')) {
         return array('success' => false);
     }
     $requested_user = User::find('first', array('conditions' => array('_id' => $id)));
     $current_user = Auth::check('li3b_user');
     // Don't allow a user to make themself active or inactive.
     if ((string) $request_user->_id == $current_user['_id']) {
         return array('success' => false);
     }
     if (User::update(array('$set' => array('active' => $active)), array('_id' => $requested_user->_id), array('atomic' => false))) {
         return array('success' => true);
     }
     // Otherwise, return false. Who knows why, but don't do anything.
     return array('success' => false);
 }
Ejemplo n.º 30
0
 public function deleteAction()
 {
     $url = "";
     $success = false;
     $errors = array();
     if (!Auth::check('default')) {
         $errors['login'] = '******';
     } else {
         if (!$this->request->is('post')) {
             $errors['call'] = 'This action can only be called with post';
         } else {
             if (!($success = self::getPost($this->request->data['id'], $post))) {
                 $errors['post'] = 'This post doesn\'t exist';
             } else {
                 if ($success = $post->delete()) {
                     $url = "http://" . $_SERVER['HTTP_HOST'];
                 } else {
                     $errors = $post->errors();
                 }
             }
         }
     }
     return compact('success', 'errors', 'url');
 }