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()
{
...
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()->...
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....
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 ...
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' => $...
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 ...
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 ...
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 ...
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 ...
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(...
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 ...
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) {
...
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 ...
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.
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\....
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
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');
5
votes
Craft 3 How to get custom user field values
If someone lands here searching for a Twig answer like me.
{{ currentUser.customFieldHandle }}
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 ...
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 ...
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 ...
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 ...
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 ...
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/...
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.
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 ...
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:
...
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:...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
users × 501plugin-development × 74
craft3 × 52
registration × 36
user-profile × 35
user-groups × 33
templating × 30
password × 28
control-panel × 25
emails × 25
login × 23
activation × 23
form × 22
permissions × 22
entries × 21
plugins × 20
current-user × 17
session × 15
relations × 14
admin × 14
usermodel × 14
config × 13
frontend × 12
assets × 11
author × 11