function force_password_change_update_user in Force Password Change 2.0.x
Same name and namespace in other branches
- 8 force_password_change.module \force_password_change_update_user()
1 string reference to 'force_password_change_update_user'
- force_password_change_form_alter in ./
force_password_change.module - Implements hook_form_alter().
File
- ./
force_password_change.module, line 258
Code
function force_password_change_update_user(array &$form, FormStateInterface $form_state) {
$uid = $form_state
->getValue('uid');
$current_user = \Drupal::currentUser();
$user_data_service = \Drupal::service('user.data');
$db = \Drupal::database();
$current_pass = $form_state
->getValue('current_pass');
if ($current_pass && $current_pass != $form_state
->getValue('pass')) {
// If a user's password has changed their password, the time of their
// password change is saved to the database.
\Drupal::service('force_password_change.service')
->setChangedTimeForUser($uid);
// This next conditional is entered when a user is changing
// their own password.
if ($current_user
->id() == $uid && $user_data_service
->get('force_password_change', $uid, 'pending_force')) {
$force_password_change_service = \Drupal::service('force_password_change.service');
// Remove the flag from the users account.
$force_password_change_service
->removePendingForce($uid);
// Remove first time force.
$force_password_change_service
->removeFirstTimeLogin($uid);
}
}
// An admin with the proper permissions is able to flag a user to change
// their password on the user's account page. This next section
// sets that flag.
if ($form_state
->getValue('force_password_change')) {
Drupal::service('force_password_change.service')
->forceUsersPasswordChange([
$uid,
]);
}
}