10

There aren't specific User element save events in Craft 3, but you can listen to EVENT_AFTER_SAVE_ELEMENT and check if the element is a user like so: Event::on(\craft\services\Elements::class, \craft\services\Elements::EVENT_AFTER_SAVE_ELEMENT, function(Event $event) { if ($event->element instanceof \craft\elements\User) { // Do your thing. ...


4

Use newPassword instead: $user->newPassword = '123456';


4

Before you can allow any type of user groups you will need at a minimum of the Client version of Craft. To allow public registration, you will need the Professional version. Only the Professional version will allow you to have public registration on our site. Here is more information about users and user groups. To add additional fields to your registration ...


4

Just because EmailService::sendEmailByKey() requires you to pass in a UserModel, doesn’t mean that the model has to represent an actual saved user. You can create one on the spot for them: $user = new UserModel(); $user->email = 'sergster@abc.xyz'; $user->firstName = 'John'; // optional $user->lastName = 'Doe'; // optional craft()->email->...


3

So it seems the only way to achieve this is to assign the user to the group, not the other way round (assign the group to the user). So once my user has saved I can call following: craft()->userGroups->assignUserToGroups($user->id, $groupId);


3

Welcome to the community Adam. Yes. Completely possible with vanilla Craft. There's always more than one way to achieve things but here's a first round. Start by creating two User Groups; Contractors and Clients. This will allow you to define permissions as needed. Your 'Property Projects' Section could contain fields like. Title Description Images ...


3

Not totally sure, but I believe this may be because the UsersService actually caches UserModels fetched by getUserById() locally in a private class variable. Instead of using getUserById(), try pulling the user with an ElementCriteriaModel: $existing = craft()->elements->getCriteria(ElementType::User, array( 'id' => $userId, ))->first();


3

As always, spent hours trying to figure this out and came upon the answer within an hour after posting the question on Stack. Here's the working code: // get entry $entry = craft()->entries->getEntryById($entryId); // get ALL users related to entry $users = craft()->elements->getCriteria(ElementType::User); $users->...


3

The Matt's answer was pretty complete and worked almost, but for the benefit of others, there is the changes required files to make it works: in integration.php find define('SET_SESSION_NAME',''); change for define('SET_SESSION_NAME','CraftSessionId'); and make your getUserID functions look like function getUserID() { $userId = 0; // ...


3

Response via Slack from Brandon Kelly: Accessing custom field values from PHP is the same as in Twig - once you have the UserModel it's just $user->myCustomFieldHandle or $user->myEntriesField->first(), etc. Managed to get via following: $user->company->first()->title


3

Usually, its very easy to pull data from a relational fieldtype (Categories, Entries, Assets etc). E.g. if your Categories field handle is memberGroups, you can simply do this: $categories = $user->memberGroups; However, your Categories field handle is groups, which conflicts with the built-in UserModel attribute groups, used to pull any user groups the ...


3

Find a single user by his/her affiliateId (int). $criteria = craft()->elements->getCriteria(ElementType::User); $criteria->affiliateId = 1; $users = $criteria->find(); Query all users within the Affiliate group, order by studentCount asc and return the top record. (I need a user that has the fewest number of students). $criteria = craft()-&...


3

As of Craft 2.3, the rules for changing an existing password are: If you're editing your existing account OR you're an administrator OR you have the 'changeUserEmails' permission set on your user account, then you need to supply your existing user account's password as a hidden input (not the current password for the account you're trying to change). <...


3

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 web. I agree, and that's something we overlooked when we added the 'useEmailAsUsername' config setting. Question: Is there a way to remove the username (in my case email address) from the photo path and replace it with the users ID ...


3

You can just use: {% for entry in craft.entries.section('downloads').relatedTo(currentUser) %} {{ entry.title }} {% endif %} This is essentially returning an ElementCriteriaModel of reverse related entries sorted by entry date by default. You can also access the related entries through the field itself: {% for entry in currentUser.selectDownloads %} ...


3

Within the context of that event, you will have access to: $event->params['user'] ... which is: A UserModel instance representing the user that has just been activated. Once you've got your user model, you can do something like this: $event->params['user']->isInGroup('artists') On a separate note, I believe the correct syntax is: craft()-&...


3

I'm not sure if this is causing your error, but it's recommended to use setContentFromPost() or getContent()->setAttributes() so that craft has a chance to prep the field values, as discussed in this answer, setContent() vs $entry->getContent()->foo, and What is getContent()?. $user = craft()->userSession->getUser(); $user->getContent()->...


3

Solved! {% for letter in currentUser.newsletters.options %} <input type="checkbox" value="{{ letter.value }}" name="{{ letter.value }}" id="{{ letter.value }}" {% if letter.selected == true %}checked="checked" {% endif %}/> <label for ="{{ letter.value }}">{{ letter.label }}</label> {% endfor %}


3

You can also try User::EVENT_BEFORE_SAVE. I'm not sure that it's documented anywhere, or if it was added after Brad responded, but it might work too. use yii\base\Event; use craft\elements\User use craft\events\ModelEvent; Event::on( User::class, User::EVENT_AFTER_SAVE, function(ModelEvent $event) { ... } );


2

The user has already been saved at this point and is available as $event->params['user']. If you modify data and save again, however, you will need to be careful of creating an endless loop — not sure what you are trying to do. In this case you should be ok because of the "IsNewUser" conditional. public function init() { parent::init(); craft()-&...


2

If you want to get a user model based on UID you can do this. For current user.. Get current user $currentUser = craft()->userSession->getUser(); Get user record $currentUserRecord = $this->_getUserRecordById($currentUser->id); Add this private function (copied from UserService.php). This will pull the user record by calling _getUserRecordById ...


2

Currently, Craft doesn't expose the UID in any of its models. Kind of a pain, but the only thing I can think of as as a workaround is to write a plugin that has a UserModel with the UID and mimics whatever methods from UsersService that you need.


2

Custom field data is accessible via currentUser.getContent(). Using dump: {{ dump(currentUser.getContent()) }} Or to output as string: {{ currentUser.getContent()|join(', ') }}


2

You'd create a Craft plugin with a controller that has an action, say actionSaveForm(). Your controller would look for a password POST variable and if that existed, validate that against the currently logged in user's account to make sure it was a match. If so, continue onto Craft's saveUser or saveEntry, etc. (whatever you're using the form for, otherwise,...


2

Looks like I needed to set $user->username = craft()->request->getPost('email'); for my attempt to work.


2

You'll need to save the new user before you can activate them. This code should do the trick: if (craft()->users->saveUser($newUser)) { craft()->users->activateUser($newUser); }


2

So, the Comet Chat is not able to read the userid, even if I made a Craft plugin who writes UserID in $_SESSION['userid']. To access Craft's session variables outside Craft, you need to pull the session ID from the CraftSessionId cookie, and then use that to revive the session: $sessId = $_COOKIE[ 'CraftSessionId' ] ?: false; if ( $sessId ) { ...


2

Per Brad's request. I am answering my own question. I figured out that I was logging in via non-www, and accessing the site at www. So the official answer is to choose either www or non-www. I chose to remove the www from the URL. Here's my .htaccess for that, including allowing for fonts to be accessed cross domain, as I had issues with this as well. &...


2

Oh well, totally forgot to allow anonymous access at the top of the controller. I guess I can leave this answer here in case somebody is as forgetful as me: protected $allowAnonymous = true;


2

You could try using the attribute function in twig, this should let you call dynamic properties. Something like: {{ attribute(currentUser, question.fieldName) }}


Only top voted, non community-wiki answers of a minimum length are eligible