Exemplo n.º 1
0
 /**
  * Block a user and remove or reassign their content.
  */
 public function cancel()
 {
     if (drush_get_option('delete-content')) {
         user_cancel(array(), $this->id(), 'user_cancel_delete');
     } else {
         user_cancel(array(), $this->id(), 'user_cancel_reassign');
     }
     // I got the following technique here: http://drupal.org/node/638712
     $batch =& batch_get();
     $batch['progressive'] = FALSE;
     batch_process();
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function userDelete(\stdClass $user)
 {
     user_cancel(array(), $user->uid, 'user_cancel_delete');
 }
 /**
  * Confirms cancelling a user account via an email link.
  *
  * @param \Drupal\user\UserInterface $user
  *   The user account.
  * @param int $timestamp
  *   The timestamp.
  * @param string $hashed_pass
  *   The hashed password.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect response.
  */
 public function confirmCancel(UserInterface $user, $timestamp = 0, $hashed_pass = '')
 {
     // Time out in seconds until cancel URL expires; 24 hours = 86400 seconds.
     $timeout = 86400;
     $current = REQUEST_TIME;
     // Basic validation of arguments.
     $account_data = $this->userData->get('user', $user->id());
     if (isset($account_data['cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
         // Validate expiration and hashed password/login.
         if ($timestamp <= $current && $current - $timestamp < $timeout && $user->id() && $timestamp >= $user->getLastLoginTime() && Crypt::hashEquals($hashed_pass, user_pass_rehash($user, $timestamp))) {
             $edit = array('user_cancel_notify' => isset($account_data['cancel_notify']) ? $account_data['cancel_notify'] : $this->config('user.settings')->get('notify.status_canceled'));
             user_cancel($edit, $user->id(), $account_data['cancel_method']);
             // Since user_cancel() is not invoked via Form API, batch processing
             // needs to be invoked manually and should redirect to the front page
             // after completion.
             return batch_process('');
         } else {
             drupal_set_message(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'error');
             return $this->redirect('entity.user.cancel_form', ['user' => $user->id()], ['absolute' => TRUE]);
         }
     }
     throw new AccessDeniedHttpException();
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $current_user_id = $this->currentUser()->id();
     // Clear out the accounts from the temp store.
     $this->tempStoreFactory->get('user_user_operations_cancel')->delete($current_user_id);
     if ($form_state['values']['confirm']) {
         foreach ($form_state['values']['accounts'] as $uid => $value) {
             // Prevent programmatic form submissions from cancelling user 1.
             if ($uid <= 1) {
                 continue;
             }
             // Prevent user administrators from deleting themselves without confirmation.
             if ($uid == $current_user_id) {
                 $admin_form_mock = array();
                 $admin_form_state = $form_state;
                 unset($admin_form_state['values']['user_cancel_confirm']);
                 // The $user global is not a complete user entity, so load the full
                 // entity.
                 $account = $this->userStorage->load($uid);
                 $admin_form = $this->entityManager->getFormObject('user', 'cancel');
                 $admin_form->setEntity($account);
                 // Calling this directly required to init form object with $account.
                 $admin_form->buildForm($admin_form_mock, $admin_form_state);
                 $admin_form->submit($admin_form_mock, $admin_form_state);
             } else {
                 user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']);
             }
         }
     }
     $form_state['redirect_route']['route_name'] = 'user.admin_account';
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function submit(array $form, FormStateInterface $form_state)
 {
     // Cancel account immediately, if the current user has administrative
     // privileges, no confirmation mail shall be sent, and the user does not
     // attempt to cancel the own account.
     if ($this->currentUser()->hasPermission('administer users') && empty($form_state['values']['user_cancel_confirm']) && $this->entity->id() != $this->currentUser()->id()) {
         user_cancel($form_state['values'], $this->entity->id(), $form_state['values']['user_cancel_method']);
         $form_state->setRedirect('user.admin_account');
     } else {
         // Store cancelling method and whether to notify the user in
         // $this->entity for user_cancel_confirm().
         $this->entity->user_cancel_method = $form_state['values']['user_cancel_method'];
         $this->entity->user_cancel_notify = $form_state['values']['user_cancel_notify'];
         $this->entity->save();
         _user_mail_notify('cancel_confirm', $this->entity);
         drupal_set_message($this->t('A confirmation request to cancel your account has been sent to your email address.'));
         $this->logger('user')->notice('Sent account cancellation request to %name %email.', array('%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>'));
         $form_state->setRedirect('user.view', array('user' => $this->entity->id()));
     }
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Cancel account immediately, if the current user has administrative
     // privileges, no confirmation mail shall be sent, and the user does not
     // attempt to cancel the own account.
     if (!$form_state->isValueEmpty('access') && $form_state->isValueEmpty('user_cancel_confirm') && $this->entity->id() != $this->currentUser()->id()) {
         user_cancel($form_state->getValues(), $this->entity->id(), $form_state->getValue('user_cancel_method'));
         $form_state->setRedirectUrl($this->entity->urlInfo('collection'));
     } else {
         // Store cancelling method and whether to notify the user in
         // $this->entity for
         // \Drupal\user\Controller\UserController::confirmCancel().
         $this->entity->user_cancel_method = $form_state->getValue('user_cancel_method');
         $this->entity->user_cancel_notify = $form_state->getValue('user_cancel_notify');
         $this->entity->save();
         _user_mail_notify('cancel_confirm', $this->entity);
         drupal_set_message($this->t('A confirmation request to cancel your account has been sent to your email address.'));
         $this->logger('user')->notice('Sent account cancellation request to %name %email.', array('%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>'));
         $form_state->setRedirect('entity.user.canonical', array('user' => $this->entity->id()));
     }
 }