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

UCC git Repository :: git.ucc.asn.au