Пример #1
0
 /**
  * Create or Update a User for authentication for use with ldap.
  *
  * @param array $credentials
  *
  * @return \Cartalyst\Sentry\Users\Eloquent\User
  */
 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 in the database, 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 ? $ldapUser->email : $username, 'username' => $username, 'password' => $password, 'last_name' => (string) $lastName, 'first_name' => (string) $firstName, 'activated' => 1];
         // Default all group
         $roles = ['all'];
         if (in_array($ldapUser->group, config('maintenance.groups.ldap.administrators'))) {
             $roles[] = 'administrators';
         } else {
             if (in_array($ldapUser->group, config('maintenance.groups.ldap.workers'))) {
                 $roles[] = 'workers';
             } else {
                 $roles[] = 'client';
             }
         }
         $user = $this->sentry->createUser($data, $roles);
     }
     return $user;
 }
Пример #2
0
 /**
  * Updates the specified users password.
  *
  * @param $id
  *
  * @return \Illuminate\Http\JsonResponse|mixed
  */
 public function update($id)
 {
     if ($this->passwordValidator->passes()) {
         if ($this->sentry->updatePasswordById($id, $this->input('password'))) {
             $this->message = 'Successfully updated password';
             $this->messageType = 'success';
             $this->redirect = routeBack('maintenance.admin.users.show', [$id]);
         } else {
             $this->message = 'There was an issue resseting this users password. Please try again';
             $this->messageType = 'danger';
             $this->redirect = routeBack('maintenance.admin.users.show', [$id]);
         }
     } else {
         $this->errors = $this->passwordValidator->getErrors();
         $this->redirect = route('maintenance.admin.users.show', [$id]);
     }
     return $this->response();
 }
Пример #3
0
 /**
  * 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;
 }