Revision [9935]

This is an old revision of UserRegistration made by NilsLindenberg on 2005-07-11 09:48:05.

 

UserRegistration


 


Is there an easy way to not allow registration? I would like to have it so that I can control the registration process, not let just anyone sign-up.
--BooYa

A nice contribution Nils. If you want to go further with fiddling with the code for registration, I've thought it would be useful if there was a feature that required a password from an administrator to be able to register so that if you were going to register you put in your user info (as now) and a password you've obtained from the admin that allows you to register....for instance, in this way a teacher could set up a wikki with registration "on" and send a note to all of the parents with the registration password so that they could register....outsiders couldn't register, only those with the registration key. Possibly a quite useful feature to many potential user groups. -- GmBowen

Last edited by NilsLindenberg:
added whole usersettings.php
Mon, 11 Jul 2005 09:48 UTC [diff]


Additions to the config

additions to wikkaconfig.php

'allow_registration' => '2',
'registercode' => 'helloWorld',


allow_registration sets the mode:
0 - no registration possible
1 - registration "without limits"
2 - password required

registercode takes the password

changes in usersettings


A) If you haven't modified your usersettings.php, you can replace it with the following version:

  1. <?php
  2. if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "logout"))
  3. {
  4.     $this->LogoutUser();
  5.     $this->Redirect($this->href(), "You are now logged out.");
  6. }
  7. else if ($user = $this->GetUser())
  8. {
  9.    
  10.     // is user trying to update?
  11.     if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "update"))
  12.     {
  13.         $this->Query("update ".$this->config["table_prefix"]."users set ".
  14.             "email = '".mysql_real_escape_string($_POST["email"])."', ".
  15.             "doubleclickedit = '".mysql_real_escape_string($_POST["doubleclickedit"])."', ".
  16.             "show_comments = '".mysql_real_escape_string($_POST["show_comments"])."', ".
  17.             "revisioncount = '".mysql_real_escape_string($_POST["revisioncount"])."', ".
  18.             "changescount = '".mysql_real_escape_string($_POST["changescount"])."' ".
  19.             "where name = '".$user["name"]."' limit 1");
  20.        
  21.         $this->SetUser($this->LoadUser($user["name"]));
  22.        
  23.         // forward
  24.         $this->Redirect($this->href(), "User settings stored!");
  25.     }
  26.    
  27.     if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "changepass"))
  28.     {
  29.             // check password
  30.             $password = $_POST["password"];        
  31.                         if (preg_match("/ /", $password)) $passerror = "Sorry, blanks are not permitted in the password.";
  32.             else if (strlen($password) < 5) $passerror = "Tsk tsk, the password is much too short...";
  33.             else if (($user["password"] == md5($_POST["oldpass"])) || ($user["password"] == $_POST["oldpass"]))
  34.             {
  35.                 $this->Query("update ".$this->config["table_prefix"]."users set "."password = md5('".mysql_real_escape_string($password)."') "."where name = '".$user["name"]."'");            
  36.                 $user["password"]=md5($password);
  37.                 $this->SetUser($user);
  38.                 $this->Redirect($this->href(), "Password changed.");
  39.             }
  40.             else
  41.             {
  42.                 $passerror = "The old password you entered is wrong.";
  43.             }
  44.     }
  45.  
  46.     print "<script type=\"text/javascript\"><!-- \nfunction hov(loc,cls){ \n    if(loc.className) loc.className=cls;\n}\n //-->\n</script>\n";
  47.     // user is logged in; display config form
  48.     print($this->FormOpen());
  49.     ?>
  50.     <input type="hidden" name="action" value="update" />
  51.     <table>
  52.         <tr>
  53.             <td align="right"></td>
  54.             <td>Hello, <?php echo $this->Link($user["name"]) ?>!</td>
  55.         </tr>
  56.         <tr>
  57.             <td align="right">Your email address:</td>
  58.             <td><input name="email" value="<?php echo $this->htmlspecialchars_ent($user["email"]) ?>" size="40" /></td>
  59.         </tr>
  60.         <tr>
  61.             <td align="right">Doubleclick Editing:</td>
  62.             <td><input type="hidden" name="doubleclickedit" value="N"><input type="checkbox" name="doubleclickedit" value="Y" <?php echo $user["doubleclickedit"] == "Y" ? "checked=\"checked\"" : "" ?> /></td>
  63.         </tr>
  64.         <tr>
  65.             <td align="right">Show comments by default:</td>
  66.             <td><input type="hidden" name="show_comments" value="N"><input type="checkbox" name="show_comments" value="Y" <?php echo $user["show_comments"] == "Y" ? "checked=\"checked\"" : "" ?> /></td>
  67.         </tr>
  68.         <tr>
  69.             <td align="right">RecentChanges display limit:</td>
  70.             <td><input name="changescount" value="<?php echo $this->htmlspecialchars_ent($user["changescount"]) ?>" size="40" /></td>
  71.         </tr>
  72.         <tr>
  73.             <td align="right">Page revisions list limit:</td>
  74.             <td><input name="revisioncount" value="<?php echo $this->htmlspecialchars_ent($user["revisioncount"]) ?>" size="40" /></td>
  75.         </tr>
  76.         <tr>
  77.             <td></td>
  78.             <td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onclick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
  79.         </tr>
  80.     </table>
  81.     <?php
  82.     print($this->FormClose());
  83.  
  84.     print($this->FormOpen());
  85.     ?>
  86.     <input type="hidden" name="action" value="changepass" />
  87.     <table>
  88.         <tr>
  89.             <td align="left"><b>Change your password:</b></td>
  90.             <td><br /><br />&nbsp;</td>
  91.         </tr>
  92.         <?php
  93.         if (isset($passerror))
  94.         {
  95.             print("<tr><td></td><td><div class=\"error\">".$this->Format($passerror)."</div></td></tr>\n");
  96.         }
  97.         ?>
  98.         <tr>
  99.             <td align="left">Your current password:</td>
  100.             <td><input type="password" name="oldpass" size="40" /></td>
  101.         </tr>
  102.         <tr>
  103.             <td align="left">Your new password:</td>
  104.             <td><input type="password" name="password" size="40" /></td>
  105.         </tr>
  106.         <tr>
  107.             <td></td>
  108.             <td><input type="submit" value="Change" size="40" /></td>
  109.  
  110.         </tr>
  111.     </table>
  112.     <br />
  113.     See a list of pages you own (<a href="<?php echo $this->href("", "MyPages"); ?>">MyPages</a>) and pages you've edited (<a href="<?php echo $this->href("", "MyChanges"); ?>">MyChanges</a>).<br />
  114.     <?php
  115.     print($this->FormClose());
  116. }
  117. else
  118. {
  119.     // user is not logged in
  120.  
  121.     print "<script type=\"text/javascript\"><!-- \nfunction hov(loc,cls){ \n    if(loc.className) loc.className=cls;\n}\n //-->\n</script>\n";
  122.  
  123.     // is user trying to log in or register?
  124.     $register = $this->GetConfigValue('allow_registration');
  125.     if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "login"))
  126.     {
  127.         // if user name already exists, check password
  128.         if ($existingUser = $this->LoadUser($_POST["name"]))
  129.         {
  130.             // check password
  131.             if ($existingUser["password"] == md5($_POST["password"]))
  132.             {
  133.                 $this->SetUser($existingUser);
  134.                 $this->Redirect($this->href());
  135.             }
  136.             else
  137.             {
  138.                 $error = "Wrong password!";
  139.             }
  140.         }
  141.         // otherwise, create new account when registration is possible without limits (1) or the password matches (2)
  142.             else if ($register == '1' || ($register == '2' && $_REQUEST['code_input'] ==  $this->GetConfigValue('registercode')))
  143.         {
  144.             $name = trim($_POST["name"]);
  145.             $email = trim($_POST["email"]);
  146.             $password = $_POST["password"];
  147.             $confpassword = $_POST["confpassword"];
  148.  
  149.             // check if name is WikiName style
  150.             if ($this->ExistsPage($name)) $error = 'Sorry, this ""WikiName"" is reserved for a page. Please choose a different name.';
  151.             elseif (!$this->IsWikiName($name)) $error = "User name must be WikiName formatted!";
  152.             elseif (!$email) $error = "You must specify an email address.";
  153.             elseif (!preg_match("/^.+?\@.+?\..+$/", $email)) $error = "That doesn't quite look like an email address.";
  154.             elseif ($confpassword != $password) $error = "Passwords didn't match.";
  155.             elseif (preg_match("/ /", $password)) $error = "Spaces aren't allowed in passwords.";
  156.             elseif (strlen($password) < 5) $error = "Password too short.";
  157.             else
  158.             {
  159.                 $this->Query("insert into ".$this->config["table_prefix"]."users set ".
  160.                     "signuptime = now(), ".
  161.                     "name = '".mysql_real_escape_string($name)."', ".
  162.                     "email = '".mysql_real_escape_string($email)."', ".
  163.                     "password = md5('".mysql_real_escape_string($_POST["password"])."')");
  164.  
  165.                 // log in
  166.                 $this->SetUser($this->LoadUser($name));
  167.  
  168.                 // forward
  169.                 $this->Redirect($this->href());
  170.             }
  171.         }
  172.             else
  173.             {
  174.                   $error = "Sorry, the register-code you entered was not correct!";
  175.             }
  176.     }
  177.     elseif  (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "updatepass"))
  178.     {
  179.             // check if name is WikkiName style
  180.             $name = trim($_POST["yourname"]);
  181.             if (!$this->IsWikiName($name)) $newerror = "You have entered an incorrect or non-existent wikiname. The wikiname must be written in wikistyle, e.g: \"\"WikkaName.\"\"";
  182.    
  183.             // if user name already exists, check password
  184.             elseif ($existingUser = $this->LoadUser($_POST["yourname"]))  
  185.             // updatepassword
  186.                 if ($existingUser["password"] == $_POST["temppassword"])
  187.                 {
  188.                         $this->SetUser($existingUser, $_POST["remember"]);
  189.                         $this->Redirect($this->href());
  190.                 }
  191.                 else
  192.                {
  193.                         $newerror = "Sorry, you entered the wrong password.";
  194.                }
  195.     }
  196.    
  197.     print($this->FormOpen());
  198.     ?>
  199.     <input type="hidden" name="action" value="login" />
  200.     <table>
  201.         <tr>
  202.             <td align="right"></td>
  203.             <td><?php echo $this->Format("If you're already a registered user, log in here!"); ?></td>
  204.         </tr>
  205.         <?php
  206.         if (isset($error))
  207.         {
  208.             print("<tr><td></td><td><div class=\"error\">".$this->Format($error)."</div></td></tr>\n");
  209.         }
  210.         ?>
  211.         <tr>
  212.             <td align="right">Your WikiName:</td>
  213.             <td><input name="name" size="40" value="<?php if (isset($name)) echo $name; ?>" /></td>
  214.         </tr>
  215.         <tr>
  216.             <td align="right">Password (5+ chars):</td>
  217.             <td><input type="password" name="password" size="40" /></td>
  218.         </tr>
  219.         <tr>
  220.             <td></td>
  221.             <td><input type="submit" value="Login" size="40" /></td>
  222.         </tr>
  223.         <?php
  224.             $register = $this->GetConfigValue('allow_registration');
  225.             if ($register == '1' || $register == '2')
  226.             {
  227.                 ?>
  228.                 <tr>
  229.                     <td align="right"></td>
  230.                     <td width="500">Stuff you only need to fill in when you are logging in for the first time (and thus signing up as a new user on this site)</td>
  231.                 </tr>
  232.                 <tr>
  233.                      <td align='right'>Confirm password:</td>
  234.                      <td><input type='password' name='confpassword' size='40' /></td>
  235.                 </tr>
  236.                 <tr>
  237.                     <td align='right'>Email address:</td>
  238.                     <td><input name='email' size='40' /></td>
  239.                 </tr>
  240.                 <?php
  241.                      if ($register == '2')
  242.                      {
  243.                 ?>
  244.                            <tr>
  245.                                <td align='right'>Register Code:</td><td><input type='text' size='20' name='code_input' /></td>
  246.                            </tr>
  247.                 <?php
  248.                      }
  249.                 ?>
  250.                 <tr>
  251.                 <td></td>
  252.                 <td><input type='submit' value='Register' size='40' /></td>
  253.                 </tr>
  254.             <?php
  255.             }
  256.             ?>
  257.     </table>
  258.     <?php
  259.     print($this->FormClose());
  260.     print($this->FormOpen());
  261.     ?>
  262.     <input type="hidden" name="action" value="updatepass" />
  263.     <table>
  264.         <tr>
  265.                 <td colspan="2"><br /><hr /><h4>Forget your password?</h4></td><td></td>
  266.             </tr>
  267.         <tr>
  268.             <td align="left"></td>
  269.             <td>Log in here with the temporary password. <br />If you need a temporary password, click <?php echo $this->Format("[[PasswordForgotten here]]") ?></td>
  270.         </tr>
  271.             <?php  
  272.             if (isset($newerror))
  273.             {  
  274.                 print("<tr><td></td><td><div class=\"error\">".$this->Format($newerror)."</div></td></tr>\n");
  275.         }  
  276.             ?>
  277.         <tr>
  278.             <td align="left">Your WikiName:</td>
  279.             <td><input name="yourname" value="<?php if (isset($_POST["yourname"])) echo $_POST["yourname"]; ?>" size="40" /></td>
  280.         </tr>
  281.         <tr>
  282.             <td align="left">Your temp password:</td>
  283.             <td><input name="temppassword" size="40" /></td>
  284.         </tr>
  285.         <tr>
  286.             <td></td>
  287.             <td><input type="submit" value="Login" size="40" /></td>
  288.         </tr>
  289.        </table>
  290.        <?php
  291.        print($this->FormClose());
  292. }
  293. ?>


