Hot answers tagged

29 votes
Accepted

How can I determine if a user is logged in, and who that user is?

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 avatar
  • 23.6k
26 votes
Accepted

Craft constantly logging out from admin area

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/...
user avatar
  • 1,132
25 votes
Accepted

Check user is in User Group / Custom User Permissions

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: {{ ...
user avatar
  • 66.4k
20 votes
Accepted

Users relatedTo multiple categories

Try passing your relatedTo parameters as an array: {% set members = craft.users.group('members').relatedTo([ 'and', { targetElement: services }, { targetElement: locations } ]) %} or a little easier ...
user avatar
  • 35.8k
19 votes
Accepted

How to add custom user fields to the front end registration page

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="...
user avatar
  • 66.4k
18 votes
Accepted

Use email address as username

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 ...
user avatar
  • 66.4k
16 votes
Accepted

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

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" ...
user avatar
  • 13.2k
16 votes

User profile public page

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 ...
user avatar
  • 1,909
16 votes
Accepted

Auto log in user

Check out the autoLoginAfterAccountActivation config setting. To enable it, set it to true in your craft/config/general.php file: 'autoLoginAfterAccountActivation' => true
user avatar
  • 13.2k
15 votes
Accepted

Change the size of a users profile photo?

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 "...
user avatar
13 votes
Accepted

How to identify the logged in user inside a plugin?

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 avatar
12 votes
Accepted

How do I display the Image of an Author in a post?

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 ...
user avatar
  • 6,226
12 votes

How to set up {siteUrl} to work with both http and https

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 ...
user avatar
  • 13.2k
12 votes
Accepted

What are the options for taking membership subscriptions via Craft?

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"...
user avatar
11 votes

Check user is in User Group / Custom User Permissions

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->...
user avatar
11 votes
Accepted

How do I output a dropdown's values if I'm on a registration form not tied to an entry?

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 ...
user avatar
  • 35.8k
11 votes
Accepted

Password protected area with unique files

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 ...
user avatar
10 votes

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

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 '...
user avatar
  • 66.4k
10 votes
Accepted

How do I change a user's password programmatically in a plugin?

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'...
user avatar
  • 66.4k
10 votes
Accepted

Getting logged out of admin area when refreshing site

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. ...
user avatar
  • 1,332
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() { ...
user avatar
9 votes
Accepted

What's the difference between 'user', 'currentUser', and 'account'?

Update: As of Craft 3.x, the deprecated user variable no longer works. Make sure to use the proper currentUser variable instead! Original: user and currentUser are exactly the same. They contain the ...
user avatar
  • 23.6k
9 votes
Accepted

Custom fields on users

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.
user avatar
  • 3,594
8 votes
Accepted

How do you format a date for saving with users/saveUser on the front end?

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 ...
user avatar
  • 6,226
8 votes
Accepted

How do I list entries from a single author?

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(...
user avatar
  • 66.4k
8 votes

Is there a native function or plugin to allow admins to email all users?

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 ...
user avatar
  • 8,316
8 votes
Accepted

How do I reset a user’s password or email them when I create an account?

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” ...
user avatar
  • 66.4k
8 votes
Accepted

Set Up A Global Dashboard For A Specific User Group

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....
user avatar
  • 7,238
8 votes
Accepted

Is it safe to mass delete users from the database directly

If you want to delete users (or any other elements in Craft) directly from the database, the place to do that is the elements table. Delete the row(s) from there, and all the elements’ rows in the ...
user avatar
8 votes
Accepted

When deleting a user do the entries they created also get deleted?

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 ...
user avatar
  • 66.4k

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