Guest User

signup

a guest
Sep 27th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. <?php
  2.  
  3. $user = new Users;
  4.  
  5. if ($config->isPOST()){
  6. $req = & $_POST;
  7. } else {
  8. $req = & $_GET;
  9. }
  10. $campaignHash = isset($req['campaignHash']) ? $req['campaignHash'] : null;
  11.  
  12. $data = array(
  13. 'screenname' => trim($req['screenname']),
  14. 'email' => trim($req['email']),
  15. 'password' => $req['password']
  16. );
  17.  
  18. $lang = isset($_GET['lang']) ? $_GET['lang'] : null;
  19.  
  20. if (empty($data['screenname'])) {
  21. Ajax::outputError(Lang::getText('fill_in_your_name', $lang));
  22. } else if (!valid_screenname($data['screenname'])){
  23. Ajax::outputError(Lang::getText('name_invalid_caracters', $lang));
  24. } else if (!Valid::email($data['email'])){
  25. Ajax::outputError(Lang::getText('invalid_email_address', $lang));
  26. } else if (Users::emailExistsForType($data['email'], Users::TYPE_SNACKTOOLS)){
  27. Ajax::outputError(Lang::getText('email_exists', $lang));
  28. } else if (strlen($data['password']) < 4){
  29. Ajax::outputError(Lang::getText('password_to_short', $lang));
  30. }
  31.  
  32. $username = null;
  33. if (isset($req['username'])) {
  34. $username = realEscapeString(trim($req['username']));
  35. if (strlen($username) < UserProfile::MIN_USERNAME_LENGTH) {
  36. Ajax::outputError(str_replace('$chars$', UserProfile::MIN_USERNAME_LENGTH, Lang::getText('name_char_length', $lang)));
  37. }
  38. if (!UserProfile::valid($username)) {
  39. Ajax::outputError(Lang::getText('name_invalid_caracters', $lang));
  40. }
  41. if (!UserProfile::accepted($username)) {
  42. Ajax::outputError(Lang::getText('username_not_accepted', $lang));
  43. }
  44. if (!UserProfile::unique($username)) {
  45. Ajax::outputError(Lang::getText('username_not_unique', $lang));
  46. }
  47. }
  48.  
  49. //check for social account with this email
  50. if ($type = Users::haveActiveOldSocialAccounts($data['email'])){
  51. $err = sprintf(Lang::getText('email_associated_with_other_account_type'), $type, $data['email']);
  52. Ajax::outputError($err);
  53. }
  54.  
  55. //temp
  56. $temailSplit = explode('@', $data['email']);
  57. if (count($temailSplit) == 2 && strtolower($temailSplit[1]) == 'hotmail.com'){
  58. $hLettersCount = 0;
  59. $tename = $temailSplit[0];
  60. $tenameCount = strlen($tename);
  61. for ($i = 0; $i < $tenameCount; $i++){
  62. if (ctype_upper($tename[$i])){
  63. $hLettersCount++;
  64. }
  65. }
  66. if ($hLettersCount >= 2){
  67. $hDigitCount = 0;
  68. $tscname = $data['screenname'];
  69. $tscnameeCount = strlen($tscname);
  70. for ($i = 0; $i < $tscnameeCount; $i++){
  71. if (ctype_digit($tscname[$i])){
  72. $hDigitCount++;
  73. }
  74. }
  75. if ($hDigitCount > 0){
  76. Ajax::outputError(Lang::getText('signup_hotmail_error'));
  77. }
  78. }
  79. }
  80. //end temp
  81.  
  82. //check bannedDomains
  83. if (UserBannedEmailDomain::bannedForEmail($data['email'])){
  84. Ajax::outputError(Lang::getText('signup_hotmail_error'));
  85. }
  86.  
  87. //temp 2
  88. //disable screenname: Joan Hx Michael, Edward Hz Michael ...
  89. $tscname = explode(" ", $data['screenname']);
  90. if (count($tscname) === 3 &&
  91. strtoupper($tscname[0][0]) === $tscname[0][0] &&
  92. strtoupper($tscname[1][0]) === $tscname[1][0] &&
  93. strtoupper($tscname[2][0]) === $tscname[2][0] &&
  94. strlen($tscname[1]) == 2 &&
  95. !UserBannedEmailDomain::emailDomainIsInWildCardList($data['email'])
  96. ){
  97. Ajax::outputError(Lang::getText('signup_hotmail_error'));
  98. }
  99. //end temp 2
  100.  
  101. $ip = isset($_GET['ip']) ? $_GET['ip'] : null;
  102. $requireCaptcha = UsersHistory::requireCaptcha($ip);
  103.  
  104. $lterminal = isset($_REQUEST['loginTerminal']) ? $_REQUEST['loginTerminal'] : null;
  105. if (!$lterminal){
  106. $lterminal = $terminal;
  107. }
  108.  
  109. if($lterminal=='snacktools'){
  110. $captchaSrc = $config->STApi->urlHttps;
  111. } else {
  112. $captchaSrc = $config->absolute_url;
  113. }
  114.  
  115. if ($requireCaptcha && !CaptchaGenerator::checkCaptcha($req['captchaId'], $req['captcha'])){
  116. $newCaptchaId = CaptchaGenerator::getNewDBId();
  117. $out = array(
  118. 'error' => Lang::getText('invalid_captcha_code'),
  119. 'id' => $newCaptchaId,
  120. 'src' => $captchaSrc . '/captcha.php?id=' . $newCaptchaId . '&t=' . $lterminal
  121. );
  122. Ajax::outputError($out, 4);
  123. }
  124.  
  125.  
  126. $smarty = UserApi::getSmarty();
  127.  
  128. $user->setRecord($data);
  129. $user->active = 1;
  130. $user->confirmed = 0;
  131. $user->password = md5($data['password']);
  132.  
  133. if (isset($req['banneradv']) && $req['banneradv']){
  134. $user->addFlag(Users::FLAG_ADVERTISING_FROM_BLOG_NEWSLETTER);
  135. }
  136.  
  137. $user->insert($lterminal, $campaignHash, isset($req['ip']) ? $req['ip'] : null);
  138.  
  139. if (!isset($req['newsletter']) || !$req['newsletter']){
  140. $udetails = $user->getDetails();
  141. if ($udetails->id){
  142. $udetails->newsletter = 0;
  143. $udetails->save();
  144. }
  145. }
  146.  
  147. if ($username) {
  148. $userProfile = new UserProfile();
  149. $userProfile->user_id = $user->id;
  150. $userProfile->user_name = $username;
  151. $userProfile->insert();
  152. }
  153.  
  154. $activation = $user->createActivationRecord($lterminal);
  155. $user->sendActivationMail($activation);
  156. $user->STApiForceLoginCurrentUser($lterminal, isset($req['ip']) ? $req['ip'] : null);
  157. CaptchaGenerator::deleteCaptcha($req['captchaId']);
  158.  
  159. TrackLogs::trackMember();
  160. TrackObjLogs::trackMember();
  161.  
  162. UserApi::addOutputData('PHPSESSID', session_id());
  163.  
  164. $textsIndexes = array(
  165. 'account_created_verify_email',
  166. 'account_created_important',
  167. 'account_created_time_left',
  168. 'continue_button',
  169. 'access_to_all_apps',
  170. 'thank_you_for_registering',
  171. 'account_created_verify_email_flipsnack'
  172. );
  173. $bsTextsIndexes = array(
  174. 'almost_there',
  175. 'best_experience',
  176. 'what_describes',
  177. 'business_owner',
  178. 'marketer',
  179. 'designer',
  180. 'developer',
  181. 'none_of_the_above',
  182. 'account_created_email_sent',
  183. 'bs_account_created_please_confirm'
  184. );
  185.  
  186. $textsIndexes = array_merge($textsIndexes, $bsTextsIndexes);
  187.  
  188. $texts = Lang::getTexts($textsIndexes, $lang);
  189. $smarty->assign('texts', $texts);
  190. $smarty->assign('terminal', $terminal);
  191.  
  192. $options = isset($_GET['options']) && is_array($_GET['options']) ? $_GET['options'] : array();
  193.  
  194. if ($lterminal != 'bannersnack') {
  195. UserApi::htmlContent($smarty->fetch('account-created.tpl'));
  196. } else {
  197. UserApi::htmlContent($smarty->fetch('bannersnack/account-created.tpl'));
  198. }
  199.  
  200. UserApi::addOutputData('user', $user);
  201. UserApi::addOutputData('pageTitle', $texts['thank_you_for_registering']);
  202. UserApi::addOutputData('header', UserApi::getHeaderHtml($terminal, $options));
  203. UserApi::addOutputData('rememberme', true);
  204. UserApi::addOutputData('email', $user->email);
  205. UserApi::addOutputData('pass', $user->password);
Add Comment
Please, Sign In to add comment