* @license PHP License * @package WB * @subpackage content */ /** * Load classes */ WBClass::load('WBContent'); /** * Content component: User_Login * * @version 1.0.0 * @package WB * @subpackage content */ class WBContent_User_Login extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'process' => 'state' ); /** * run * * run component * * @return array parameter list */ public function run() { $process = strtolower($this->config['process']); switch ($process) { case 'login': $this->config['process'] = 'state'; // fall through case 'register': case 'activate': case 'approverenewpassword': case 'renewpassword': if ($this->user->isAuthenticated()) { $this->loadTemplates('auth'); $this->config['process'] = 'state'; break; } $this->processForm($process, null); break; case 'password': if (!$this->user->isAuthenticated()) { $this->loadTemplates('anon'); $this->config['process'] = 'login'; break; } $this->processForm('password', null); break; case 'logout': if ($this->user->isAuthenticated()) { $this->user->logout(); WBClass::load('WBService'); WBService::addEvent('logout'); } $this->loadTemplates('anon'); break; default: if ($this->user->isAuthenticated()) { $this->loadTemplates('auth'); } else { $this->loadTemplates('anon'); } $this->config['process'] = 'state'; break; } return $this->config; } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { if ($this->user->isAuthenticated()) { $this->tmpl->addGlobalVars($this->user->getData(), 'user_current_'); } return $this->tmpl->getParsedTemplate('snippet'); } /** * login user * */ public function onLoginValid($form, $values) { $this->user->login($values); if ($this->user->isAuthenticated()) { WBClass::load('WBService'); WBService::addEvent('login'); $this->loadTemplates('auth'); return false; } return true; } /** * set new password * * * @param patForms $form * @param array $values * @return bool always true */ public function onPasswordValid($form, $values) { $reg = WBClass::create('WBUser_Register'); /** @var WBUser_Register */ $reg->load($this->user->getId()); $reg->setPassword($values['password']); return true; } /** * register user account * * Call user register function * * @param patForms $form * @param array $values * @return bool always true */ public function onRegisterValid($form, $values) { $reg = WBClass::create('WBUser_Register'); /** @var WBUser_Register */ $reg->register($values); return true; } /** * init password renewal * * @param patForms $form * @param array $values * @return bool always true */ public function onRenewpasswordValid($form, $values) { $reg = WBClass::create('WBUser_Register'); /** @var WBUser_Register */ $reg->renewPassword($values); return true; } /** * approve password renewal * * set new password for user * * @param patForms $form * @param array $values * @return bool always true */ public function onApproverenewpasswordValid($form, $values) { $reg = WBClass::create('WBUser_Register'); /** @var WBUser_Register */ if (!$reg->approvePasswordRenewal($values['code'])) { // this should never happen return true; } $reg->setPassword($values['password']); return true; } /** * merge form parameters * * Mend "method" (POST) * * @param array $param list of form parameters * @return bool */ protected function mergeFormParameters(&$params) { $params['method'] = 'post'; return true; } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'user/login'; } /** * 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; } } } ?>