예제 #1
0
파일: url.php 프로젝트: cepharum/txf
 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;
 }
예제 #2
0
파일: login.php 프로젝트: cepharum/txf
 /**
  * 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;
 }
예제 #3
0
파일: manager.php 프로젝트: cepharum/txf
 /**
  * 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;
     }
 }
예제 #4
0
파일: password.php 프로젝트: cepharum/txf
 /**
  * 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;
 }
예제 #5
-1
파일: logout.php 프로젝트: cepharum/txf
 /**
  * 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'));
 }