Questions tagged [users]

Use it for question about the user entity. Don't use it for a generic question about, for example, what users can do on a site.

Filter by
Sorted by
Tagged with
2 votes
1 answer
16 views

Anonymous User name is changed to a strange name in watchdog logs

Our D9 site's dblog is showing the anonymous user name as a very stange name instead of anonymous. All anonymous users are shown as "closhewupheheh…" even though the anonymous user name is ...
user avatar
1 vote
1 answer
22 views

Send "admin (user awaiting approval)" email programmatically to admin

I want to send the "admin (user awaiting approval)" email after creating an account in the user_insert hook I don't know what function is used. I did find _user_mail_notify which works well ...
user avatar
0 votes
0 answers
27 views

Redirect after using the one time login after password reset

How can i programmatically change the button link destination after clicking the one time login button in drupal 9: I've tried this solution but got stuck because i didn't know how to compare a link ...
user avatar
  • 11
0 votes
1 answer
15 views

Comparing 'old' values in hook_user_update

I've got a function which is running on hook_ENTITY_TYPE_update for the user account, but I want to be able to compare against previous values that may have been on the user account, eg see if the ...
user avatar
1 vote
0 answers
22 views

Why am I getting different results for entity::save() between REST and web?

I'm refactoring my user entities to use entity bundle classes. Before, I saved the value of a time offset in a field using hook_user_presave(): // Initialize in user timezone. $user_timezone = ...
user avatar
0 votes
0 answers
14 views

Automatically Insert value in field while creating content depending on user

I am stuck on something. I have different users each representing a specific Faculty. Using the groups module I let each one edit and delete its own content but while creating a content of custom type ...
user avatar
0 votes
0 answers
26 views

Login fails: returns to anonymous user home page with no message

I am testing upgrade to Drupal 9. I upgraded core and logged in and fixed a few issues with module deprecated code and then was presented with a Twig issue where replace syntax had changed. I changed ...
user avatar
1 vote
0 answers
21 views

Unable to have user role permissions correctly applied

I have a multi-language site managed by different admins. We want to create a news editor role and apply it so that a) the person can only modify content applicable to their language and b) can only ...
user avatar
  • 163
1 vote
1 answer
134 views

Wrong user with currentUser() on prod

I'm getting the name of my user that I load from the profile. It's works fine on my local, but on my prod, the firstname displayed is showing the name from the previous user. How do I prevent that ? ...
user avatar
  • 51
0 votes
1 answer
34 views

How can I encrypt user-submitted content per user for a content type?

Let's say I have a website where people keep a personal diary (diary content type). I have configured permissions so that each user can only read, write, and view his/her own diary. Users can create ...
user avatar
1 vote
1 answer
58 views

Permission granted to a programatically created role is not working!

In the submission handler for a custom module form, I am using this code. $role = Role::create(['id' => 'member', 'label' => t('Member')]); $role->grantPermission('Renew membership'); $role-&...
2 votes
1 answer
87 views

How to remove user role temporarily?

I need to disable the "administrator" role from user accounts who log into my website from outside my network. For security, I only want users who have this role to be able to use it when ...
user avatar
  • 253
0 votes
1 answer
151 views

Cannot add new user due to "Integrity constraint violation: Duplicate entry" error

Starting December 14, 2021, my site began creating users with low user IDs, even though the highest-used user ID was 9317. I thought something had been changed in a core update to reuse IDs that had ...
user avatar
0 votes
0 answers
12 views

How to filter out content by compare field value in user profile?

Is there any way to filter out content by compare values of the same field in nodes and user profile? I have a fivestar rating field "field_diffculty" in several content types and user ...
user avatar
  • 1
2 votes
1 answer
257 views

How would I disallow special characters in usernames?

