Hot answers tagged

28

To determine if the user is logged in at all, you'll want to use the currentUser variable: {% if currentUser %} Welcome, {{ currentUser.friendlyName }}! {% endif %} To determine if the logged in user is a specific user, then simply compare against their username: {% if currentUser and currentUser.username is 'johndoe' %} Hey Johnny Boy! {% endif %}...


27

My solution is to add: 'overridePhpSessionLocation' => false Into craft/config/general.php This tells Craft to use the default location to write sessions, instead of craft/storage/runtime/sessions For whatever reason, even though craft/storage/runtime/sessions has CHMOD 777, PHP was saving the session file with 644. When it tried to write to the same ...


20

I believe what you're looking for is 'isInGroup' {% if currentUser.isInGroup('groupHandle') %} It will also accept an actual group object or a group ID as well. There is also getGroups: {{ currentUser.getGroups() }} Will return an array of UserGroupModels all of the groups the user belongs to. And finally, can: {{ currentUser.can('permissionName') }} ...


18

Try passing your relatedTo parameters as an array: {% set members = craft.users.group('members').relatedTo([ 'and', { targetElement: services }, { targetElement: locations } ]) %} or a little easier to read: {% set entries = craft.users({ group: 'members', relatedTo: [ 'and', { targetElement: services }, { targetElement: ...


17

You need to change your input tag from: <input id="Address" type="text" name="Address" {%- if account is defined %} value="{{ account.Address}}"{% endif -%}> To: <input id="Address" type="text" name="fields[Address]" {%- if account is defined %} value="{{ account.Address}}"{% endif -%}> All custom fields input types should have a name ...


16

Before you can allow a user to manage their profile photo in your front-end profile edit form, be sure to update your form tag with the enctype="multipart/form-data" parameter: <form method="post" enctype="multipart/form-data"> You can access a users profile photo using the currentUser global and fallback to a different image like so: {% if ...


16

You will need to add a custom route for the path for which you want to show the profile from a list of all users. Per my example of /profile/{{ username }}: In your profile/index template, you would run a loop on the user set of your choice: {% set users = craft.users %} {% for user in users %} <a href="/profile/{{ user }}">{{ user }}</a> {...


16

I believe you're looking for the conveniently named useEmailAsUsername config setting. When that is set to true, any new user that is saved with a valid email address will have that copied over to the username field as well.


16

Check out the autoLoginAfterAccountActivation config setting. To enable it, set it to true in your craft/config/general.php file: 'autoLoginAfterAccountActivation' => true


15

I found the answer on the Craft website under the UserModel section: getPhotoUrl( size ) Returns a URL to the user’s photo at a given size in pixels (defaults to 100). You can also pass in "original" if you want to get a non-resized photo back. Although this does answer my question, I feel the behavior between handling this "asset" ...


12

That will get you the url of the current user's photo. To get an author's photo do this: {{ author.photoUrl }} If the author is not defined in your context but the entry is, then get the entry's author's photo as follows: {{ entry.author.photoUrl }}


12

One method is using something like the following in your general.php file. Using this method the config settings will take on the scheme of the request being made. I've set both the siteUrl and example environmentVariables below: <?php // Ensure our urls have the right scheme define('URI_SCHEME', ( isset($_SERVER['HTTPS'] ) ) ? "https://" : "http://" ...


12

I don't think that there currently is a plugin option right now, but keep an eye on the craft plugin page. However, given your requirement to "automatically assign users to different membership groups", I think you would need to write your own regardless. That is pretty specific and would require that you have your user groups set up to match the ...


12

I'm a bit confused by your question. It sounds as though you want to check if the currently logged-in user is an Administrator, but it looks like you're actually checking whether the newly-registered user is an Administrator. Here's how to retrieve the currently logged-in User, and check whether they belong to a specific User Group. function (Event $event)...


11

The not so elegant way to do this is to re-use the field somewhere else, where you do have access to (e.g. a global set). But you probably want to avoid this, right? What you can do instead is to access the field directly using craft.fields. This function returns the FieldModel of your field, containing all of its properties. The FieldModel property you ...


11

It is very easy within your templates to define requirements for whether the page itself, or portions of the content are displayed, and/or route the user to another page if they do not meet the page requirements. For example, you can check whether the user is logged in, belongs to a particular group, is the author of the entry, has a specific permission (and ...


10

If you want a user to be able to upload a profile photo from the front-end, the you should be able to add enctype="multipart/form-data" to your form that saves your user and have a file input called 'userPhoto'. <input type="file" name="userPhoto" id="image-upload" /> If you want to delete a user's existing profile photo, then add a hidden input ...


10

You shouldn't need to call changePassword() at all. Try this: $user = craft()->users->getUserById(6); $user->newPassword = 'mynewpassword123'; craft()->users->saveUser($user); If it's not updating correctly, then there is likely a validation error somewhere. You can check that with: $user->getErrors(); Which will return an array of ...


10

The problem was actually Chrome using iOS emulation when viewing the site, thus spoofing the UA string into something different than the usual Chrome UA string when logging into the admin area. Solution (as suggested by @craftcms on Twitter) was to set: 'requireMatchingUserAgentForSession' => false In craft/config/general.php For whatever environment ...


10

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() { craft()->on('users.beforeSetPassword', array($this, 'onBeforeSetPassword')); } public function onBeforeSetPassword(Event $e) { $user = $e->params['user']...


8

Craft stores dates in the database in the following format: Y-m-d H:i:s So submitting the date in this format should work, for example: 2014-06-24 23:30:00 It should also be possible to split the date and time into individual fields as follows: <input type="text" name="fields[customFieldName][date]" value="2014-06-24" /> <input type="text" name=...


8

Try this: {# First, grab the username from the URI #} {% set username = craft.request.segment(2) %} {# Then, grab the user based on the username %} {% set user = craft.users.username(username).first() %} {# Make sure we actually found a user #} {% if user %} {% set blogPosts = craft.entries.section('blog').authorId(user.id).find() %} Found: {{ ...


8

Currently there isn't a native function to do this. The only plugin that I know of that can do this, is Sprout Email from Barrel Strength Design. EDIT: I just released a plugin called Craft-Mailer which does what you are looking for.


8

If you are an administrator or your account has “administrate users” privileges, then there is a checkbox on the user’s edit page in the control panel that says “Require Password Reset on Next Login” which, if checked, will force the users to reset their password the next time they attempt to login. When creating a new account, if you leave the “Require ...


8

The dashboard widgets are currently set on a per user basis. Brandon has said on the Google+ community that a site-wide and/or user group solution is planned but doesn't have en ETA. https://plus.google.com/106689452282751248337/posts/CvZZa5DDGwb https://plus.google.com/103717873128586100650/posts/gW9buKqF4LA


8

If you're looking to check groups and/or permissions from your plugin controller with PHP, you can access the same methods. Craft 3.0.x: //get the current user from craft $user = Craft::$app->getUser(); //check if the current user has permission to edit certain entries $user->getIdentity()->can('editEntries: 27') //check if user is in group $...


8

Currently, yes, that's how it works. It's on our list to 1) Add a prompt warning what's about to happen and 2) Add options as to what you want to do with that author's current content (assign to a different user, delete, etc.). Update: As of Craft 2.3, when a user's account is deleted you'll be prompted what you want to do with their content.


8

Yes you can. Go to Settings > Users then the Fields tab. Here you can add fields just like you would for categories or entry types.


8

For security reasons, this was changed in Craft 2.3... Admins are no longer allowed to change other users’ passwords. But savvy admins can still pull it off... Simply click the gear icon in the right sidebar, and select "Copy password reset URL". Then, instead of sending that URL to the user, just use it yourself.


7

I don't know of a plugin that exists expressly for this purpose, but you could combine LumberJack (logging plugin) with Craft's numerous events to make this happen with your own plugin. You can log from within said plugin or even in your Craft templates. Take a look at the event reference and see if there's enough there to satisfy your client's needs. ...


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