/** * Authenticate against the ldap. A closure may be provided * for a callback upon authentication as a shortcut for subscribing * to an event. * * @param \Cartalyst\Sentinel\Users\UserInterface|array $credentials * @param bool $remember * @return \Cartalyst\Sentinel\Users\UserInterface */ public function authenticate($credentials, $remember = false) { $config = Config::get('vionox/sentinel-ldap::ldap'); if ($conn = $this->connect($config['host'], $config['port'])) { $user = $this->sentinel->findByCredentials($credentials); ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3); $valid = $user !== null ? ldap_bind($conn, $user->email, $credentials['password']) : false; if ($valid) { $this->login($user, $remember); $this->disconnect($conn); return $user; } } $this->disconnect($conn); return false; }
/** * Retrieves a link and associates a user (will lazily * create one) for the given slug, provider and token. * * @param string $slug * @param mixed $provider * @param mixed $token * @return \Cartalyst\Sentinel\Addons\Social\Models\LinkInterface */ protected function linkLoggedOut($slug, $provider, $token) { $uid = $provider->getUserUid($token); $link = $this->retrieveLink($slug, $uid, $token); if (!($user = $link->getUser())) { $login = $provider->getUserEmail($token) ?: $uid . '@' . $slug; $user = $this->sentinel->findByCredentials(compact('login')); if ($user) { $link->setUser($user); $this->fireEvent('sentinel.social.existing', [$link, $provider, $token, $slug]); } else { $user = $this->sentinel->getUserRepository()->createModel(); // Create a dummy password for the user $password = [$slug, $login, time(), mt_rand()]; shuffle($password); $password = implode('', $password); $credentials = ['login' => $login, 'password' => $password]; // Some providers give a first / last name, some don't. // If we only have one name, we'll just put it in the // "first_name" attribute. if (is_array($name = $provider->getUserScreenName($token))) { $credentials['first_name'] = $name[0]; $credentials['last_name'] = $name[1]; } elseif (is_string($name)) { $credentials['first_name'] = $name; } $this->fireEvent('sentinel.social.registering', [$link, $provider, $token, $slug]); $user = $this->sentinel->registerAndActivate($credentials); $link->setUser($user); $this->fireEvent('sentinel.social.registered', [$link, $provider, $token, $slug]); } } else { $this->fireEvent('sentinel.social.existing', [$link, $provider, $token, $slug]); } $this->fireEvent('sentinel.social.linking', [$link, $provider, $token, $slug]); return $link; }
/** * {@inheritDoc} */ public function findByCredentials(array $data) { return $this->sentinel->findByCredentials($data); }