We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I need to add a unique code to a user profile when a new user is created VIA the admin.
    - the person adding the user should not have to enter the code, it should be auto generated
    - I need to be able to retrieve that code easily to generate some custom urls

    I was wondering what the best method to start this would be, I can easily enough create a snippet that will generate the code, but as far as ’firing’ it and associating it with the user profile - am a bit stuck.....

    Is there some documentation/examples for something similar I could read to get started?

    -thanks
    -sean
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 3749
      • 24,544 Posts
      What version of MODx? What field will the unique code be going in?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 26503
        • 620 Posts
        Revolution [the most recent build] - we are talking a new custom field, not re-purposing an existing one.
          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525
          • 32699 ☆ A M B ☆
          • 427 Posts
          If you are talking about a single field you may be able to get away with using the extended fields tab.

          If you are wanting to implement something more involved, you may want to take a look at my article in the docs:
          http://rtfm.modx.com/display/revolution20/Extending+modUser. it should give you a starting point.
            Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

            Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
            • 3749
            • 24,544 Posts
            One way is to generate the code with time(), then add it to the user profile in a plugin connected to OnUserFormSave only when
            $mode  ==  modSystemEvent::MODE_NEW


            That will keep it from happening when updating an existing user.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 26503
              • 620 Posts
              thanks Shawn, Bob;

              ok - lemme see if I got this right,

              - create my extra DB table in mysql
              - create and register the schema http://rtfm.modx.com/display/revolution20/Using+Custom+Database+Tables+in+your+3rd+Party+Components
              - create a plugin that fires on the ’OnUserFormSave’ event http://rtfm.modx.com/display/revolution20/Plugins
              Now here’s where it gets hazy, I should be able to now create a modx resource page containing a snippet that accesses the user object[??] and can retrieve that value/code for use?

              not quite sure I understand the ’MODE_NEW’ part [I see what you are saying it does, just not where it comes from] of
              $mode  ==  modSystemEvent::MODE_NEW


              -sean
                *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                Sean Kimball CLP, CLS.
                Technical Director / Sr. Developer | BigBlock Studios
                ._______________________________________________.
                Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                phone/fax: 905-426-5525
                • 1169
                • 312 Posts
                Hi am I missing something here??

                The user already has a unique id.

                Just a thought!!
                  DEVELOPMENT ENV:- Ubuntu 12.04 | MODx Revolution 2.2.8 | LAMP 2i Apache 2.2.22 | Php 5.3.10 | Mysql 5.5.31 MySQL client version: 5.5.31
                  • 26503
                  • 620 Posts
                  Hi Allan;

                  yes - the user does already have an ID, but I want something ’unguessable’ as they are to be used in public URLs i.e. http://_mysite.com/fileRequest.php?userid=1234-qwer&file=myfile

                  -sean
                    *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                    Sean Kimball CLP, CLS.
                    Technical Director / Sr. Developer | BigBlock Studios
                    ._______________________________________________.
                    Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                    27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                    phone/fax: 905-426-5525
                    • 3749
                    • 24,544 Posts
                    Quote from: sean69 at Mar 22, 2011, 10:20 AM

                    thanks Shawn, Bob;

                    ok - lemme see if I got this right,

                    - create my extra DB table in mysql
                    - create and register the schema http://rtfm.modx.com/display/revolution20/Using+Custom+Database+Tables+in+your+3rd+Party+Components
                    - create a plugin that fires on the ’OnUserFormSave’ event http://rtfm.modx.com/display/revolution20/Plugins
                    Now here’s where it gets hazy, I should be able to now create a modx resource page containing a snippet that accesses the user object[??] and can retrieve that value/code for use?

                    not quite sure I understand the ’MODE_NEW’ part [I see what you are saying it does, just not where it comes from] of
                    $mode  ==  modSystemEvent::MODE_NEW


                    -sean

                    I would use one of the unused fields in the user profile instead (fax?) It will be much easier and faster and won’t require a custom DB table.

                    The $mode variable is sent to the plugin automatically when the OnUserFormSave event is triggered and has only two possible values. All you have to do is check its value.

                    You can create the resource page in your plugin, and yes, a snippet can access the user object and send the user there.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 26503
                      • 620 Posts
                      ah so we are talking more along the lines of:

                           if($mode  ==  modSystemEvent::MODE_NEW){
                                // then do something interesting
                           }else{
                                // do nothing at all!
                           }
                      


                      I’m not 100% sure about the ’unused field, theses users are companies - I have no idea what fields the end user is going to populate - but I do know they can’t be trusted not to ’fiddle’ with something, so I really do want that unique id to be well hidden & tamper proof.


                      Currently I do have the core stuff done, the database table, a plugin on the event that does insert a UUID on the form save [every time wink - will fix that today] - though the database call is the stand mysqlconnect provides user names and passwords, will need to find some docs and tutorials on how to interact with the database ’correctly’ today. [truth is I read too much documentation yesterday and got overloaded!]


                      Thanks for staying tuned, I really do appreciate the help.


                      -sean


                      ****EDIT***

                      Just tested, this works perfectly BTW
                        *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                        Sean Kimball CLP, CLS.
                        Technical Director / Sr. Developer | BigBlock Studios
                        ._______________________________________________.
                        Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                        27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                        phone/fax: 905-426-5525