We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25663 MODX Staff
    • 12,272 Posts
    The current and next tech preview has weblogin snippets already created. Or am I missing something here (late to the party... sorry...)
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 33337
      • 3,975 Posts
      Would any of you guys mind posting a snippet you've created for login/registration?

      Please see below the code:

      WebLogin Snippet:
      # WebLogin 1.0
      # Created By Raymond Irving 2004
      #::::::::::::::::::::::::::::::::::::::::
      # Usage: 	
      #	Allows a web user to login to the website
      #
      # Params:	
      #	&loginhomeid 	- (Optional)
      #		redirects the user to first authorized page in the list.
      #		If no id was specified then the login home page id or 
      #		the current document id will be used
      #
      #	&logouthomeid 	- (Optional)
      #		document id to load when user logs out	
      #
      #	&pwdreqid 	- (Optional)
      #		document id to load after the user has submited
      #		a request for a new password
      #
      #	&pwdactid 	- (Optional)
      #		document id to load when the after the user has activated
      #		their new password
      #
      #	&logintext		- (Optional) 
      #		Text to be displayed inside login button (for built-in form)
      #
      #	&logouttext 	- (Optional)
      #		Text to be displayed inside logout link (for built-in form)
      #	
      #	&tpl			- (Optional)
      #		Chunk name or document id to as a template
      #				  
      #	Note: Templats design:
      #			section 1: login template
      #			section 2: logout template 
      #			section 3: password reminder template 
      #
      #			See weblogin.tpl for more information
      #
      # Examples:
      #
      #	[[WebLogin? &loginhomeid=`8` &logouthomeid=`1`]] 
      #
      #	[[WebLogin? &loginhomeid=`8,18,7,5` &tpl=`Login`]] 
      
      # Set Snippet Paths 
      $snipPath  = (($modx->insideManager())? "../":"");
      $snipPath .= "assets/snippets/";
      
      # check if inside manager
      if ($m = $modx->insideManager()) {
      	return ''; # don't go any further when inside manager
      }
      
      # deprecated params - only for backward compatibility
      
      if($loginid) $loginhomeid=$loginid;
      if($logoutid) $logouthomeid = $logoutid;
      if($template) $tpl = $template;
      
      # Snippet customize settings
      $liHomeId	= isset($loginhomeid)? explode(",",$loginhomeid):array($modx->config['login_home'],$modx->documentIdentifier);
      $loHomeId	= isset($logouthomeid)? $logouthomeid:$modx->documentIdentifier;
      $pwdReqId	= isset($pwdreqid)? $pwdreqid:0;
      $pwdActId	= isset($pwdactid)? $pwdactid:0;
      $loginText	= isset($logintext)? $logintext:'Login';
      $logoutText	= isset($logouttext)? $logouttext:'Logout';
      $tpl		= isset($tpl)? $tpl:"";
      
      # System settings
      $isLogOut		= $_REQUEST['webloginmode']=='lo' ? 1:0;
      $isPWDActivate	= $_REQUEST['webloginmode']=='actp' ? 1:0;
      $isPostBack		= count($_POST) && isset($_POST['cmdweblogin']);
      $isPWDReminder	= $isPostBack && $_REQUEST['txtpwdrem']=='1' ? 1:0;
      
      $cookieKey = substr(md5($site_id."Web-User"),0,15);
      
      # Start processing
      include_once $snipPath."weblogin/weblogin.common.inc.php";
      include_once ("manager/includes/crypt.class.inc.php");
      
      if ($isPWDActivate || $isPWDReminder || $isLogOut || $isPostBack) {
      	# include the logger class
      	include_once "manager/includes/log.class.inc.php";
      	include_once $snipPath."weblogin/weblogin.processor.inc.php";
      }
      
      include_once $snipPath."weblogin/weblogin.inc.php";
      
      # Return
      return $output;
      


      WebSignup Snippet:
      # WebSignup 1.0
      # Created By Raymond Irving April, 2005
      #::::::::::::::::::::::::::::::::::::::::
      # Usage: 	
      #	Allows a web user to signup for a new web account from the website
      #	This snippet provides a basic set of form fields for the signup form
      #	You can customize this snippet to create your own signup form
      #
      # Params:	
      #
      #	&tpl			- (Optional)
      #		Chunk name or document id to use as a template
      #				  
      #	Note: Templats design:
      #			section 1: signup template
      #			section 2: notification template 
      #
      # Examples:
      #
      #	[[WebSignup? &tpl=`SignupForm`]] 
      
      # Set Snippet Paths 
      $snipPath  = (($modx->insideManager())? "../":"");
      $snipPath .= "assets/snippets/";
      
      # check if inside manager
      if ($m = $modx->insideManager()) {
      	return ''; # don't go any further when inside manager
      }
      
      
      # Snippet customize settings
      $tpl		= isset($tpl)? $tpl:"";
      
      # System settings
      $isPostBack		= count($_POST) && isset($_POST['cmdwebsignup']);
      
      # Start processing
      include_once $snipPath."weblogin/weblogin.common.inc.php";
      include_once $snipPath."weblogin/websignup.inc.php";
      
      # Return
      return $output;
      


      WebChangePwd Snippet:
      # WebChangePwd 1.0
      # Created By Raymond Irving April, 2005
      #::::::::::::::::::::::::::::::::::::::::
      # Usage: 	
      #	Allows a web user to change his/her password from the website
      #
      # Params:	
      #
      #	&tpl			- (Optional)
      #		Chunk name or document id to use as a template
      #				  
      #	Note: Templats design:
      #			section 1: change pwd template
      #			section 2: notification template 
      #
      # Examples:
      #
      #	[[WebChangePwd? &tpl=`ChangePwd`]] 
      
      # Set Snippet Paths 
      $snipPath  = (($modx->insideManager())? "../":"");
      $snipPath .= "assets/snippets/";
      
      # check if inside manager
      if ($m = $modx->insideManager()) {
      	return ''; # don't go any further when inside manager
      }
      
      
      # Snippet customize settings
      $tpl		= isset($tpl)? $tpl:"";
      
      # System settings
      $isPostBack		= count($_POST) && isset($_POST['cmdwebchngpwd']);
      
      # Start processing
      include_once $snipPath."weblogin/weblogin.common.inc.php";
      include_once $snipPath."weblogin/webchangepwd.inc.php";
      
      # Return
      return $output;
      


      (THE CHUNK USED WITH SNIPPETS)
      WebLoginSideBar Chunk:
      <!-- #declare:separator <hr> --> 
      <!-- login form section-->
      <form method="post" name="loginfrm" action="[+action+]" style="margin: 0px; padding: 0px;"> 
      <input type="hidden" value="[+rememberme+]" name="rememberme"> 
      <table border="0" cellspacing="0" cellpadding="0">
      <tr>
      <td>
      <table border="0" cellspacing="0" cellpadding="0">
        <tr>
      	<td><b>User:</b></td>
      	<td><input type="text" name="username" tabindex="1" onkeypress="return webLoginEnter(document.loginfrm.password);" size="5" style="width: 100px;" value="[+username+]" /></td>
        </tr>
        <tr>
      	<td><b>Password:</b></td>
      	<td><input type="password" name="password" tabindex="2" onkeypress="return webLoginEnter(document.loginfrm.cmdweblogin);" size="5" style="width: 100px;" value="" /></td>
        </tr>
        <tr>
      	<td><label for="chkbox" style="cursor:pointer">Remember me:  </label></td>
      	<td>
      	<table width="100%"  border="0" cellspacing="0" cellpadding="0">
      	  <tr>
      		<td valign="top"><input type="checkbox" id="chkbox" name="chkbox" tabindex="4" size="1" value="" [+checkbox+] onClick="webLoginCheckRemember()" /></td>
      		<td align="right">									
      		<input type="submit" value="[+logintext+]" name="cmdweblogin" /></td>
      	  </tr>
      	</table>
      	</td>
        </tr>
        <tr>
      	<td colspan="2"><a href="#" onclick="webLoginShowForm(2);return false;">Forget Password?</a></td>
        </tr>
      </table>
      </td>
      </tr>
      </table>
      </form>
      <hr>
      <!-- log out hyperlink section -->
      <a href='[+action+]'>[+logouttext+]</a>
      <hr>
      <!-- Password reminder form section -->
      <form name="loginreminder" method="post" action="[+action+]" style="margin: 0px; padding: 0px;">
      <input type="hidden" name="txtpwdrem" value="0" />
      <table border="0">
      	<tr>
      	  <td>Enter the email address of your account <br />below to receive your password:</td>
      	</tr>
      	<tr>
      	  <td><input type="text" name="txtwebemail" size="24" /></td>
      	</tr>
      	<tr>
      	  <td align="right"><input type="submit" value="Submit" name="cmdweblogin" />
      	  <input type="reset" value="Cancel" name="cmdcancel" onclick="webLoginShowForm(1);" /></td>
      	</tr>
        </table>
      </form>
      


      I hope it helps smiley, but as Ryan said above, these snippets are packaged with the Tech Preview 1 files, and can be had from http://vertexworks.com/forums/viewtopic.php?t=196.

      Best regards,

      -zi smiley
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I'm in the process of creating a file upload/download manager (actually, more of a document management system) using the weblogins to determine who can add/delete documents (real .doc documents, not modx documents!) and who can check in/check out documents, all on the front-end. Sort of like SourceSafe.

        Certain web users will get sent to a file management page allowing them to upload, set permissions on (using a multiple select drop-down with web user names that belong to the correct web group), download, and delete files that they "own".

        Other web users will be sent to a page where they will see the files available to them and be able to check out/check in these files, according to the permissions the "owner" set on the files. If it's already out, it will say so and not let anyone else check it out.

        There will also be a rudimentary logging feature, to show who last checked in the file and the date, and it will send email to the "owner", with the name of whoever checked it out or in, whenever a file gets checked in or out.

        For this particular custom design, I'm leaving creation of the web users in the Manager. Otherwise it could be allowed in the front end by using the web user registration snippet.
          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
          • 25663 MODX Staff
          • 12,272 Posts
          Susan, is that something you'll be sharing when done? wink
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Yes, I'm making it as generic as possible, and will package it with instructions and the .sql file it needs. The code in the .php files is also heavily commented (mostly because I can't remember why I did that ten minutes after I did it!). Then I'll hack my application of it for my client's requirements.

            The power went out in town about 4 AM this morning, loudly, as all the transformers in town blew out their circuit breakers three times in a row for no discernable reason before giving up entirely, so I spent the morning looking through the tutorials and articles and scripts I've printed out over the last four or five years, and found this one called "Cracking the Vault"; in two parts, it came from DevShed about four years ago. Once power came back on around noon, I got busy on it. It should actually work in a couple of days; I'm no speed coder, and I'm adding error handling and a few other odd bells and whistles as I go along.
              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
              • 25663 MODX Staff
              • 12,272 Posts
              Thanks Susan... that sounds wonderful! laugh
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 14267
                • 113 Posts
                Thanks so much, Zi. My bad for not seeing those files in the package. Such nice people around here.... :wink:
                  • 33337
                  • 3,975 Posts
                  Thanks so much, Zi. My bad for not seeing those files in the package. Such nice people around here.... :wink:

                  You are most welcome jlarson cool

                  Have a great day !

                  -zi smiley
                    Zaigham R - MODX Professional | Skype | Email | Twitter

                    Digging the interwebs for #MODX gems and bringing it to you. modx.link
                    • 32963
                    • 1,732 Posts
                    This sounds very cool Susan.

                    Keep up the good work
                      xWisdom
                      www.xwisdomhtml.com
                      The fear of the Lord is the beginning of wisdom:
                      MODx Co-Founder - Create and do more with less.
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      I spent most of the day playing with javascript tabbing packages; finally found a fairly recent one that's free and I really like; tabtastic - http://phrogz.net/JS/Tabtastic/index.html.

                      Now instead of having several pages, I am just creating one page for file managers and one page for file users.

                      The manager page will have tabs; the user page only needs one page to list their available files and enable checkout/checkin.

                      I'll use something like the faq snippet on the tab that lists available files, and when you click on the file you'll get the info and various options (delete, edit comment, edit permissions) for that file.

                      [later]
                      Well, been fighting the good fight all day...one line of code at a time, it seems like! Anyway, I found a really nice script for handling selecting items from a multiple select list populated from the database:
                      http://www.mredkj.com/tutorials/tutorial_mixed2b.html
                      Makes a very nice form for selecting web users you want to give file access permissions to! I had to add a javascript function for generating a string to pass via POST, in a hidden input field, then explode() it to feed it into the files_perms table; I'm sure a javascript pro could do a better job of it, but it works!

                      Now just to set up the actual download/checkout/checkin functions and it's all set.
                        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