public function validate($input, $property, model_editor $editor) { parent::validate($input, $property, $editor); if ($input != '') { if (!url::isFile($input)) { throw new \InvalidArgumentException(\de\toxa\txf\_L('This is not a valid URL.')); } if ($this->absolute && url::isRelative($input)) { throw new \InvalidArgumentException(\de\toxa\txf\_L('This URL must be absolute. Include scheme e.g. http://www.example.com/!')); } } return true; }
/** * Processes input of widget updating its internal state. * * @return $this current instance */ public function processInput() { if (user::current()->isAuthenticated()) { view::flash(\de\toxa\txf\_L('You are logged in, already.')); $this->redirect(); } $form = $this->getForm(); if ($form->hasInput()) { if (input::vget('submit') == 'cancel') { $this->redirect(); } $username = input::vget('name'); if ($username) { try { user::setCurrent(user::load($username), input::vget('token')); $this->redirect(); } catch (unauthorized_exception $ex) { if ($ex->isAccountLocked()) { if ($this->resendUnlockMailUrl) { view::flash(sprintf(\de\toxa\txf\_L('Your account is locked! <a href="%s">Resend unlock mail now.</a>'), sprintf($this->resendUnlockMailUrl, $ex->getUser()->getID())), 'error'); } else { view::flash(sprintf(\de\toxa\txf\_L('Your account is locked!')), 'error'); } } else { sleep(3); if ($ex->isUserNotFound()) { view::flash(\de\toxa\txf\_L('User does not exist.'), 'error'); } else { view::flash(\de\toxa\txf\_L('Authentication failed.'), 'error'); } } } } else { view::flash(\de\toxa\txf\_L('Provide login name and password!')); } } else { $session =& txf::session(); $referrer = input::vget('referrer'); $session['referrer'] = url::isRelative($referrer) ? $referrer : null; } return $this; }
/** * Adds asset to current view. * * This method is considered to be used to append asset files like javascript * code or CSS definitions to current output. * * @param string $id ID used to identify asset after adding to current view * @param string $source URL/address of asset, omit to drop existing asset * @param enum $type one of view::ASSET_TYPE_* constants * @param boolean $blnIfNotExists if true, asset is added unless existing already * @param string|true $insertBeforeId ID of existing asset this will be inserted before * omit to append at end (default if selected asset is missing), * provide true or "*" to prepend before first existing asset * @return void */ public static function addAsset($id, $source, $type, $insertBeforeId = null, $blnIfNotExists = false) { if (trim($id) === '') { throw new \InvalidArgumentException('missing asset id'); } if (trim($source) === null) { unset(static::current()->assets[$id]); } else { if ($blnIfNotExists && array_key_exists($id, static::current()->assets)) { return; } if (url::isRelative($source)) { $source = application::current()->relativePrefix($source); } $newAsset = array('url' => $source, 'type' => $type); if ($insertBeforeId !== null) { if ($insertBeforeId === '*' || $insertBeforeId === true) { $offset = 0; } else { $offset = array_search($insertBeforeId, array_keys(static::current()->assets)); } if ($offset !== false) { static::current()->assets = array_merge(array_slice(static::current()->assets, 0, max(0, $offset - 1), true), array($id => $newAsset), array_slice(static::current()->assets, $offset, count(static::current()->assets) - $offset, true)); return; } } static::current()->assets[$id] = $newAsset; } }
/** * Processes input of widget updating its internal state. * * @return $this current instance */ public function processInput() { if (!user::current()->isAuthenticated()) { view::flash(\de\toxa\txf\_L('You must be logged in.')); $this->redirect(); } $form = $this->getForm(); if ($form->hasInput()) { if (input::vget('submit') == 'cancel') { $this->redirect(); } $passwordOld = trim(input::vget('old')); $passwordNewA = trim(input::vget('new')); $passwordNewB = trim(input::vget('repeat')); if ($passwordOld === '') { $form->setRowError('old', \de\toxa\txf\_L('Provide current password!')); } if ($passwordNewA === '' || $passwordNewB === '') { $form->setRowError('new', \de\toxa\txf\_l('Provide new password twice for excluding typos.')); } else { if ($passwordNewA !== $passwordNewB) { $form->setRowError('new', \de\toxa\txf\_L('Doubly entered passwords don\'t match.')); } else { try { if (is_callable($this->passwordValidator)) { call_user_func($this->passwordValidator, $passwordNewA); } else { $this->passwordValidatorDefault($passwordNewA); } } catch (\InvalidArgumentException $e) { $form->setRowError('new', $e->getMessage()); } } } exception::enterSensitive(); if (!$form->hasAnyRowError()) { try { $user = user::load(user::current()->getID()); try { $user->authenticate($passwordOld); } catch (unauthorized_exception $e) { $form->setRowError('old', \de\toxa\txf\_L('Authenticating request using old password failed.')); } } catch (unauthorized_exception $e) { $form->setRowError('old', \de\toxa\txf\_L('Current user isn\'t available.')); } } $hasError = false; if (!$form->hasAnyRowError()) { try { user::current()->changePassword($passwordNewA); view::flash(\de\toxa\txf\_L('Password has been changed successfully.')); try { user::current()->authenticate($passwordNewA); } catch (unauthorized_exception $e) { view::flash(\de\toxa\txf\_L('Updating current session for using changed password failed. Probably you need to login, again.'), 'error'); } } catch (\RuntimeException $e) { $hasError = true; view::flash(\de\toxa\txf\_L('Your input is okay, but changing password failed nevertheless.'), 'error'); } } exception::leaveSensitive(); if (!$hasError && !$form->hasAnyRowError()) { $this->redirect(); } } else { $session =& txf::session(); $referrer = input::vget('referrer'); $session['referrer'] = url::isRelative($referrer) ? $referrer : null; } return $this; }
/** * Processes input of widget updating its internal state. * * @return widget current instance */ public function processInput() { if (user::current()->isAuthenticated()) { user::dropCurrent(); } view::flash(\de\toxa\txf\_L('You logged out successfully.')); $referrer = input::vget('referrer'); $referrer = url::isRelative($referrer) ? $referrer : null; txf::redirectTo(\de\toxa\txf\_1($referrer, 'home')); }