By default, Drupal 9 allows usernames to have spaces, periods(.), hyphens(-), apostrophes('), underscores(_) and @ symbols. How would I disallow spaces, periods, apostrophes and @ symbols?
user avatar
0 votes
1 answer
85 views

"Access denied" Error on clicking user/reset link [closed]

I am a Drupal newbie, so pardon any errors in my question. In my D9 site I am using password policy module to set password policy rules. When I hit "Reset password" I get a one-time link to ...
user avatar
0 votes
1 answer
39 views

store user entered mail id to separate table

Have a requirement to develop drupal 9 custom module to get the mail id from the user registration form and store it separate table. I tried the hook_user_presave function to get the mail id but was ...
user avatar
  • 123
0 votes
0 answers
50 views

Restrict permissions for user to only allow certain user managing actions

I would like to restrict permissions for a user to only allow certain user managing actions like for example blocking other users and / or deleting them. This is meant for a user role like a moderator ...
user avatar
0 votes
2 answers
64 views

Load node entities by owner

I want to load entities by their owner. This is what I have so far: \Drupal::logger('migrate_users')->notice("Hello start"); $userStorage = \Drupal::entityTypeManager()->getStorage('...
user avatar
1 vote
0 answers
67 views

Referencing disabled users during migration

I have migration that creates files. For file owners I'm trying to find existing user by email and if don't find I create one on fly. Problem is that those users I'm creating must be disabled (I don't ...
user avatar
  • 375
0 votes
1 answer
59 views

How do you remove a user role via a hook update?

I would like to remove a user role via a hook update in Drupal 9. I believe I would need to do something like the below but unclear what other code might be needed. $user->removeRole('administrator'...
user avatar
  • 23
1 vote
1 answer
228 views

How can I force user logout from a JavaScript library in a custom module?

I've written a custom module for Drupal 8 to monitor user device location frequently. If a user goes out of an allowed zone boundary, I need to force logging the user out of the website. I created ...
user avatar
2 votes
2 answers
118 views

add field to user in hook_update_n

The latest release of our existing module needs to define MANY new fields that are attached to the drupal user. For each field, in {module}/config/optional there is a field config and a field storage ...
user avatar
0 votes
0 answers
17 views

How to distinguish new users who haven't validated their email?

How can a site manager filter the list of users so they only see new users who have validated their email addresses? Registration to the site requires approval, and the site manager does not want to ...
user avatar
0 votes
1 answer
33 views

Can users with a custom role approve the user registration?

I have created a site that requires approval of new user registrations. I added the Manager role for the site owner. I'd like users with that role to approve the account registrations. Is there any ...
user avatar
  • 3
0 votes
0 answers
224 views

How can I get specific fields from user object in the REST API?

I have a question about retrieving fields from the user object using REST in Drupal 8. When i am logged in into Drupal i can use the following GET call too retrieve the user object: http://localhost:...
user avatar
1 vote
0 answers
44 views

Restrict users from creating administrators?

I want to give some users the ability to add and edit other users, but I don't want them to be able to add administrators (or for them to be able to give themselves or other users the "...
user avatar
  • 943
2 votes
1 answer
698 views

How can I programmatically delete a user without deleting their content?

I want to delete a user with this code: $account = User::load(19920); $account->delete(); How can I do that without also deleting the user's content? I've been reviewing _user_cancel() hooks, but ...
user avatar
  • 263
2 votes
1 answer
198 views

How can I bulk delete users? [duplicate]

My site got hacked and I had an online service clean it out. However, it now has over 150,000 user accounts, the bulk of which have no role assignment. How do I delete these accounts and their content?...
user avatar
0 votes
2 answers
105 views

Map profile_id based on previously mapped uid when migrating user profiles from CSV file

I'm trying to migrate users and user profiles to site, where both entities might be already present. In this case I would like to overwrite specified fields and leave others in the original state. I'm ...
user avatar
1 vote
1 answer
108 views

How to determine which password hash is used?

We have migrated website from a vanilla coded PHP to Drupal, and I have also migrated all the users. The old website has been using the password_hash() function to encrypt the password. The website ...
user avatar
-1 votes
1 answer
237 views

How do I get the (integer) uid from the User entity?

On the odd chance there was a "getUid()" method for the user entity, I tried it, but got: Call to undefined method Drupal\user\Entity\User::getUid() Is there a way to get the uid from the ...
user avatar
  • 14.8k
0 votes
1 answer
843 views

How to get current user jwt token?

In a custom module, I need to get the jwt token (access_token) related to the current user. Following this issue I've tried to get it, but without success, because get_jwt_key() and jwt_token_params() ...
user avatar
  • 582
1 vote
1 answer
39 views

How to display 'Welcome [first_name] [last_name]' in a custom views block? D8

I would like to create a custom block / view to display a welcome message to the currently logged in user in Drupal 8. I followed this answer but it isn't working for me. Maybe things changed in D8. ...
user avatar
1 vote
0 answers
18 views

What is the specific security implication with the permission "Select method for cancelling account"

Below the permission "Select method for cancelling account" there is the following hint: Warning: Give to trusted roles only; this permission has security implications. I understand that ...
user avatar
0 votes
1 answer
47 views

How do I let users cancel their account with JWT / JSON:API?

I am making an Ionic app with Drupal as the backend. Users log in via JWT. I'm using JSON:API to send data to Ionic. Now I want to allow users to cancel their accounts in the app (by JSON:API) ...
user avatar
0 votes
0 answers
68 views

How can I sync just roles/permission config across multi-site instances?

On a Drupal 8 multi site, we need to have unified ROLES/permission config in all sites. Then we'll assign these roles to users via interface or Drush. How could I export / import? Or even better sync ...
user avatar
  • 137
0 votes
1 answer
110 views

Does the login-link users receive upon registration actually expire?

I'm trying to expand the duration for the expiration of the one-time-login for the initial registration process: the user clicks on "create new account" after filling name and email and ...
user avatar
  • 1,360
1 vote
1 answer
104 views

how to set a node to anonymous author?

Change node author works : $node = \Drupal\node\Entity\Node::load($nid); $node->set('uid','45'); $node->save(); But i don't know how to set it to anonymous user ? or unset it ? $node = \Drupal\...
user avatar
  • 2,775
0 votes
1 answer
120 views

How to get the contents created by a User?

How to get all contents from which the current user is author? $currentUser = \Drupal::currentUser(); $user = User::load($currentUser->id()); //get the contents from which $user is author?
user avatar
  • 2,775
0 votes
0 answers
760 views

How can I programmatically create an user account and trigger an activation email?

I developed custom module to create users. And I setup config account setting "Require email verification" to "Require a verification email, but let users set their password directly on ...
user avatar
1 vote
0 answers
139 views

Can I cast a generic type reference (EntityInterface) of an object, to a more specific, AccountInterface, if I know the object is a user?

Here is my code // implements hook_node_presave function mymodule_entity_presave(Drupal\Core\Entity\EntityInterface $entity) { if ( $entity->getEntityTypeId() === 'user' ) { so now I know the $...
user avatar
0 votes
0 answers
117 views

Error message for duplicate email for user registration

On my site, users sign up by submitting their email and name to a user registration form. They will get an email with a link that will allow them to complete the rest of the sign up process, like ...
user avatar
0 votes
1 answer
58 views

Headers already sent

I found this error repeated several times for two of the pages on my website. Warning: Cannot modify header information - headers already sent by (output started at /home/customer/www/mydomain....
user avatar
  • 41
2 votes
2 answers
508 views

How do I get group to which the node belongs and redirect anonymous users to the login page if they land on it?

I'm using the Drupal Group module and I've added content to a Drupal group I've created. I've also added users to this Group. Works well: Drupal users have to login to see this content in that group. ...
user avatar
2 votes
2 answers
642 views

PostCreate/Hook on User Registration

I want to hook into user registration but there doesn't seem to be any hook for it anymore. This is what I see from Drupal 8.8: hook_user_cancel hook_user_cancel_methods_alter ...
user avatar
  • 236
1 vote
1 answer
134 views

Migrating user accounts to Okta

I'm trying to migrate users exported from Drupal into Okta using the /api/v1/users API (specifically [creating users with import hash][1]), and am stuck, and desperate for help as I'm late on a ...
user avatar
0 votes
1 answer
30 views

How can I conditionally create a user account based on field in registration?

Here is the scenario: Prospective employees (PE) who need to access this Drupal site for onboarding resources will be sent an access code from someone in HR (to prevent random people from creating ...
user avatar
  • 451
4 votes
4 answers
871 views

How to implement decoupled user registration with React / jsonapi?

I have built a React app that uses JSON:API to pull in data, but now I want to implement user registration. JSON:API doesn't do user registration because it isn't a CRUD operation. However, the links ...
user avatar
0 votes
0 answers
58 views

How can I migrate users?

I need to rebuild my website, actually built with Drupal 7, and install Drupal 8. I have some modules that don't exist in Drupal 8. So, I decided to install Drupal 8 and rebuild the website from ...
user avatar

1
2 3 4 5
131