Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.07 KB | None | 0 0
  1. <?php
  2. if (!defined('init_executes'))
  3. {
  4. header('HTTP/1.0 404 not found');
  5. exit;
  6. }
  7.  
  8. //setup new instance of multiple errors
  9. $ERRORS->NewInstance('register');
  10.  
  11. //load the register module
  12. $CORE->load_CoreModule('accounts.register');
  13. $CORE->load_CoreModule('raf');
  14. $CORE->load_CoreModule('email.reservation');
  15. $CORE->load_CoreModule('text.captcha');
  16.  
  17. $raf = new RAF();
  18. $captcha = new TextCaptcha();
  19.  
  20. //Define the variables
  21. $username = isset($_POST['username']) ? $_POST['username'] : false;
  22.  
  23. $displayName = isset($_POST['displayname']) ? $_POST['displayname'] : false;
  24.  
  25. $password = isset($_POST['password']) ? $_POST['password'] : false;
  26. $password2 = isset($_POST['password2']) ? $_POST['password2'] : false;
  27.  
  28. $email = isset($_POST['email']) ? $_POST['email'] : false;
  29.  
  30. $birthdayMonth = isset($_POST['birthday']['month']) ? $_POST['birthday']['month'] : false;
  31. $birthdayDay = isset($_POST['birthday']['day']) ? $_POST['birthday']['day'] : false;
  32. $birthdayYear = isset($_POST['birthday']['year']) ? $_POST['birthday']['year'] : false;
  33.  
  34. $country = isset($_POST['country']) ? $_POST['country'] : false;
  35.  
  36. $secretQuestion = isset($_POST['secretQuestion']) ? (int)$_POST['secretQuestion'] : false;
  37. $secretAnswer = isset($_POST['secretAnswer']) ? $_POST['secretAnswer'] : false;
  38.  
  39. $rafHash = isset($_POST['raf']) ? $_POST['raf'] : false;
  40. $gender = isset($_POST['gender']) ? $_POST['gender'] : false;
  41.  
  42. //missing inputs check
  43. ######################################
  44. ######## USERNAME CHECK ##############
  45. if ($usernameError = AccountsRegister::checkUsername($username))
  46. {
  47. $ERRORS->Add($usernameError);
  48. }
  49.  
  50. $username = trim($username);
  51.  
  52. ######################################
  53. ###### DISPLAY NAME CHECK ############
  54. if ($displaynameError = AccountsRegister::checkDisplayname($displayName))
  55. {
  56. $ERRORS->Add($displaynameError);
  57. }
  58.  
  59. ######################################
  60. ######## PASSWORD CHECK ##############
  61. if ($passwordError = AccountsRegister::checkPassword($password, $password2))
  62. {
  63. $ERRORS->Add($passwordError);
  64. }
  65.  
  66. $password = trim($password);
  67.  
  68. ######################################
  69. ######### EMAIL CHECK ################
  70. if ($emailError = AccountsRegister::checkEmail($email))
  71. {
  72. $ERRORS->Add($emailError);
  73. }
  74. else
  75. {
  76. //check for reservation
  77. if (EmailReservations::IsReserved(array('email' => $email)) === true)
  78. {
  79. $ERRORS->Add('The e-mail address is reserved.');
  80. }
  81. }
  82.  
  83. $email = trim($email);
  84.  
  85. ######################################
  86. ######### BIRTHDAY Check #############
  87. //validate the Month
  88. if ($birthdayMonthError = AccountsRegister::checkBirthdayMonth($birthdayMonth))
  89. {
  90. $ERRORS->Add($birthdayMonthError);
  91. }
  92.  
  93. //validate the Day
  94. if ($birthdayDayError = AccountsRegister::checkBirthdayDay($birthdayDay))
  95. {
  96. $ERRORS->Add($birthdayDayError);
  97. }
  98.  
  99. //validate the Year
  100. if ($birthdayYearError = AccountsRegister::checkBirthdayYear($birthdayYear))
  101. {
  102. $ERRORS->Add($birthdayYearError);
  103. }
  104.  
  105. //add zero "0" to the day if it's not aready entered
  106. $dayLen = strlen($birthdayDay);
  107. if (($dayLen >= 1 and $dayLen <= 2) and ($birthdayDay >= 1 and $birthdayDay <= 31))
  108. {
  109. if ($dayLen == 1)
  110. {
  111. $birthdayDay = '0' . $birthdayDay;
  112. }
  113. }
  114.  
  115. //merge the birthday
  116. $birthday = $birthdayMonth . '/' . $birthdayDay . '/' . $birthdayYear;
  117.  
  118. ######################################
  119. ######### Gender Check ##############
  120. if($genderError = AccountsRegister::checkGender($gender)) {
  121. $ERRORS->add($genderError);
  122. }
  123.  
  124. ######################################
  125. ######### Country Check ##############
  126. if ($countryError = AccountsRegister::checkCountry($country))
  127. {
  128. $ERRORS->Add($countryError);
  129. }
  130.  
  131. ######################################
  132. ## Secret Question & Answer Check ####
  133. if ($secretQuestionError = AccountsRegister::checkSecretQuestion($secretQuestion))
  134. {
  135. $ERRORS->Add($secretQuestionError);
  136. }
  137.  
  138. if ($secretAnswerError = AccountsRegister::checkSecretAnswer($secretAnswer))
  139. {
  140. $ERRORS->Add($secretAnswerError);
  141. }
  142.  
  143. $secretAnswer = trim($secretAnswer);
  144.  
  145. ######################################
  146. ######### Text Captcha Check #########
  147. /*
  148. if ($CaptchaResponseField = $captcha->GetResponseFieldName())
  149. {
  150. $CaptchaResponse = isset($_POST[$CaptchaResponseField]) ? $_POST[$CaptchaResponseField] : false;
  151. //check if it was filled in
  152. if (!$CaptchaResponse)
  153. {
  154. $ERRORS->Add('Please answer the Human Test question.');
  155. }
  156. else if (!$captcha->CheckAnswer($CaptchaResponse))
  157. {
  158. $ERRORS->Add('You have failed to answer the Human Test question.');
  159. }
  160. }
  161. else
  162. {
  163. $ERRORS->Add('There was a problem with the Human Test.');
  164. }
  165. //kill the captcha session
  166. $captcha->Kill();
  167. //free up some mem
  168. unset($CaptchaResponseField, $CaptchaResponse, $captcha);
  169. */
  170. //Check for errors
  171. $ERRORS->Check('/index.php?page=register'.($rafHash ? '&raf='.$rafHash : ''));
  172.  
  173. ##################################################
  174. ######## REGISTER SERVER ACCOUNT #################
  175.  
  176. //some default variables
  177. $expansion = 2;
  178. $recruiter = 0;
  179.  
  180. //resolve the RAF acc ID
  181. if ($rafHash)
  182. {
  183. if ($rafRow = $raf->FindHash($rafHash))
  184. {
  185. $recruiter = $rafRow['account'];
  186. }
  187. }
  188.  
  189. //register
  190. if ($accountId = server_Account::register($username, $password, $email, $expansion, $recruiter))
  191. {
  192. //unset the terms variable
  193. unset($_SESSION['TermsAccepted']);
  194.  
  195. //Get visitor's IP Address
  196. $ip = $SECURITY->getip();
  197. $thetime = $CORE->getTime();
  198. $regStatus = 'active';
  199.  
  200. //hash the secret answer
  201. $aHash = sha1($secretQuestion . ':' . strtolower($secretAnswer));
  202.  
  203. //insert web record
  204. $insert = $DB->prepare("REPLACE INTO `account_data` (`id`, `displayName`, `birthday`, `country`, `secretQuestion`, `secretAnswer`, `last_ip`, `reg_ip`, `last_login`, `last_login2`, `status`, `gender` , `password`) VALUES (:accid, :displayName, :birthday, :country, :secretQuestion, :secretAnswer, :lastip, :regip, '0000-00-00 00:00:00', :lastlogin2, :status, :gender, :password);");
  205. $insert->bindParam(':accid', $accountId, PDO::PARAM_INT);
  206. $insert->bindparam(':displayName', $displayName, PDO::PARAM_STR);
  207. $insert->bindParam(':birthday', $birthday, PDO::PARAM_STR);
  208. $insert->bindParam(':country', $country, PDO::PARAM_STR);
  209. $insert->bindParam(':secretQuestion', $secretQuestion, PDO::PARAM_INT);
  210. $insert->bindParam(':secretAnswer', $aHash, PDO::PARAM_STR);
  211. $insert->bindParam(':lastip', $ip, PDO::PARAM_STR);
  212. $insert->bindParam(':regip', $ip, PDO::PARAM_STR);
  213. $insert->bindParam(':lastlogin2', $thetime, PDO::PARAM_STR);
  214. $insert->bindParam(':status', $regStatus, PDO::PARAM_STR);
  215. $insert->bindParam(':gender', $gender, PDO::PARAM_STR);
  216. $insert->bindparam(':password', $password, PDO::PARAM_STR);
  217. $insert->execute();
  218.  
  219. ######################################
  220. ############## RAF ###################
  221. //make a new raf link record because
  222. //we dont wanna query out auth databse
  223. //too much with the website
  224. if ($rafHash)
  225. {
  226. if ($rafRow)
  227. {
  228. $raf->CreateLink($accountId, $recruiter);
  229. }
  230. }
  231.  
  232. ######################################
  233. ############ MAILING #################
  234. $CORE->load_CoreModule('phpmailer');
  235.  
  236. //setup the PHPMailer class
  237. $mail = new PHPMailer();
  238. $mail->IsMail();
  239. $mail->From = $config['Email'];
  240. $mail->FromName = 'example - Info';
  241. $mail->AddAddress($email);
  242.  
  243. //get the message html
  244. $message = file_get_contents($config['RootPath'] . '/resources/mails/register_mail.html');
  245.  
  246. //break if the function failed to laod HTML
  247. if ($message)
  248. {
  249. //replace the tags with info
  250. $search = array('{USERNAME}', '{DISPLAYNAME}', '{PASSWORD}');
  251. $replace = array($username, $displayName, $password);
  252. $message = str_replace($search, $replace, $message);
  253.  
  254. $mail->WordWrap = 50;
  255. $mail->IsHTML(true);
  256.  
  257. $mail->Subject = "example Registration";
  258. $mail->Body = $message;
  259. //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
  260.  
  261. $mail->Send();
  262. }
  263.  
  264. ######################################
  265. ############# LOGIN ##################
  266. $shapasshash = server_Account::makeHash($username, $password);
  267. $CURUSER->setLoggedIn($accountId, $shapasshash);
  268.  
  269. //unset
  270. unset($raf);
  271.  
  272. //Setup our welcoming notification
  273. $NOTIFICATIONS->SetTitle('Notification');
  274. $NOTIFICATIONS->SetHeadline('Congratulation!');
  275. $NOTIFICATIONS->SetText('Welcome and thank you for joining the example community.<br>Your example account has been automatically activated.<br>Please enjoy.');
  276. $NOTIFICATIONS->SetTextAlign('center');
  277. //$NOTIFICATIONS->SetAutoContinue(true);
  278. //$NOTIFICATIONS->SetContinueDelay(5);
  279. $NOTIFICATIONS->Apply();
  280.  
  281. ######################################
  282. ########## Redirect ##################
  283. header("Location: ".$config['BaseURL']."/index.php?page=home");
  284. }
  285. else
  286. {
  287. $ERRORS->Add('Website Failure, it seems the website is not functioning at the moment. If this problem persists please contact the administration.');
  288. }
  289.  
  290. //unset
  291. unset($raf);
  292.  
  293. $ERRORS->Check('/index.php?page=register'.($rafHash ? '&raf='.$rafHash : ''));
  294.  
  295. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement