resend-activation.php (3991B)
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 //Forms posted 11 if(!empty($_POST) && $emailActivation) 12 { 13 $email = $_POST["email"]; 14 $username = $_POST["username"]; 15 16 //Perform some validation 17 //Feel free to edit / change as required 18 if(trim($email) == "") 19 { 20 $errors[] = lang("ACCOUNT_SPECIFY_EMAIL"); 21 } 22 //Check to ensure email is in the correct format / in the db 23 else if(!isValidEmail($email) || !emailExists($email)) 24 { 25 $errors[] = lang("ACCOUNT_INVALID_EMAIL"); 26 } 27 28 if(trim($username) == "") 29 { 30 $errors[] = lang("ACCOUNT_SPECIFY_USERNAME"); 31 } 32 else if(!usernameExists($username)) 33 { 34 $errors[] = lang("ACCOUNT_INVALID_USERNAME"); 35 } 36 37 if(count($errors) == 0) 38 { 39 //Check that the username / email are associated to the same account 40 if(!emailUsernameLinked($email,$username)) 41 { 42 $errors[] = lang("ACCOUNT_USER_OR_EMAIL_INVALID"); 43 } 44 else 45 { 46 $userdetails = fetchUserDetails($username); 47 48 //See if the user's account is activation 49 if($userdetails["active"]==1) 50 { 51 $errors[] = lang("ACCOUNT_ALREADY_ACTIVE"); 52 } 53 else 54 { 55 if ($resend_activation_threshold == 0) { 56 $hours_diff = 0; 57 } 58 else { 59 $last_request = $userdetails["last_activation_request"]; 60 $hours_diff = round((time()-$last_request) / (3600*$resend_activation_threshold),0); 61 } 62 63 if($resend_activation_threshold!=0 && $hours_diff <= $resend_activation_threshold) 64 { 65 $errors[] = lang("ACCOUNT_LINK_ALREADY_SENT",array($resend_activation_threshold)); 66 } 67 else 68 { 69 //For security create a new activation url; 70 $new_activation_token = generateActivationToken(); 71 72 if(!updateLastActivationRequest($new_activation_token,$username,$email)) 73 { 74 $errors[] = lang("SQL_ERROR"); 75 } 76 else 77 { 78 $mail = new userCakeMail(); 79 80 $activation_url = $websiteUrl."activate-account.php?token=".$new_activation_token; 81 82 //Setup our custom hooks 83 $hooks = array( 84 "searchStrs" => array("#ACTIVATION-URL","#USERNAME#"), 85 "subjectStrs" => array($activation_url,$userdetails["display_name"]) 86 ); 87 88 if(!$mail->newTemplateMsg("resend-activation.txt",$hooks)) 89 { 90 $errors[] = lang("MAIL_TEMPLATE_BUILD_ERROR"); 91 } 92 else 93 { 94 if(!$mail->sendMail($userdetails["email"],"Activate your ".$websiteName." Account")) 95 { 96 $errors[] = lang("MAIL_ERROR"); 97 } 98 else 99 { 100 //Success, user details have been updated in the db now mail this information out. 101 $successes[] = lang("ACCOUNT_NEW_ACTIVATION_SENT"); 102 } 103 } 104 } 105 } 106 } 107 } 108 } 109 } 110 111 //Prevent the user visiting the logged in page if he/she is already logged in 112 if(isUserLoggedIn()) { header("Location: account.php"); die(); } 113 114 require_once("models/header.php"); 115 116 echo " 117 <body> 118 <div id='wrapper'> 119 <div id='top'><div id='logo'></div></div> 120 <div id='content'> 121 <h1>UserCake</h1> 122 <h2>Resend Activation</h2> 123 <div id='left-nav'>"; 124 125 include("left-nav.php"); 126 127 echo " 128 </div> 129 <div id='main'>"; 130 131 echo resultBlock($errors,$successes); 132 133 echo "<div id='regbox'>"; 134 135 //Show disabled if email activation not required 136 if(!$emailActivation) 137 { 138 echo lang("FEATURE_DISABLED"); 139 } 140 else 141 { 142 echo "<form name='resendActivation' action='".$_SERVER['PHP_SELF']."' method='post'> 143 <p> 144 <label>Username:</label> 145 <input type='text' name='username' /> 146 </p> 147 <p> 148 <label>Email:</label> 149 <input type='text' name='email' /> 150 </p> 151 <p> 152 <label> </label> 153 <input type='submit' value='Submit' class='submit' /> 154 </p> 155 </form>"; 156 } 157 158 echo " 159 </div> 160 </div> 161 <div id='bottom'></div> 162 </div> 163 </body> 164 </html>"; 165 166 ?>