Questions tagged [usermodel]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
5 votes
2 answers
3k views

User events in Craft 3

How do I capture user events in Craft 3? I looked at the documentation but couldn't figure it out. I need to capture after user registration events and after user save events. Here is what I tried, ...
  • 485
4 votes
1 answer
445 views

How do I set the user password when using saveUser service method?

I am saving users from an external source and able to create them in the Craft db as users. However, each user's password is set to null despite setting it on the user model prior to saving it. Is ...
  • 183
3 votes
1 answer
828 views

Searching for users from a plugin

I know how to find user by username and email. The problem comes when I need to query users based on a custom field. Here is my scenario. I have about 2,000 users (part of a user group 'Affiliates') ...
3 votes
1 answer
140 views

Remove username from photoUrl path

I just realized that Craft puts the username into the path of the photoUrl. Since I use email addresses as usernames, I don’t think it’s a good idea to expose the email addresses of all users on the ...
3 votes
1 answer
131 views

How do I access the properties of an object which triggered an event?

I'm trying my first plug-in; it's to automatically create an entry in a section when a user belonging to a specific user group is activated. However I'm not that hot at PHP and I can't figure out how ...
  • 3,084
3 votes
0 answers
363 views

How can I create a dropdown field programmatically with a plugin?

I'm trying to create a Dropdown field and add it to the User field layout. I've successfully created an empty dropdown field (no options) and added it to the User field layout. Here is my current ...
  • 76
2 votes
3 answers
1k views

CometChat integration

I need to implement Comet Chat, a facebook-chat-like third-party script, into my Craft project. Comet Chat can connect to most CMS and PHP framework but there is no Craft integration yet, so I tried ...
  • 147
2 votes
1 answer
819 views

How to add addition attribute and fields in public registration form in Craft CMS

User Registration Form I want to setup a public registration form in Craft CMS. Currently this form support only fields username, email, password, but I want to add at least 10 other fields. Also I ...
  • 21
2 votes
1 answer
291 views

Sending email by key to non-user

In a custom plugin, I would like to use Craft's ability to register email message keys in order to keep emails consistent, and I would like to be able to send these emails to users as well as non-...
  • 391
2 votes
1 answer
546 views

RelatedTo with users

The RelatedTo function keeps puzzeling me. I got it working with categories, but now I want to do something in reverse with users. But I don't fully understand the RelatedTo function. I have a ...
  • 1,456
2 votes
1 answer
269 views

Saving/assigning User Group via a plugin

Anyone had experience of assigning a user group when saving or registering a user via a plugin? Tried various combinations of $user->group = 1, $user->group = [1], $user->setGroups([$group]) ...
  • 1,731
2 votes
1 answer
141 views

Sharing files with logged-in users

Our client is a builder and they need a way for their contractors to login and upload/download documents about each build (plans, building consents, information etc). They (the builder) also need a ...
  • 23
2 votes
1 answer
138 views

`onBeforeSaveUser` - Access existing user data

I'm trying to run a quick check to see if any of my user's data has changed before saving them. However, I'm running into a situation where I can only access the new data. I can't tell if this is a ...
  • 23.6k
2 votes
1 answer
440 views

How to activate a user in a plugin?

