Hot answers tagged

10 votes
Accepted

How do I enforce stronger password requirements on my Craft site?

In Craft 2 Plugins have the power to enforce stricter password requirements using the users.onBeforeSetPassword event. Add this code to your plugin’s primary class: public function init() { ...
Brandon Kelly's user avatar
7 votes
Accepted

Redirecting after login based on user group

To set the setting dynamically, you’ll need to create a new plugin, which just has an init() method with this: public function init() { // Is this a login request? if ( craft()->...
Brandon Kelly's user avatar
6 votes
Accepted

How to list all User Groups and Users

Something like this should work: {% set userGroups = craft.userGroups.getAllGroups() %} {% if userGroups|length %} {% for userGroup in userGroups %} <h2> {{ userGroup....
Brad Bell's user avatar
  • 67.2k
6 votes

/admin/actions/users/login 404

What server provisioner are you using? Forge? Something else? If it's Forge, it's most likely this: https://twitter.com/nystudio107/status/895726366477344772 Also here are some Nginx configs (with ...
andrew.welch's user avatar
  • 11.3k
6 votes
Accepted

Create a pending user from plugin

Rolling with this does what I need $newUser = new User([ 'firstName' => $submission->firstName->getValue(), 'lastName' => $submission->lastName->getValue(), 'username' => $...
Steven Grant's user avatar
  • 1,855
5 votes

Recovering (or creating a new) admin account

I'm rusty on MySQL so it took me a while to go through this. I'm leaving this here for future internet travelers. It's based on Brad's solution, so read through that first, then you can use these ...
hisnameisjimmy's user avatar
5 votes

Limit number of sessions per user

Im on Craft v3.4.25, and I've added the following event handler in my module to handle this. There are two scenarios here: either you want the new login to invalidate any existing session, or you want ...
Gary Reckard's user avatar
5 votes
Accepted

Get Groups from User in plugin

Your code to get a user returns a UserModel (as can be seen from the Full Class Reference docs): $user = craft()->users->getUserById($id); You can then get the user groups the $user is a ...
Steve Rowling's user avatar
5 votes

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

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 ...
Damon's user avatar
  • 4,706
5 votes
Accepted

Adding second user to user field in plugin brings server to its knees

You've created an endless loop with calling saveEntry within the entries.saveEntry event listener. You can fix it with implementing a static variable. craft()->on('entries.saveEntry', function(...
carlcs's user avatar
  • 36.1k
5 votes
Accepted

Eager Loading Users Returning "Array to String Conversion" Error

Just checked eager-loading a text field in a template and by eager-loading it you are actually converting the field to an array and therefore unable to template it as usual. Eager-loading is generally ...
mcclaskiem's user avatar
5 votes
Accepted

Automatically subscribe users to MailChimp list?

Install the MailChimp Subscribe plugin and add the following users.onActivateUser event listener to your site’s Business Logic plugin. craft()->on('users.onActivateUser', function(Event $event) { ...
carlcs's user avatar
  • 36.1k
5 votes
Accepted

Single-sign on for multiple Craft sites

No, Craft doesn't have any native notion of SSO. (You can technically run multiple sites from the same Craft instance. If you had sites sharing the same server, you could run them from the same Craft ...
Michael Rog's user avatar
  • 3,400
5 votes

How do I UNLOCK my account?

If you don’t have access to another admin account, you could unlock the account directly in the database. Change the lock value to 0 for the account in the craft_users table.
carlcs's user avatar
  • 36.1k
5 votes
Accepted

/admin/actions/users/login 404

So I looked into this a bunch more tonight to satisfy my curiosity, and here's what is happening. The default rewrite rule that Forge is apparently adding is this: if ($request_uri ~* "^(.*/)index\....
andrew.welch's user avatar
  • 11.3k
5 votes
Accepted

Sending activation emails to all pending users

foreach(\craft\elements\User::find()->status('pending')->all() as $user){ Craft::$app->getUsers()->sendActivationEmail($user); } Fetch all pending users and send them the mail
Robin Schambach's user avatar
5 votes
Accepted

Craft 3 How to get custom user field values

You should be able to access the custom fields on element\user object. Craft::$app->getUser()->getIdentity()->getFieldValue('customfieldname');
Dasun Rathnayake's user avatar
5 votes

Craft 3 How to get custom user field values

If someone lands here searching for a Twig answer like me. {{ currentUser.customFieldHandle }}
Jessica Talzor's user avatar
5 votes
Accepted

Protecting public assets

This answer is a bit self-serving, but I'm the author of the Digital Download plugin. It allows you to control how and when assets are downloaded. You can restrict downloads by a time period, maximum ...
Lindsey D's user avatar
  • 23.9k
5 votes
Accepted

Not require password on user signup

What you want is the deferPublicRegistrationPassword config setting. By default, Craft will require a 'password' field to be submitted on front-end, public user registrations. Setting this to true ...
Marion Newlevant's user avatar
5 votes
Accepted

Stay on the same page after logout

Yep, postLogoutRedirect can be set to a function instead of a static value. So for example, in your template you can generate a hidden field in your logout form (or append a querystring parameter to ...
Evan Warner's user avatar
4 votes

Craft constantly logging out from admin area

For me the solution required was 'requireMatchingUserAgentForSession' => false in my config/general.php I was debugging the site in Chrome and it was changing my user agent, which was instantly ...
James Nisbet's user avatar
4 votes

Allow user to change or delete their photo for their profile from the front end

FWIW, Niall, I've always just created an additional Profile field for people's images. The weird "not really an asset" aspect of the profile pictures is gone in Craft 3, but I found enough annoyances ...
andrew.welch's user avatar
  • 11.3k
4 votes

Activate Users - privilege

I realise this is an old post but I wrote a plugin to handle exactly this, putting this as an answer instead of a comment since OP asks if there's an override: https://github.com/billythekid/...
billythekid's user avatar
4 votes
Accepted

How can I interact with Users via the ElementAPI?

Change function (EntryModel $user) to function (UserModel $user) You were passing in a user to a function that’s expecting an EntryModel. That’s the reason for the error you are getting.
Luke Holder's user avatar
  • 6,767
4 votes
Accepted

How can I add custom validation rules to a new User registration?

At the time of writing the users.onBeforeSave event runs after validation, which means that we can’t add errors to the user easily. The solution I’ve currently come up with is a plugin that adds ...
Joshua Baker's user avatar
4 votes
Accepted

Some paths and settings being ignored in config

You're close! Those config settings are off in no-mans-land right now. If you want them to apply across all of your multi-environment configs, you need to move them into the '*' array like so: ...
Brad Bell's user avatar
  • 67.2k
4 votes
Accepted

How to pull out all user data in a template?

If i understand your question correct, you like to output the user data. I don't think that you need the getContent() function. But it's important, that you use the first() function. Here is your code:...
Tom Bauer's user avatar
  • 1,327
4 votes
Accepted

How can I disable/decrease the number of calls to getAuthTimeout?

Unfortunately, the AJAX call to getAuthTimeout is hard coded to fire every 60 seconds. In other words, if you're looking for a config value, there isn't one – might be worth a feature request? For a ...
Mats Mikkel Rummelhoff's user avatar

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