* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBAjax' , 'WBAjax_User'); /** * AJAX implementation: User_Login * * @version 0.1.0 * @package WB * @subpackage base */ class WBAjax_User_Login extends WBAjax_User { /** * Register * * handle requests */ protected function register() { return $this->doProcessForm('register'); } /** * Login * * handle requests */ protected function login() { return $this->doProcessForm('login'); } protected function logout() { if ($this->user->isAuthenticated()) { $this->user->logout(); WBClass::load('WBService'); WBService::addEvent('logout'); } $this->loadTemplates('anon'); return $this->tmpl->getParsedTemplate('snippet'); } /** * Callback on login * * Login user and add event * * @param patForms * @param array * @return bool continue or stop here */ public function onLoginValid($form, $values) { $this->user->login($values); if (!$this->user->isAuthenticated()) { return true; } WBClass::load('WBService'); WBService::addEvent('login'); $this->loadTemplates('auth'); return false; } /** * Renew password * * handle requests */ protected function renewPassword() { return $this->doProcessForm('renewPassword'); } /** * Actually call form processor * * Dispatcher to simplify request methods. * * @param string form's name * @return string html */ private function doProcessForm($name = 'login') { if ($this->user->isAuthenticated()) { $this->loadTemplates('auth'); return $this->tmpl->getParsedTemplate('snippet'); } $this->loadTemplates($name); $this->processForm($name); return $this->tmpl->getParsedTemplate('snippet'); } /** * merge form parameters * * This allows to overwrite default form parameters * * @param array $param list of form parameters * @return bool */ protected function mergeFormParameters(&$params) { // $params['onsubmit'] = 'return user' return true; } /** * Add form rules to just created form * * - login * - registrations * - password changes * - password renewal request and approval * * @param patForms $form object * @param string name of the xml- and template-filename * @param array $elements list of elements current form * @return bool true on success */ protected function insertFormRules(&$form, $name, $elements) { if ($name == 'login') { $loginRule = patForms::createRule('UserLogin'); $form->addRule($loginRule, PATFORMS_RULE_AFTER_VALIDATION); return true; } if ($name == 'register' || $name == 'approverenewpassword' || $name == 'password') { $retypeRule = patForms::createRule('Retype'); /** @var $retypeRule patForms_Rule_Retype */ $retypeRule->setFieldnames('password', 'passwordretype'); $form->addRule($retypeRule, PATFORMS_RULE_AFTER_VALIDATION); return true; } if ($name == 'renewpassword') { $findUserRule = patForms::createRule('UserFind'); $form->addRule($findUserRule, PATFORMS_RULE_AFTER_VALIDATION); return true; } } }