We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Should you also allow anyone to register with a username that equals their email address?
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
    • Quote from: rthrash at Apr 21, 2008, 11:37 PM

      Should you also allow anyone to register with a username that equals their email address?
      [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,7}

      Provided you are using my updated e-mail RegExp, then it would need to accept the following:

      a-zA-Z, 0-9, period, underscore, percent, plus, minus, @ sign
      //<?php // Used for highlighting only - Do Not Copy
      
      // Check username for bullshit.
      if( strspn($_POST['username'],'"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._%+-@') != strlen($_POST['username']) ) // pixelchutes
      


      However, you’ll find you may quickly run into this error message:

      Your username is too long. It must be less than 20 characters.

      (Which is odd, since the table structurally can hold up to 100 characters)

      To correct this, find the following:
      //<?php // Used for highlighting only - Do Not Copy
      
      		// Check username length 
      		if (strlen($username) >= 20)
      

      And update to this:
      //<?php // Used for highlighting only - Do Not Copy
      
      		// Check username length 
      		if (strlen($username) > 100)
      


      Registered Successfully!* Now you can register your email as your username! (Thx Ryan)

      Quote from: "assets/snippets/webloginpe/lang/en.php"
      $wlpe_lang[1] = ’Your username is too long. It must be less than 20 characters.’;

      NOTES:*
      - You may want to update your language files for $wlpe_lang[1] as it states maximum length of 20 characters here
      - By allowing e-mail address to function as the registered member’s username, you may run into unforeseen (and untested) dilemmas, such as: public exposure of "usernames" which many users would not like, as well "Profile" view from the users list appears to break:

      For example, if you registered using a username of: [email protected]

      The default "View User Profile" link would cause the plus to be converted to a space, resulting in an empty result set for the query, not to mention an empty profile page:
      SELECT * FROM `modx_site`.`modx_web_users` WHERE `username` = 'mike [email protected]'


      One way this could be corrected is by handling web user references via internalKey in place of username, but would also require additional work to the PHP Class.

      view_profile.html?service=viewprofile&[email protected]
      to something like:
      view_profile.html?service=viewprofile&userid=15

      Provided everything DID work ok, however, some users may still wish to hide their email address from public view...Then what? You could use the user’s Fullname, but that might conflict with those users who want their name protected.
      Would you then need to begin handling custom --yet unique--"Display Names" huh
        Mike Reid - www.pixelchutes.com
        MODx Ambassador / Contributor
        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
        ________________________________
        Where every pixel matters.
      • We decided we wanted to break-out First name and Last name into separate fields, which was super easy to pull off using the CustomTable and CustomFields! However, we wanted to ensure that the web_user_attributes.fullname table column was updated as well...

        Unfortunately, there does not seem to be a way to do this via OnBeforeWebSaveUser as the $fullname variable is not an attribute of the WLPE instance, and therefore does not provide a way to change this data prior to the user record being created.

        So, without having to rewrite everything to accomplish this, we opted to use an SQL UPDATE statement in the OnWebSaveUser system event instead. However, the internalKey from the newly inserted web user does not get passed in the parameters provided to the plugin!

        Rather than querying the table to determine manually, a small update to the Register() function can provide us exactly what we need!

        In the Register() function, find the following line: (The function already determines the new internalKey value)
        $key = $modx->db->getInsertId();
        Add the following code below the line above:
        $NewUser[’internalKey’] = $key; // pixelchutes

        Now, in OnWebSaveUser (and OnBeforeAddToGroup) plugins, you can reference $user[’internalKey’] directly!

        //<?php - Syntax highlighting only - Do Not Copy
        
        $e = &$modx->event;
        
        switch( $e->name ){
        
            case 'OnWebSaveUser': 
                
                // Map first name/last name to MODx fullname            
                $updateFullName = "UPDATE ".$modx->getFullTableName('web_user_attributes')." SET `fullname`='".$modx->db->escape(ucwords(strtolower( $user['lname'].', '.$user['fname'] )))."' WHERE `internalKey`='".$user['internalKey']."'";
                $updateFullName = $modx->db->query( $updateFullName );
                        
            break;
             
        }
        
          Mike Reid - www.pixelchutes.com
          MODx Ambassador / Contributor
          [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
          ________________________________
          Where every pixel matters.
        • Quote from: elander at Jan 12, 2008, 05:05 PM


          Corrected version:
          				$charset='"'.$modx->config['modx_charset'].'"';
          				$generalElementsUpdate[] = " `".$field."` = '".$modx->db->escape(stripslashes(htmlentities(trim($_POST[$field]), ENT_QUOTES,$charset)))."'";


          That should do the trick.

          I run into issues when trying the above suggested solution. (Not sure why enclosing a string in quotes?)

          This worked fine for me:

          //<?php - Highlighting only - Do Not Copy
          
          $generalElementsUpdate[] = " `".$field."` = '".$modx->db->escape(stripslashes(htmlentities(trim($_POST[$field]), ENT_QUOTES, $modx->config['modx_charset'])))."'";
            Mike Reid - www.pixelchutes.com
            MODx Ambassador / Contributor
            [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
            ________________________________
            Where every pixel matters.
            • 18862
            • 70 Posts
            @ Soshite - How did your spring exams go? smiley

            wlpe1.3.1 seems to be very close. Thanks to everyone for their contributions to this awesome snippet. I think so far Pixelchutes is the winner with the most bug fixes submitted. What a great community! This is one of the best threads I’ve seen. Those who are working with the snippet actually submit the SOLUTIONS together with the problems they are encountering. That is just awesome.
              • 18862
              • 70 Posts
              Soshite has posted a preliminary 1.3.1 release and needs help testing it!

              Head on over to download and start testing! smiley

              http://modxcms.com/forums/index.php/topic,25821.0.html
              • Quote from: mbrinson at May 21, 2008, 03:39 PM

                I think so far Pixelchutes is the winner with the most bug fixes submitted. What a great community! This is one of the best threads I’ve seen. Those who are working with the snippet actually submit the SOLUTIONS together with the problems they are encountering. That is just awesome.

                Woo hoo! smiley
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                  • 28033
                  • 925 Posts
                  Quote from: mbrinson at May 21, 2008, 03:39 PM

                  @ Soshite - How did your spring exams go? smiley

                  Pretty good. Aced everyone one of them (A’s). smiley
                    My Snippets
                    -> PopUpChunk v1.0
                  • I’ll give you an A+ if you can incorporate a proper admin-approval of webusers modification. Would likely need a new mode, and being able to do it from an admin email would be even better! smiley
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 34017
                      • 898 Posts
                      Quote from: rthrash at May 23, 2008, 12:53 PM

                      I’ll give you an A+ if you can incorporate a proper admin-approval of webusers modification. Would likely need a new mode, and being able to do it from an admin email would be even better! smiley

                      It should be possible with 2 new parameters.
                      1. admin_approve=`1` (default to 0)
                      2. admin_approve_email = `` (default to site_config->email)

                      The approve function is already set. It could just pull these params in and change the email to. I did this manually recently.
                        Chuck the Trukk
                        ProWebscape.com :: Nashville-WebDesign.com
                        - - - - - - - -
                        What are TV's? Here's some info below.
                        http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                        http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008