/** * Runs the seeding operation. */ public function run() { $users = $this->ldap->users(); foreach ($users as $user) { if ($this->syncFiltersEnabled()) { if ($this->userAllowed($user)) { $this->createUser($user); } continue; } } }
/** * Creates or updates a user using LDAP and Sentry. * * @param array $credentials * * @return mixed */ public function createOrUpdateLdapUser(array $credentials) { $loginAttribute = $this->config->setPrefix('cartalyst.sentry')->get('users.login_attribute'); $username = $credentials[$loginAttribute]; $password = $credentials['password']; // If a user is found, update their password to match active-directory $user = $this->model()->where('username', $username)->first(); if ($user) { $this->sentry->updatePasswordById($user->id, $password); } else { // If a user is not found, create their web account $ldapUser = $this->ldap->user($username); $fullName = explode(',', $ldapUser->name); $lastName = array_key_exists(0, $fullName) ? $fullName[0] : null; $firstName = array_key_exists(1, $fullName) ? $fullName[1] : null; $data = ['email' => $ldapUser->email, 'password' => $password, 'username' => $username, 'last_name' => (string) $lastName, 'first_name' => (string) $firstName, 'activated' => 1]; $user = $this->sentry->createUser($data, ['all_users', 'customers', 'workers']); } return $user; }