Revision [13955]

This is an old revision of UserRegistration made by JavaWoman on 2006-04-27 06:59:59.

 

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 JavaWoman:
Updated code - see comment below it
Thu, 27 Apr 2006 06:59 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.         </tr>
  110.     </table>
  111.     <br />
  112.     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 />
  113.     <?php
  114.     print($this->FormClose());
  115. }
  116. else
  117. {
  118.     // user is not logged in
  119.  
  120.     print "<script type=\"text/javascript\"><!-- \nfunction hov(loc,cls){ \n    if(loc.className) loc.className=cls;\n}\n //-->\n</script>\n";
  121.  
  122.     // is user trying to log in or register?
  123.     $register = $this->GetConfigValue('allow_registration');
  124.     if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "login"))
  125.     {
  126.         // if user name already exists, check password
  127.         if ($existingUser = $this->LoadUser($_POST["name"]))
  128.         {
  129.             // check password
  130.             if ($existingUser["password"] == md5($_POST["password"]))
  131.             {
  132.                 $this->SetUser($existingUser);
  133.                 $this->Redirect($this->href());
  134.             }
  135.             else
  136.             {
  137.                 $error = "Wrong password!";
  138.             }
  139.         }
  140.         // otherwise, create new account when registration is possible without limits (1) or the password matches (2)
  141.         elseif ($register == '1' || ($register == '2' && $_REQUEST['code_input'] ==  $this->GetConfigValue('registercode')))
  142.         {
  143.             $name = trim($_POST["name"]);
  144.             $email = trim($_POST["email"]);
  145.             $password = $_POST["password"];
  146.             $confpassword = $_POST["confpassword"];
  147.  
  148.             // check if name is WikiName style
  149.             if ($this->ExistsPage($name)) $error = 'Sorry, this ""WikiName"" is reserved for a page. Please choose a different name.';
  150.             elseif (!$this->IsWikiName($name)) $error = "User name must be WikiName formatted!";
  151.             elseif (!$email) $error = "You must specify an email address.";
  152.             elseif (!preg_match("/^.+?\@.+?\..+$/", $email)) $error = "That doesn't quite look like an email address.";
  153.             elseif ($confpassword != $password) $error = "Passwords didn't match.";
  154.             elseif (preg_match("/ /", $password)) $error = "Spaces aren't allowed in passwords.";
  155.             elseif (strlen($password) < 5) $error = "Password too short.";
  156.             else
  157.             {
  158.                 $this->Query("insert into ".$this->config["table_prefix"]."users set ".
  159.                     "signuptime = now(), ".
  160.                     "name = '".mysql_real_escape_string($name)."', ".
  161.                     "email = '".mysql_real_escape_string($email)."', ".
  162.                     "password = md5('".mysql_real_escape_string($_POST["password"])."')");
  163.  
  164.                 // log in
  165.                 $this->SetUser($this->LoadUser($name));
  166.  
  167.                 // forward
  168.                 $this->Redirect($this->href());
  169.             }
  170.         }
  171.         else
  172.         {
  173.             $error = "Sorry, the register-code you entered was not correct!";
  174.         }
  175.     }
  176.     elseif  (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "updatepass"))
  177.     {
  178.         // check if name is WikkiName style
  179.         $name = trim($_POST["yourname"]);
  180.         if (!$this->IsWikiName($name)) $newerror = "You have entered an incorrect or non-existent wikiname. The wikiname must be written in wikistyle, e.g: \"\"WikkaName.\"\"";
  181.  
  182.         // if user name already exists, check password
  183.         elseif ($existingUser = $this->LoadUser($_POST["yourname"]))
  184.         {
  185.             if ($existingUser["password"] == $_POST["temppassword"])
  186.             {
  187.                 // update password
  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.  
  198.     print($this->FormOpen());
  199.     ?>
  200.     <input type="hidden" name="action" value="login" />
  201.     <table>
  202.         <tr>
  203.             <td align="right"></td>
  204.             <td><?php echo $this->Format("If you're already a registered user, log in here!"); ?></td>
  205.         </tr>
  206.         <?php
  207.         if (isset($error))
  208.         {
  209.             print("<tr><td></td><td><div class=\"error\">".$this->Format($error)."</div></td></tr>\n");
  210.         }
  211.         ?>
  212.         <tr>
  213.             <td align="right">Your WikiName:</td>
  214.             <td><input name="name" size="40" value="<?php if (isset($name)) echo $name; ?>" /></td>
  215.         </tr>
  216.         <tr>
  217.             <td align="right">Password (5+ chars):</td>
  218.             <td><input type="password" name="password" size="40" /></td>
  219.         </tr>
  220.         <tr>
  221.             <td></td>
  222.             <td><input type="submit" value="Login" size="40" /></td>
  223.         </tr>
  224.         <?php
  225.             $register = $this->GetConfigValue('allow_registration');
  226.             if ($register == '1' || $register == '2')
  227.             {
  228.         ?>
  229.         <tr>
  230.             <td align="right"></td>
  231.             <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>
  232.         </tr>
  233.         <tr>
  234.             <td align='right'>Confirm password:</td>
  235.             <td><input type='password' name='confpassword' size='40' /></td>
  236.         </tr>
  237.         <tr>
  238.             <td align='right'>Email address:</td>
  239.             <td><input name='email' size='40' /></td>
  240.         </tr>
  241.             <?php
  242.                 if ($register == '2')
  243.                 {
  244.             ?>
  245.         <tr>
  246.             <td align='right'>Register Code:</td>
  247.             <td><input type='text' size='20' name='code_input' /></td>
  248.         </tr>
  249.             <?php
  250.                 }
  251.             ?>
  252.         <tr>
  253.             <td></td>
  254.             <td><input type='submit' value='Register' size='40' /></td>
  255.         </tr>
  256.         <?php
  257.             }
  258.         ?>
  259.     </table>
  260.     <?php
  261.     print($this->FormClose());
  262.  
  263.     print($this->FormOpen());
  264.     ?>
  265.     <input type="hidden" name="action" value="updatepass" />
  266.     <table>
  267.         <tr>
  268.             <td colspan="2"><br /><hr /><h4>Forget your password?</h4></td><td></td>
  269.         </tr>
  270.         <tr>
  271.             <td align="left"></td>
  272.             <td>Log in here with the temporary password. <br />If you need a temporary password, click <?php echo $this->Format("[[PasswordForgotten here]]") ?></td>
  273.         </tr>
  274.     <?php
  275.     if (isset($newerror))
  276.     {
  277.         print("<tr><td></td><td><div class=\"error\">".$this->Format($newerror)."</div></td></tr>\n");
  278.     }
  279.     ?>
  280.         <tr>
  281.             <td align="left">Your WikiName:</td>
  282.             <td><input name="yourname" value="<?php if (isset($_POST["yourname"])) echo $_POST["yourname"]; ?>" size="40" /></td>
  283.         </tr>
  284.         <tr>
  285.             <td align="left">Your temp password:</td>
  286.             <td><input name="temppassword" size="40" /></td>
  287.         </tr>
  288.         <tr>
  289.             <td></td>
  290.             <td><input type="submit" value="Login" size="40" /></td>
  291.         </tr>
  292.     </table>
  293.     <?php
  294.     print($this->FormClose());
  295. }
  296. ?>



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