Guest User

Untitled

a guest
Dec 15th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. class RegisterController extends Controller {
  4.  
  5. public $helpers = array('form', 'html');
  6.  
  7. public function __construct() {
  8. if(!ENABLE_REGISTRATION) {
  9. $this->render("/page_not_found");
  10. }
  11. parent::__construct();
  12. Loader::model('user_attributes');
  13.  
  14. $u = new User();
  15. $this->set('u', $u);
  16.  
  17. /*
  18. if (USER_REGISTRATION_WITH_EMAIL_ADDRESS) {
  19. $this->set('displayUserName', false);
  20. } else {
  21. $this->set('displayUserName', true);
  22. }*/
  23.  
  24. $this->set('displayUserName', true);
  25.  
  26. }
  27.  
  28. public function forward($cID) {
  29. $this->set('rcID', $cID);
  30. }
  31.  
  32. public function do_register() {
  33.  
  34. $registerData['success']=0;
  35.  
  36. $userHelper = Loader::helper('concrete/user');
  37. $e = Loader::helper('validation/error');
  38. $ip = Loader::helper('validation/ip');
  39. $txt = Loader::helper('text');
  40. $vals = Loader::helper('validation/strings');
  41. $valc = Loader::helper('concrete/validation');
  42.  
  43. $username = $_POST['uName'];
  44. $password = $_POST['uPassword'];
  45. $passwordConfirm = $_POST['uPasswordConfirm'];
  46.  
  47. // clean the username
  48. $username = trim($username);
  49. $username = preg_replace("/ +/", " ", $username);
  50.  
  51.  
  52. if (!$ip->check()) {
  53. $e->add($ip->getErrorMessage());
  54. }
  55.  
  56. if (ENABLE_REGISTRATION_CAPTCHA) {
  57. $captcha = Loader::helper('validation/captcha');
  58. if (!$captcha->check()) {
  59. $e->add(t("Incorrect image validation code. Please check the image and re-enter the letters or numbers as necessary."));
  60. }
  61. }
  62.  
  63. if (!$vals->email($_POST['uEmail'])) {
  64. $e->add(t('Invalid email address provided.'));
  65. } else if (!$valc->isUniqueEmail($_POST['uEmail'])) {
  66. $e->add(t("The email address %s is already in use. Please choose another.", $_POST['uEmail']));
  67. }
  68.  
  69. //if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == false) {
  70.  
  71. if (strlen($username) < USER_USERNAME_MINIMUM) {
  72. $e->add(t('A username must be between at least %s characters long.', USER_USERNAME_MINIMUM));
  73. }
  74.  
  75. if (strlen($username) > USER_USERNAME_MAXIMUM) {
  76. $e->add(t('A username cannot be more than %s characters long.', USER_USERNAME_MAXIMUM));
  77. }
  78.  
  79.  
  80. if (strlen($username) >= USER_USERNAME_MINIMUM && !$valc->username($username)) {
  81. if(USER_USERNAME_ALLOW_SPACES) {
  82. $e->add(t('A username may only contain letters, numbers and spaces.'));
  83. } else {
  84. $e->add(t('A username may only contain letters or numbers.'));
  85. }
  86.  
  87. }
  88. if (!$valc->isUniqueUsername($username)) {
  89. $e->add(t("The username %s already exists. Please choose another", $username));
  90. }
  91. //}
  92.  
  93. if ($username == USER_SUPER) {
  94. $e->add(t('Invalid Username'));
  95. }
  96.  
  97. /*
  98. if ((strlen($password) < USER_PASSWORD_MINIMUM) || (strlen($password) > USER_PASSWORD_MAXIMUM)) {
  99. $e->add(t('A password must be between %s and %s characters', USER_PASSWORD_MINIMUM, USER_PASSWORD_MAXIMUM));
  100. }
  101.  
  102. if (strlen($password) >= USER_PASSWORD_MINIMUM && !$valc->password($password)) {
  103. $e->add(t('A password may not contain ", \', >, <, or any spaces.'));
  104. }
  105. */
  106.  
  107. $userHelper->validNewPassword($password,$e);
  108.  
  109. if ($password) {
  110. if ($password != $passwordConfirm) {
  111. $e->add(t('The two passwords provided do not match.'));
  112. }
  113. }
  114.  
  115. $aks = UserAttributeKey::getRegistrationList();
  116.  
  117. foreach($aks as $uak) {
  118. if ($uak->isAttributeKeyRequiredOnRegister()) {
  119. $e1 = $uak->validateAttributeForm();
  120. if ($e1 == false) {
  121. $e->add(t('The field "%s" is required', $uak->getAttributeKeyName()));
  122. } else if ($e1 instanceof ValidationErrorHelper) {
  123. $e->add($e1);
  124. }
  125. }
  126. }
  127.  
  128. if (!$e->has()) {
  129.  
  130. // do the registration
  131. $data = $_POST;
  132. $data['uName'] = $username;
  133. $data['uPassword'] = $password;
  134. $data['uPasswordConfirm'] = $passwordConfirm;
  135.  
  136. $process = UserInfo::register($data);
  137. if (is_object($process)) {
  138.  
  139. foreach($aks as $uak) {
  140. $uak->saveAttributeForm($process);
  141. }
  142.  
  143. if (defined('EMAIL_ADDRESS_REGISTER_NOTIFICATION')) {
  144. $mh = Loader::helper('mail');
  145. if (defined('EMAIL_ADDRESS_REGISTER_NOTIFICATION_FROM')) {
  146. $mh->from(EMAIL_ADDRESS_REGISTER_NOTIFICATION_FROM, t('Website Registration Notification'));
  147. } else {
  148. $adminUser = UserInfo::getByID(USER_SUPER_ID);
  149. if (is_object($adminUser)) {
  150. $mh->from($adminUser->getUserEmail(), t('Website Registration Notification'));
  151. }
  152. }
  153. $mh->addParameter('uName', $process->getUserName());
  154. $mh->addParameter('uID', $process->getUserID());
  155. $mh->addParameter('uEmail', $process->getUserEmail());
  156. $attribs = UserAttributeKey::getRegistrationList();
  157. foreach($attribs as $ak) {
  158. $attribValues[] = $ak->getAttributeKeyDisplayHandle() . ': ' . $process->getAttribute($ak->getAttributeKeyHandle(), 'display');
  159. }
  160. $mh->addParameter('attribs', $attribValues);
  161. $mh->to(EMAIL_ADDRESS_REGISTER_NOTIFICATION);
  162. if (USER_REGISTRATION_APPROVAL_REQUIRED) {
  163. $mh->load('user_register_approval_required');
  164. } else {
  165. $mh->load('user_register');
  166. }
  167. $mh->sendMail();
  168. }
  169.  
  170. // now we log the user in
  171. if (USER_REGISTRATION_WITH_EMAIL_ADDRESS) {
  172. $u = new User($_POST['uEmail'], $_POST['uPassword']);
  173. } else {
  174. $u = new User($_POST['uName'], $_POST['uPassword']);
  175. }
  176. // if this is successful, uID is loaded into session for this user
  177.  
  178. $rcID = $this->post('rcID');
  179. $nh = Loader::helper('validation/numbers');
  180. if (!$nh->integer($rcID)) {
  181. $rcID = 0;
  182. }
  183.  
  184. // now we check whether we need to validate this user's email address
  185. if (defined("USER_VALIDATE_EMAIL") && USER_VALIDATE_EMAIL) {
  186. if (USER_VALIDATE_EMAIL > 0) {
  187. $uHash = $process->setupValidation();
  188.  
  189. $mh = Loader::helper('mail');
  190. if (defined('EMAIL_ADDRESS_VALIDATE')) {
  191. $mh->from(EMAIL_ADDRESS_VALIDATE, t('Validate Email Address'));
  192. }
  193. $mh->addParameter('uEmail', $_POST['uEmail']);
  194. $mh->addParameter('uHash', $uHash);
  195. $mh->to($_POST['uEmail']);
  196. $mh->load('validate_user_email');
  197. $mh->sendMail();
  198.  
  199. //$this->redirect('/register', 'register_success_validate', $rcID);
  200. $redirectMethod='register_success_validate';
  201. $registerData['msg']= join('<br><br>',$this->getRegisterSuccessValidateMsgs());
  202.  
  203. $u->logout();
  204.  
  205. }
  206. } else if(defined('USER_REGISTRATION_APPROVAL_REQUIRED') && USER_REGISTRATION_APPROVAL_REQUIRED) {
  207. $ui = UserInfo::getByID($u->getUserID());
  208. $ui->deactivate();
  209. //$this->redirect('/register', 'register_pending', $rcID);
  210. $redirectMethod='register_pending';
  211. $registerData['msg']=$this->getRegisterPendingMsg();
  212. $u->logout();
  213. }
  214.  
  215. if (!$u->isError()) {
  216. //$this->redirect('/register', 'register_success', $rcID);
  217. if(!$redirectMethod){
  218. $redirectMethod='register_success';
  219. $registerData['msg']=$this->getRegisterSuccessMsg();
  220. }
  221. $registerData['uID']=intval($u->uID);
  222. }
  223.  
  224. $registerData['success']=1;
  225.  
  226. if($_REQUEST['format']!='JSON')
  227. $this->redirect('/register', $redirectMethod, $rcID);
  228. }
  229. } else {
  230. $ip->logSignupRequest();
  231. if ($ip->signupRequestThreshholdReached()) {
  232. $ip->createIPBan();
  233. }
  234. $this->set('error', $e);
  235. $registerData['errors'] = $e->getList();
  236. }
  237.  
  238. if( $_REQUEST['format']=='JSON' ){
  239. $jsonHelper=Loader::helper('json');
  240. echo $jsonHelper->encode($registerData);
  241. die;
  242. }
  243. }
  244.  
  245. public function register_success_validate($rcID = 0) {
  246. $this->set('rcID', $rcID);
  247. $this->set('success', 'validate');
  248. $this->set('successMsg', $this->getRegisterSuccessValidateMsgs() );
  249. }
  250.  
  251. public function register_success($rcID = 0) {
  252. $this->set('rcID', $rcID);
  253. $this->set('success', 'registered');
  254. $this->set('successMsg', $this->getRegisterSuccessMsg() );
  255. }
  256.  
  257. public function register_pending() {
  258. $this->set('rcID', $rcID);
  259. $this->set('success', 'pending');
  260. $this->set('successMsg', $this->getRegisterPendingMsg() );
  261. }
  262.  
  263. public function getRegisterSuccessMsg(){
  264. return t('Your account has been created, and you are now logged in.');
  265. }
  266.  
  267. public function getRegisterSuccessValidateMsgs(){
  268. $msgs=array();
  269. $msgs[]= t('You are registered but you need to validate your email address. Some or all functionality on this site will be limited until you do so.');
  270. $msgs[]= t('An email has been sent to your email address. Click on the URL contained in the email to validate your email address.');
  271. return $msgs;
  272. }
  273.  
  274. public function getRegisterPendingMsg(){
  275. return t('You are registered but a site administrator must review your account, you will not be able to login until your account has been approved.');
  276. }
  277. }
  278.  
  279. ?>
Add Comment
Please, Sign In to add comment