PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/User/Form/Signup/Account.php

https://github.com/grandison/budo16
PHP | 317 lines | 241 code | 36 blank | 40 comment | 26 complexity | 0b21ecca568ec2ff3bbe734e3b8a3c4e MD5 | raw file
  1. <?php
  2. /**
  3. * SocialEngine
  4. *
  5. * @category Application_Core
  6. * @package User
  7. * @copyright Copyright 2006-2010 Webligo Developments
  8. * @license http://www.socialengine.net/license/
  9. * @version $Id: Account.php 8913 2011-05-02 18:03:07Z shaun $
  10. * @author John
  11. */
  12. /**
  13. * @category Application_Core
  14. * @package User
  15. * @copyright Copyright 2006-2010 Webligo Developments
  16. * @license http://www.socialengine.net/license/
  17. */
  18. class User_Form_Signup_Account extends Engine_Form
  19. {
  20. public function init()
  21. {
  22. $settings = Engine_Api::_()->getApi('settings', 'core');
  23. $inviteSession = new Zend_Session_Namespace('invite');
  24. // Init form
  25. $this->setTitle('Create Account');
  26. // Element: email
  27. $this->addElement('Text', 'email', array(
  28. 'label' => 'Email Address',
  29. 'description' => 'You will use your email address to login.',
  30. 'required' => true,
  31. 'allowEmpty' => false,
  32. 'validators' => array(
  33. array('NotEmpty', true),
  34. array('EmailAddress', true),
  35. array('Db_NoRecordExists', true, array(Engine_Db_Table::getTablePrefix() . 'users', 'email'))
  36. ),
  37. ));
  38. $this->email->getDecorator('Description')->setOptions(array('placement' => 'APPEND'));
  39. $this->email->getValidator('NotEmpty')->setMessage('Please enter a valid email address.', 'isEmpty');
  40. $this->email->getValidator('Db_NoRecordExists')->setMessage('Someone has already registered this email address, please use another one.', 'recordFound');
  41. if( !empty($inviteSession->invite_email) ) {
  42. $this->email->setValue($inviteSession->invite_email);
  43. }
  44. //if( $settings->getSetting('user.signup.verifyemail', 0) > 0 && $settings->getSetting('user.signup.checkemail', 0) == 1 ) {
  45. // $this->email->addValidator('Identical', true, array($inviteSession->invite_email));
  46. // $this->email->getValidator('Identical')->setMessage('Your email address must match the address that was invited.', 'notSame');
  47. //}
  48. // Element: code
  49. if( $settings->getSetting('user.signup.inviteonly') > 0 ) {
  50. $codeValidator = new Engine_Validate_Callback(array($this, 'checkInviteCode'), $this->email);
  51. $codeValidator->setMessage("This invite code is invalid or does not match the selected email address");
  52. $this->addElement('Text', 'code', array(
  53. 'label' => 'Invite Code',
  54. 'required' => true
  55. ));
  56. $this->code->addValidator($codeValidator);
  57. if( !empty($inviteSession->invite_code) ) {
  58. $this->code->setValue($inviteSession->invite_code);
  59. }
  60. }
  61. if( $settings->getSetting('user.signup.random', 0) == 0 ) {
  62. // Element: password
  63. $this->addElement('Password', 'password', array(
  64. 'label' => 'Password',
  65. 'description' => 'Passwords must be at least 6 characters in length.',
  66. 'required' => true,
  67. 'allowEmpty' => false,
  68. 'validators' => array(
  69. array('NotEmpty', true),
  70. array('StringLength', false, array(6, 32)),
  71. )
  72. ));
  73. $this->password->getDecorator('Description')->setOptions(array('placement' => 'APPEND'));
  74. $this->password->getValidator('NotEmpty')->setMessage('Please enter a valid password.', 'isEmpty');
  75. // Element: passconf
  76. $this->addElement('Password', 'passconf', array(
  77. 'label' => 'Password Again',
  78. 'description' => 'Enter your password again for confirmation.',
  79. 'required' => true,
  80. 'validators' => array(
  81. array('NotEmpty', true),
  82. )
  83. ));
  84. $this->passconf->getDecorator('Description')->setOptions(array('placement' => 'APPEND'));
  85. $this->passconf->getValidator('NotEmpty')->setMessage('Please make sure the "password" and "password again" fields match.', 'isEmpty');
  86. $specialValidator = new Engine_Validate_Callback(array($this, 'checkPasswordConfirm'), $this->password);
  87. $specialValidator->setMessage('Password did not match', 'invalid');
  88. $this->passconf->addValidator($specialValidator);
  89. }
  90. // Element: username
  91. if( $settings->getSetting('user.signup.username', 1) > 0 ) {
  92. $description = Zend_Registry::get('Zend_Translate')
  93. ->_('This will be the end of your profile link, for example: <br /> ' .
  94. '<span id="profile_address">http://%s</span>');
  95. $description = sprintf($description, $_SERVER['HTTP_HOST']
  96. . Zend_Controller_Front::getInstance()->getRouter()
  97. ->assemble(array('id' => 'yourname'), 'user_profile'));
  98. $this->addElement('Text', 'username', array(
  99. 'label' => 'Profile Address',
  100. 'description' => $description,
  101. 'required' => true,
  102. 'allowEmpty' => false,
  103. 'validators' => array(
  104. array('NotEmpty', true),
  105. array('Alnum', true),
  106. array('StringLength', true, array(4, 64)),
  107. array('Regex', true, array('/^[a-z][a-z0-9]*$/i')),
  108. array('Db_NoRecordExists', true, array(Engine_Db_Table::getTablePrefix() . 'users', 'username'))
  109. ),
  110. //'onblur' => 'var el = this; en4.user.checkUsernameTaken(this.value, function(taken){ el.style.marginBottom = taken * 100 + "px" });'
  111. ));
  112. $this->username->getDecorator('Description')->setOptions(array('placement' => 'APPEND', 'escape' => false));
  113. $this->username->getValidator('NotEmpty')->setMessage('Please enter a valid profile address.', 'isEmpty');
  114. $this->username->getValidator('Db_NoRecordExists')->setMessage('Someone has already picked this profile address, please use another one.', 'recordFound');
  115. $this->username->getValidator('Regex')->setMessage('Profile addresses must start with a letter.', 'regexNotMatch');
  116. $this->username->getValidator('Alnum')->setMessage('Profile addresses must be alphanumeric.', 'notAlnum');
  117. }
  118. // Element: profile_type
  119. $topStructure = Engine_Api::_()->fields()->getFieldStructureTop('user');
  120. if( count($topStructure) == 1 && $topStructure[0]->getChild()->type == 'profile_type' ) {
  121. $profileTypeField = $topStructure[0]->getChild();
  122. $options = $profileTypeField->getOptions();
  123. if( count($options) > 1 ) {
  124. $options = $profileTypeField->getElementParams('user');
  125. unset($options['options']['order']);
  126. unset($options['options']['multiOptions']['0']);
  127. $this->addElement('Select', 'profile_type', array_merge($options['options'], array(
  128. 'required' => true,
  129. 'allowEmpty' => false,
  130. )));
  131. } else if( count($options) == 1 ) {
  132. $this->addElement('Hidden', 'profile_type', array(
  133. 'value' => $options[0]->option_id
  134. ));
  135. }
  136. }
  137. // Element: timezone
  138. $this->addElement('Select', 'timezone', array(
  139. 'label' => 'Timezone',
  140. 'value' => $settings->getSetting('core.locale.timezone'),
  141. 'multiOptions' => array(
  142. 'US/Pacific' => '(UTC-8) Pacific Time (US & Canada)',
  143. 'US/Mountain' => '(UTC-7) Mountain Time (US & Canada)',
  144. 'US/Central' => '(UTC-6) Central Time (US & Canada)',
  145. 'US/Eastern' => '(UTC-5) Eastern Time (US & Canada)',
  146. 'America/Halifax' => '(UTC-4) Atlantic Time (Canada)',
  147. 'America/Anchorage' => '(UTC-9) Alaska (US & Canada)',
  148. 'Pacific/Honolulu' => '(UTC-10) Hawaii (US)',
  149. 'Pacific/Samoa' => '(UTC-11) Midway Island, Samoa',
  150. 'Etc/GMT-12' => '(UTC-12) Eniwetok, Kwajalein',
  151. 'Canada/Newfoundland' => '(UTC-3:30) Canada/Newfoundland',
  152. 'America/Buenos_Aires' => '(UTC-3) Brasilia, Buenos Aires, Georgetown',
  153. 'Atlantic/South_Georgia' => '(UTC-2) Mid-Atlantic',
  154. 'Atlantic/Azores' => '(UTC-1) Azores, Cape Verde Is.',
  155. 'Europe/London' => 'Greenwich Mean Time (Lisbon, London)',
  156. 'Europe/Berlin' => '(UTC+1) Amsterdam, Berlin, Paris, Rome, Madrid',
  157. 'Europe/Athens' => '(UTC+2) Athens, Helsinki, Istanbul, Cairo, E. Europe',
  158. 'Europe/Moscow' => '(UTC+3) Baghdad, Kuwait, Nairobi, Moscow',
  159. 'Iran' => '(UTC+3:30) Tehran',
  160. 'Asia/Dubai' => '(UTC+4) Abu Dhabi, Kazan, Muscat',
  161. 'Asia/Kabul' => '(UTC+4:30) Kabul',
  162. 'Asia/Yekaterinburg' => '(UTC+5) Islamabad, Karachi, Tashkent',
  163. 'Asia/Dili' => '(UTC+5:30) Bombay, Calcutta, New Delhi',
  164. 'Asia/Katmandu' => '(UTC+5:45) Nepal',
  165. 'Asia/Omsk' => '(UTC+6) Almaty, Dhaka',
  166. 'Indian/Cocos' => '(UTC+6:30) Cocos Islands, Yangon',
  167. 'Asia/Bangkok' => '(UTC+7) Bangkok, Jakarta, Hanoi',
  168. 'Asia/Hong_Kong' => '(UTC+8) Beijing, Hong Kong, Singapore, Taipei',
  169. 'Asia/Tokyo' => '(UTC+9) Tokyo, Osaka, Sapporto, Seoul, Yakutsk',
  170. 'Australia/Adelaide' => '(UTC+9:30) Adelaide, Darwin',
  171. 'Australia/Sydney' => '(UTC+10) Brisbane, Melbourne, Sydney, Guam',
  172. 'Asia/Magadan' => '(UTC+11) Magadan, Solomon Is., New Caledonia',
  173. 'Pacific/Auckland' => '(UTC+12) Fiji, Kamchatka, Marshall Is., Wellington',
  174. )
  175. ));
  176. $this->timezone->getDecorator('Description')->setOptions(array('placement' => 'APPEND'));
  177. // Element: language
  178. // Languages
  179. $translate = Zend_Registry::get('Zend_Translate');
  180. $languageList = $translate->getList();
  181. //$currentLocale = Zend_Registry::get('Locale')->__toString();
  182. // Prepare default langauge
  183. $defaultLanguage = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'en');
  184. if( !in_array($defaultLanguage, $languageList) ) {
  185. if( $defaultLanguage == 'auto' && isset($languageList['en']) ) {
  186. $defaultLanguage = 'en';
  187. } else {
  188. $defaultLanguage = null;
  189. }
  190. }
  191. // Prepare language name list
  192. $localeObject = Zend_Registry::get('Locale');
  193. $languageNameList = array();
  194. $languageDataList = Zend_Locale_Data::getList($localeObject, 'language');
  195. $territoryDataList = Zend_Locale_Data::getList($localeObject, 'territory');
  196. foreach( $languageList as $localeCode ) {
  197. $languageNameList[$localeCode] = Zend_Locale::getTranslation($localeCode, 'language', $localeCode);
  198. if( empty($languageNameList[$localeCode]) ) {
  199. list($locale, $territory) = explode('_', $localeCode);
  200. $languageNameList[$localeCode] = "{$territoryDataList[$territory]} {$languageDataList[$locale]}";
  201. }
  202. }
  203. $languageNameList = array_merge(array(
  204. $defaultLanguage => $defaultLanguage
  205. ), $languageNameList);
  206. if(count($languageNameList)>1){
  207. $this->addElement('Select', 'language', array(
  208. 'label' => 'Language',
  209. 'multiOptions' => $languageNameList
  210. ));
  211. $this->language->getDecorator('Description')->setOptions(array('placement' => 'APPEND'));
  212. }
  213. else{
  214. $this->addElement('Hidden', 'language', array(
  215. 'value' => $languageNameList
  216. ));
  217. }
  218. // Element: captcha
  219. if( Engine_Api::_()->getApi('settings', 'core')->core_spam_signup ) {
  220. $this->addElement('captcha', 'captcha', array(
  221. 'description' => '_CAPTCHA_DESCRIPTION',
  222. 'captcha' => 'image',
  223. 'required' => true,
  224. 'allowEmpty' => false,
  225. 'captchaOptions' => array(
  226. 'wordLen' => 6,
  227. 'fontSize' => '30',
  228. 'timeout' => 300,
  229. 'imgDir' => APPLICATION_PATH . '/public/temporary/',
  230. 'imgUrl' => $this->getView()->baseUrl() . '/public/temporary',
  231. 'font' => APPLICATION_PATH . '/application/modules/Core/externals/fonts/arial.ttf'
  232. )
  233. ));
  234. }
  235. if( $settings->getSetting('user.signup.terms', 1) == 1 ) {
  236. // Element: terms
  237. $description = Zend_Registry::get('Zend_Translate')->_('I have read and agree to the <a target="_blank" href="%s/help/terms">terms of service</a>.');
  238. $description = sprintf($description, Zend_Controller_Front::getInstance()->getBaseUrl());
  239. $this->addElement('Checkbox', 'terms', array(
  240. 'label' => 'Terms of Service',
  241. 'description' => $description,
  242. 'required' => true,
  243. 'validators' => array(
  244. 'notEmpty',
  245. array('GreaterThan', false, array(0)),
  246. )
  247. ));
  248. $this->terms->getValidator('GreaterThan')->setMessage('You must agree to the terms of service to continue.', 'notGreaterThan');
  249. //$this->terms->getDecorator('Label')->setOption('escape', false);
  250. $this->terms->clearDecorators()
  251. ->addDecorator('ViewHelper')
  252. ->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::APPEND, 'tag' => 'label', 'class' => 'null', 'escape' => false, 'for' => 'terms'))
  253. ->addDecorator('DivDivDivWrapper');
  254. //$this->terms->setDisableTranslator(true);
  255. }
  256. // Init submit
  257. $this->addElement('Button', 'submit', array(
  258. 'label' => 'Continue',
  259. 'type' => 'submit',
  260. 'ignore' => true,
  261. ));
  262. // Set default action
  263. $this->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array(), 'user_signup', true));
  264. }
  265. public function checkPasswordConfirm($value, $passwordElement)
  266. {
  267. return ( $value == $passwordElement->getValue() );
  268. }
  269. public function checkInviteCode($value, $emailElement)
  270. {
  271. $inviteTable = Engine_Api::_()->getDbtable('invites', 'invite');
  272. $select = $inviteTable->select()
  273. ->from($inviteTable->info('name'), 'COUNT(*)')
  274. ->where('code = ?', $value)
  275. ;
  276. if( Engine_Api::_()->getApi('settings', 'core')->getSetting('user.signup.checkemail') ) {
  277. $select->where('recipient LIKE ?', $emailElement->getValue());
  278. }
  279. return (bool) $select->query()->fetchColumn(0);
  280. }
  281. }