class loginController extends ActionController { function index() { require_once 'include.php'; //Element du formulaire require_once 'HTML'.DIRECTORY_SEPARATOR.'QuickForm.php'; require_once 'HTML/QuickForm/CAPTCHA/Equation.php'; $form = new HTML_QuickForm('login','post',$_SERVER['PHP_SELF']); $form->addElement('text', 'login', 'Login', array('size' => '15')); $form->addElement('password', 'password', 'Mot de passe', array('size' => '15', 'name' => 'password', 'id' => 'password')); $options = array('sessionVar' => basename(__FILE__, '.php')); $captcha_question =& $form->addElement('CAPTCHA_Equation', 'captcha_question', 'Can you resolve this?', $options); if (PEAR::isError($captcha_question)) { echo $captcha_question->getMessage(); exit; } $captcha_answer =& $form->addElement('text', 'captcha', 'Enter the answer'); $form->addRule('captcha', 'Enter the answer to the equation', 'required', null, 'client'); $form->addRule('captcha', 'What you entered didn\'t match the equation', 'CAPTCHA', $captcha_question); $form->addElement('hidden', 'module', 'login'); $form->addElement('hidden', 'action', 'index'); $form->addElement('submit', 'submit', 'Connexion', array('class' => 'button')); if($form->validate()) { $user = DB_DataObject::factory('Users'); $user->setLogin($form->exportValue('login')); if(($r=$user->checkLogin($form->exportValue('password')))==LOGIN_SUCCESS) { HTTP_Session2::set('user_logged', serialize($user)); $this->redirect(KL_DEFAULT_MODULE, KL_DEFAULT_ACTION); } else { if($r==LOGIN_MAX_ATTEMPTS_EXCEEDED) { $this->Messager = Messager::setMessage('Trop de tentative : compte bloqué !'); $form->getElement('password')->setValue(''); } else { $this->Messager = Messager::setMessage('Utilisateur ou mot de passe incorrect'); $form->getElement('password')->setValue(''); } } } //Template $this->form = $form; } ///........