register.php (3436B)
1 <?php 2 /* 3 UserCake Version: 2.0.2 4 http://usercake.com 5 */ 6 7 require_once("models/config.php"); 8 if (!securePage($_SERVER['PHP_SELF'])){die();} 9 10 //Prevent the user visiting the logged in page if he/she is already logged in 11 if(isUserLoggedIn()) { header("Location: account.php"); die(); } 12 13 //Forms posted 14 if(!empty($_POST)) 15 { 16 $errors = array(); 17 $email = trim($_POST["email"]); 18 $username = trim($_POST["username"]); 19 $displayname = trim($_POST["displayname"]); 20 $password = trim($_POST["password"]); 21 $confirm_pass = trim($_POST["passwordc"]); 22 $captcha = md5($_POST["captcha"]); 23 24 25 if ($captcha != $_SESSION['captcha']) 26 { 27 $errors[] = lang("CAPTCHA_FAIL"); 28 } 29 if(minMaxRange(5,25,$username)) 30 { 31 $errors[] = lang("ACCOUNT_USER_CHAR_LIMIT",array(5,25)); 32 } 33 if(!ctype_alnum($username)){ 34 $errors[] = lang("ACCOUNT_USER_INVALID_CHARACTERS"); 35 } 36 if(minMaxRange(5,25,$displayname)) 37 { 38 $errors[] = lang("ACCOUNT_DISPLAY_CHAR_LIMIT",array(5,25)); 39 } 40 if(!ctype_alnum($displayname)){ 41 $errors[] = lang("ACCOUNT_DISPLAY_INVALID_CHARACTERS"); 42 } 43 if(minMaxRange(8,50,$password) && minMaxRange(8,50,$confirm_pass)) 44 { 45 $errors[] = lang("ACCOUNT_PASS_CHAR_LIMIT",array(8,50)); 46 } 47 else if($password != $confirm_pass) 48 { 49 $errors[] = lang("ACCOUNT_PASS_MISMATCH"); 50 } 51 if(!isValidEmail($email)) 52 { 53 $errors[] = lang("ACCOUNT_INVALID_EMAIL"); 54 } 55 //End data validation 56 if(count($errors) == 0) 57 { 58 //Construct a user object 59 $user = new User($username,$displayname,$password,$email); 60 61 //Checking this flag tells us whether there were any errors such as possible data duplication occured 62 if(!$user->status) 63 { 64 if($user->username_taken) $errors[] = lang("ACCOUNT_USERNAME_IN_USE",array($username)); 65 if($user->displayname_taken) $errors[] = lang("ACCOUNT_DISPLAYNAME_IN_USE",array($displayname)); 66 if($user->email_taken) $errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email)); 67 } 68 else 69 { 70 //Attempt to add the user to the database, carry out finishing tasks like emailing the user (if required) 71 if(!$user->userCakeAddUser()) 72 { 73 if($user->mail_failure) $errors[] = lang("MAIL_ERROR"); 74 if($user->sql_failure) $errors[] = lang("SQL_ERROR"); 75 } 76 } 77 } 78 if(count($errors) == 0) { 79 $successes[] = $user->success; 80 } 81 } 82 83 require_once("models/header.php"); 84 echo " 85 <body> 86 <div id='wrapper'> 87 <div id='top'><div id='logo'></div></div> 88 <div id='content'> 89 <h1>UserCake</h1> 90 <h2>Register</h2> 91 92 <div id='left-nav'>"; 93 include("left-nav.php"); 94 echo " 95 </div> 96 97 <div id='main'>"; 98 99 echo resultBlock($errors,$successes); 100 101 echo " 102 <div id='regbox'> 103 <form name='newUser' action='".$_SERVER['PHP_SELF']."' method='post'> 104 105 <p> 106 <label>User Name:</label> 107 <input type='text' name='username' /> 108 </p> 109 <p> 110 <label>Display Name:</label> 111 <input type='text' name='displayname' /> 112 </p> 113 <p> 114 <label>Password:</label> 115 <input type='password' name='password' /> 116 </p> 117 <p> 118 <label>Confirm:</label> 119 <input type='password' name='passwordc' /> 120 </p> 121 <p> 122 <label>Email:</label> 123 <input type='text' name='email' /> 124 </p> 125 <p> 126 <label>Security Code:</label> 127 <img src='models/captcha.php'> 128 </p> 129 <label>Enter Security Code:</label> 130 <input name='captcha' type='text'> 131 </p> 132 <label> <br> 133 <input type='submit' value='Register'/> 134 </p> 135 136 </form> 137 </div> 138 139 </div> 140 <div id='bottom'></div> 141 </div> 142 </body> 143 </html>"; 144 ?>