Login.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. class Application_Form_Login extends Zend_Form
  3. {
  4. public function init()
  5. {
  6. $CC_CONFIG = Config::getConfig();
  7. // Set the method for the display form to POST
  8. $this->setMethod('post');
  9. $this->addElement('hash', 'csrf', array(
  10. 'salt' => 'unique'
  11. ));
  12. $this->setDecorators(array(
  13. array('ViewScript', array('viewScript' => 'form/login.phtml'))
  14. ));
  15. // Add username element
  16. $this->addElement('text', 'username', array(
  17. 'label' => _('Username:'),
  18. 'class' => 'input_text',
  19. 'required' => true,
  20. 'value' => (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1)?'admin':'',
  21. 'filters' => array('StringTrim'),
  22. 'validators' => array(
  23. 'NotEmpty',
  24. ),
  25. 'decorators' => array(
  26. 'ViewHelper'
  27. )
  28. ));
  29. // Add password element
  30. $this->addElement('password', 'password', array(
  31. 'label' => _('Password:'),
  32. 'class' => 'input_text',
  33. 'required' => true,
  34. 'value' => (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1)?'admin':'',
  35. 'filters' => array('StringTrim'),
  36. 'validators' => array(
  37. 'NotEmpty',
  38. ),
  39. 'decorators' => array(
  40. 'ViewHelper'
  41. )
  42. ));
  43. $locale = new Zend_Form_Element_Select("locale");
  44. $locale->setLabel(_("Language:"));
  45. $locale->setMultiOptions(Application_Model_Locale::getLocales());
  46. $locale->setDecorators(array('ViewHelper'));
  47. $this->addElement($locale);
  48. $this->setDefaults(array(
  49. "locale" => Application_Model_Locale::getUserLocale()
  50. ));
  51. if (Application_Model_LoginAttempts::getAttempts($_SERVER['REMOTE_ADDR']) >= 3) {
  52. $this->addRecaptcha();
  53. }
  54. // Add the submit button
  55. $this->addElement('submit', 'submit', array(
  56. 'ignore' => true,
  57. 'label' => _('Login'),
  58. 'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center',
  59. 'decorators' => array(
  60. 'ViewHelper'
  61. )
  62. ));
  63. }
  64. public function addRecaptcha()
  65. {
  66. $pubKey = '6Ld4JsISAAAAAIxUKT4IjjOGi3DHqdoH2zk6WkYG';
  67. $privKey = '6Ld4JsISAAAAAJynYlXdrE4hfTReTSxYFe5szdyv';
  68. $params= array('ssl' => true);
  69. $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey, $params);
  70. $captcha = new Zend_Form_Element_Captcha('captcha',
  71. array(
  72. 'label' => _('Type the characters you see in the picture below.'),
  73. 'captcha' => 'ReCaptcha',
  74. 'captchaOptions' => array(
  75. 'captcha' => 'ReCaptcha',
  76. 'service' => $recaptcha,
  77. 'ssl' => 'true'
  78. )
  79. )
  80. );
  81. $this->addElement($captcha);
  82. }
  83. }