I'm trying to activate a user via a plugin so that when the user is returned to the login page they are re-directed to their profile page.

I'm making use of the social logins beta plugin by dukt (I have written directly to them as well) which works fine if the user is already a craft user. However if the user is completely new to craft it throws an error saying the 'Account Has Not Been Activated'. When checking the CMS though the account has been set up and is active. So somewhere along the line the activation seems to be too late and is being delayed until after the user is sent back to the template.

The code creates a new user model in the plugin service with the _registerUser function. Which when looking at the object returned has 'pending =>' so not actually set to anything not even zero.

I've tried a couple of things but neither worked firstly adding


directly after saving the new UserModel and before returning the model.

Secondly setting the new UserModel with pending = 0 and pending = '0'

$newUser = new UserModel();
$newUser->username = $attributes['email'];
$newUser->email = $attributes['email'];
$newUser->pending = '0';

So can anyone shed any light on this or can advise me if this is possible from within the plugin or how the activation works on a new user when you want to automatically activate them without sending an activation email.

Many thanks

2 Answers 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 3 answer:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.