PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/webroot/updates/concrete5.6.0.2/concrete/core/controllers/single_pages/register.php

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