function key_auth_user_insert in Key auth 8
Implements hook_ENTITY_TYPE_insert().
File
- ./
key_auth.module, line 35 - Module that allows authentication via key.
Code
function key_auth_user_insert(EntityInterface $entity) {
// Check if we should auto-generate a key.
if (\Drupal::config('key_auth.settings')
->get('auto_generate_keys')) {
// Load the key auth service.
$key_auth = \Drupal::service('key_auth');
// Check if this user has access to use key auth.
if ($key_auth
->access($entity)) {
// Generate a key.
$entity
->set('api_key', $key_auth
->generateKey())
->save();
}
}
}