We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25586
    • 105 Posts
    Hi, I installed the ’Login’ snippit yesterday and after playing with it I noticed that I can’t use extended paramaters.

    So my question is: Is there a way to add extended profile options to registred users in modx?
    • Use WebLoginPE instead.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 25586
        • 105 Posts
        I wish I could use it but I’m working with Revolution and WebLoginPE won’t support it sad
        • Oops...sorry, reading too many forum posts too fast!
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 25586
            • 105 Posts
            Oke, I have tried several ways but my php knowledge is to minor to get it working.

            I have taken the Login snippit and took the register.snippit.php. I have added the my addProject code but the project wont get added to the db sad

            Anyone know how to get it working? ’//ADDED CODE’ is my costum code

            $model_path = $modx->getOption('core_path').'components/login/model/login/';
            $login = $modx->getService('login','Login',$model_path,$scriptProperties);
            $modx->lexicon->load('login:register');
            $pm_base_path = $modx->getOption('core_path').'components/projectmanager/'; //ADDED CODE
            
            
            
            /* set default properties */
            $properties = array();
            $name = $_POST["name"]; //ADDED CODE
            
            $submitVar = $modx->getOption('submitVar',$scriptProperties,'login-register-btn');
            if (!empty($_POST) && (empty($submitVar) || !empty($_POST[$submitVar]))) {
                /* handle validation */
                $login->loadValidator();
                $fields = $login->validator->validateFields($_POST);
            
                /* make sure username isnt taken */
                $alreadyExists = $modx->getObject('modUser',array('username' => $fields['username']));
                if ($alreadyExists) {
                    if ($alreadyExists->get('active') == 0) {
                        /* if inactive, probably an expired activation account, so
                         * let's remove it and let user re-register
                         */
                        $alreadyExists->remove();
                    } else {
                        $login->validator->errors['username'] = $modx->lexicon('register.username_taken');
                    }
                }
            
                if (empty($login->validator->errors)) {
                    $result = require_once $login->config['processorsPath'].'register.php';
                    
            		$modx->addPackage('projectmanager',$pm_base_path.'model/'); //ADDED CODE
            		$pm_project = $modx->newObject('pmProject'); //ADDED CODE
            		$pm_project->fromArray(array( //ADDED CODE
             		   'name' => $name, //ADDED CODE
            		)); //ADDED CODE
            		$pm_project->save(); //ADDED CODE
            
                    if ($result !== true) {
                        $modx->toPlaceholder('message',$result,'error');
                    }
                }
                $modx->toPlaceholders($login->validator->errors,'error');
                $modx->toPlaceholders($fields);
            }
            
            return '';



            My added code:
            $name = $_POST["name"];
            $pm_base_path = $modx->getOption('core_path').'components/projectmanager/';
            		$modx->addPackage('projectmanager',$pm_base_path.'model/'); 
            		$pm_project = $modx->newObject('pmProject');
            		$pm_project->fromArray(array(
             		   'name' => $name,
            		));
            		$pm_project->save();
            


            If someone can point out what I’m doing wrong I can continue with my snippit smiley

            Thanks!

            Rogier
              • 25586
              • 105 Posts
              I got it working.

              	if (empty($login->validator->errors)) {
              		$base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/projectmanager/';
                      $modx->addPackage('projectmanager',$base_path.'model/');
                 		$newProjectTpl = $modx->getChunk($newProjectTpl);
              		$name = $_POST["name"];
              		$project = $modx->newObject('pmProject');
              		$project->fromArray(array(
               		   	'name' => $name,
              		));
              		$project->save();
              	}
              


              Took my code and put it in a if statement, now it is working smiley. After reading http://modxcms.com/forums/index.php?topic=40479.0 I’m beginning to wonder if I’m working in the correct way. This is my working example:

              A user sings up for a project. Both user and project have a unique company_id so the user can view there projects. Is it a good way to work like this or would it be better to use "aggregate element"?

              Its working but I prefer to work with the best method possible smiley
              • You could do this in a Plugin attached to the OnWebLogin and/or OnManagerLogin events without changing the Login snippet code, I believe.
                  • 25586
                  • 105 Posts
                  Thanks, but I decided to dig deeper in http://svn.modxcms.com/docs/display/xPDO20/Working+with+Related+Objects. I think it’s a better way to deal with related objects than a unique identifier.