Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
4 added 55 characters in body
source | link

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only service method I can use? I would prefer to be able to use my custom one.

EDIT: code below works fine when I'm logged in as an admin user, otherwise it redirects me to login form, after form submission. Have I missed something in here?

public function actionAddPartner() 
{
        $content = craft()->request->getPost();
        $companyId = explode("@", $content['email']);
        $user = new UserModel();
        $user->username         = $content['email'];
        $user->email            = $content['email'];
        $user->unverifiedEmail  = $content['email'];
        $user->firstName        = $content['firstName'];
        $user->lastName         = $content['lastName'];
        $user->pending          = true;
        $success = craft()->users->saveUser($user);
        if ($success) {
            // Assign them to the Partner Admin user group
            craft()->userGroups->assignUserToGroups($user->id, 1);
            // Update the Element Index
            craft()->search->indexElementAttributes($user);
        }
}

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only service method I can use? I would prefer to be able to use my custom one.

EDIT: code below works fine when I'm logged in as an admin user, otherwise it redirects me to login form, after form submission. Have I missed something in here?

public function actionAddPartner() 
{
        $content = craft()->request->getPost();
        $companyId = explode("@", $content['email']);
        $user = new UserModel();
        $user->username         = $content['email'];
        $user->email            = $content['email'];
        $user->unverifiedEmail  = $content['email'];
        $user->firstName        = $content['firstName'];
        $user->lastName         = $content['lastName'];
        $user->pending          = true;

        if ($success) {
            // Assign them to the Partner Admin user group
            craft()->userGroups->assignUserToGroups($user->id, 1);
            // Update the Element Index
            craft()->search->indexElementAttributes($user);
        }
}

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only service method I can use? I would prefer to be able to use my custom one.

EDIT: code below works fine when I'm logged in as an admin user, otherwise it redirects me to login form, after form submission. Have I missed something in here?

public function actionAddPartner() 
{
        $content = craft()->request->getPost();
        $companyId = explode("@", $content['email']);
        $user = new UserModel();
        $user->username         = $content['email'];
        $user->email            = $content['email'];
        $user->unverifiedEmail  = $content['email'];
        $user->firstName        = $content['firstName'];
        $user->lastName         = $content['lastName'];
        $user->pending          = true;
        $success = craft()->users->saveUser($user);
        if ($success) {
            // Assign them to the Partner Admin user group
            craft()->userGroups->assignUserToGroups($user->id, 1);
            // Update the Element Index
            craft()->search->indexElementAttributes($user);
        }
}
3 added 1011 characters in body
source | link

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only service method I can use? I would prefer to be able to use my custom one.

EDIT: code below works fine when I'm logged in as an admin user, otherwise it redirects me to login form, after form submission. Have I missed something in here?

public function actionAddPartner() 
{
        $content = craft()->request->getPost();
        $companyId = explode("@", $content['email']);
        $user = new UserModel();
        $user->username         = $content['email'];
        $user->email            = $content['email'];
        $user->unverifiedEmail  = $content['email'];
        $user->firstName        = $content['firstName'];
        $user->lastName         = $content['lastName'];
        $user->pending          = true;

        if ($success) {
            // Assign them to the Partner Admin user group
            craft()->userGroups->assignUserToGroups($user->id, 1);
            // Update the Element Index
            craft()->search->indexElementAttributes($user);
        }
}

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only service method I can use? I would prefer to be able to use my custom one.

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only service method I can use? I would prefer to be able to use my custom one.

EDIT: code below works fine when I'm logged in as an admin user, otherwise it redirects me to login form, after form submission. Have I missed something in here?

public function actionAddPartner() 
{
        $content = craft()->request->getPost();
        $companyId = explode("@", $content['email']);
        $user = new UserModel();
        $user->username         = $content['email'];
        $user->email            = $content['email'];
        $user->unverifiedEmail  = $content['email'];
        $user->firstName        = $content['firstName'];
        $user->lastName         = $content['lastName'];
        $user->pending          = true;

        if ($success) {
            // Assign them to the Partner Admin user group
            craft()->userGroups->assignUserToGroups($user->id, 1);
            // Update the Element Index
            craft()->search->indexElementAttributes($user);
        }
}
2 added 5 characters in body
source | link

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser() craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only controllerservice method I can use? I would prefer to be able to use my custom one.

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser() , but this doesn't work when no user is logged in.

Is "users/saveUser" the only controller I can use? I would prefer to be able to use my custom one.

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in.

Is "users/saveUser" the only service method I can use? I would prefer to be able to use my custom one.

1
source | link