I'm trying to activate a user via a plugin so that when the user is returned to the login page they are re-directed to their profile page. I'm making use of the social logins beta plugin by dukt (I ...
  • 2,023
2 votes
1 answer
115 views

Conditional for user registration fields

What’s the best way to validate a user registration form to make sure that at least one of two fields is not empty? I’ve tried a very simple controller but can’t get this to work past the point of ...
  • 1,128
2 votes
1 answer
191 views

Processing Business Logic on user.saveUser

I have the following code in my plugin. public function init() { parent::init(); craft()->on('users.saveUser', function(Event $event) { // only fire if new user if ($event->...
2 votes
1 answer
673 views

Correct way of showing errors when editing profile via front-end form?

I've been looking at the following resources: https://craftcms.com/docs/templating/user-profile-form Allow user to change or delete their photo for their profile from the front end Front end edit: ...
2 votes
1 answer
119 views

onSaveUser event - cannot redirect or access errors

I've written a plugin which intercepts the user.onSaveUser event. However if the save fails the user is still redirected to the page specified in the 'redirect' parameter/field of the form. How do I ...
  • 1,731
1 vote
2 answers
792 views

Saving Custom Field Values to User Profile

I have a custom user field 'myuserfield' How do I save a value to this field via a plugin in Craft3? Here is my current attempt. $myvar = '12345'; Craft::$app->getUser()->getIdentity()...
1 vote
2 answers
1k views

Getting the UID of a user model

I want to use the UID to get a user from a url and don't want to use the ID as it is guessable. I know I can do craft()->users->getUserByUid($uid); but after getting the uid, the uid is not on ...
  • 6,702
1 vote
1 answer
222 views

Batch saving a custom field to multiple users via controller

I have to build a custom plugin for an internal user management system/data export that needs to be able to get triggered from the CP. I basically have to sort a big amount of users (1500+) in a ...
  • 1,064
1 vote
1 answer
120 views

Add Checked Attribute to Custom User Fields on Frontend User Form

I have a multi-select for users to sign up for newsletters. When they edit their profile they need to be able to see which newsletters they are already signed up for. I have the code to output the ...
1 vote
1 answer
82 views

Fetching "Pending" Users Related To Entry Within Plugin

This works (but only obtains the active users): // get entry $entry = craft()->entries->getEntryById($entryId); // get existing users in field $entry->customUserField->ids(); So in ...
  • 346
1 vote
1 answer
758 views

Update User Profile with Plugin

I'm trying to create a plugin to create/update users' profile data. I figured out how to create a user but updating... not so much. Here is the code I'm using: $user = craft()->userSession->...
  • 491
1 vote
1 answer
294 views

I cannot get the email address to properly update from my user account management form

I figure I must need to pass the current user's password along with the updated email address upon form submit. However, I cannot get the email address change to take. Any help is greatly appreciated. ...
1 vote
1 answer
149 views

Adding entry type using setContentFromPost

I'm creating a new user using $user->setContentFromPost(). It all works fine except I can't attach an entry to an Entries field. $user = new UserModel(); $user->username = $email; $user-...
  • 555
1 vote
1 answer
464 views

Variable for User Field

How do I go about using a dynamic value to access a user field value? I have created a form builder for users and dynamically populate the user field based on the question's associated field. <...
1 vote
1 answer
329 views

currentUser global is null. I can't figure out why

Does anyone know why currentUser would return null? I'm logged in as an admin.. actually the only user. I've cleared cache, logged out and back in, etc. I can't seem to get it to work. I'm trying to ...
  • 306
1 vote
1 answer
166 views

Require password from current user on front-end form?

I have a controller that handles some font-end form validation. From that controller I’d like to require the current (already logged in) user’s password to update any field. How can I do that?
  • 1,128
1 vote
1 answer
385 views

Set User's entry field from PHP in Craft 3

From this question, I tried: $user->setAttributes(['products' => $userProductsIds]); return Craft::$app->getElements()->saveElement($user); Where $user is an instance of craft\elements\...
1 vote
1 answer
440 views

How to pragmatically set registered user status to pending and then manually send activation email

I have 2 front end registration forms. One for normal users and one for admins. In each form I have a hidden input with a group value like so: <input type="hidden" name="group" value="ypo"> In ...
  • 555
1 vote
1 answer
80 views

Craft redirects to domain.tld/domain.tld/ on logout

I have a logout button on my site that points to the logoutUrl. While the logout works and ends the user session, the user is brought to a page with the URL similar to domain.tld/domain.tld/ where ...
  • 163
1 vote
1 answer
167 views

Save Entry Data as CSV and Email it to the Author / Logged in User

I am trying to email some Entry data that they have created in CSV Format to the author/logged in user. I have a controller setup with a frontend form posting an action to the controller: public ...
1 vote
1 answer
99 views

entry.getAuthor().getGroups() always return empty array

I'm trying to output users groups for every entries in a for loop, but it returns an empty array: {%for entry in craft.entries.section('news') %} ... {{ dump(entry.getAuthor().getGroups()) }} ...
  • 133
1 vote
0 answers
288 views

Save and log in a user from event callback

I'm trying to build a plugin wherein after a user is created via the normal means via a front end template, the user is immediately logged in. My module is watching for the after save event on ...
  • 11
1 vote
1 answer
43 views

How do I set the Post field after manipulation

I'm trying to write a simple plugin that will intercept registration form's data, manipulate it and move it forward. What I'm struggling with is how to set the Post content of a field after the ...
  • 555
1 vote
0 answers
55 views

Filter conditions on related UserModel in custom Record

My plugin has a custom ResponseRecord with relations to a UserRecord and ElementRecord as follows: public function defineRelations() { return array( 'user' => array(static::BELONGS_TO,...
  • 153
1 vote
0 answers
201 views

Uploading a user picture on registration

I would like to make an image upload field so new members are required to upload a picture. I'm new to Craft (I've been a Drupal Front End developer). Other custom fields are working perfectly, and I'...
  • 363
0 votes
1 answer
918 views

Accessing custom fields from User Model

I have a User entries field called 'company'. I'm writing a bespoke plugin to manage users in the front-end and was wondering how I can access the content of this field in my plugin via the user model?...
  • 1,731
0 votes
1 answer
152 views

Trying to capture categories field type data in user profile save/update

I am trying to capture the data that is selected when a user selects categories within a categories field type (handle: groups) within the Control Panel profile tab. I was looking thru the Fields, ...
  • 487
0 votes
2 answers
446 views

Is there a way to programatically add a user when no one is logged in

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in. Is "users/saveUser" the ...
  • 555
0 votes
1 answer
254 views

How can I return all user custom profile fields in an array?

Hi I'm sure this is simple but it is eluding me. I want to pull out all the user profile fields with twig as an array that I can then check. When I dump the user or currentUser data it does not show ...
  • 2,023