B) Or apply the following changes to actions/usersettings.php:

line 123
        // is user trying to log in or register?
        $register = $this->GetConfigValue('allow_registration');
        if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "login"))


line 140
                // otherwise, create new account when registration is possible without limits (1) or the password matches (2)
                else if ($register == '1' || ($register == '2' && $_REQUEST['code_input'] ==  $this->GetConfigValue('registercode')))


line 169
                else
                {
                    $error = "Sorry, the register-code you entered was not correct!";
                }


lines 218-233
        <?php
            $register = $this->GetConfigValue('allow_registration');
            if ($register == '1' || $register == '2')
            {
                ?>
                <tr>
                    <td align="right"></td>
                    <td width="500">Stuff you only need to fill in when you are logging in for the first time (and thus signing up as a new user on this site)</td>
                </tr>
                <tr>
                     <td align='right'>Confirm password:</td>
                     <td><input type='password' name='confpassword' size='40' /></td>
                </tr>
                <tr>
                    <td align='right'>Email address:</td>
                    <td><input name='email' size='40' /></td>
                </tr>
                <?php
                     if ($register == '2')
                     {
                ?>
                           <tr>
                               <td align='right'>Register Code:</td><td><input type='text' size='20' name='code_input' /></td>
                           </tr>
                <?php
                     }
                ?>
                <tr>
                <td></td>
                <td><input type='submit' value='Register' size='40' /></td>
                </tr>
            <?php
            }
            ?>



CategoryDevelopmentActions CategoryDevelopmentUserAccount
There are 33 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki