示例#1
0
文件: 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'));
 }
示例#2
0
文件: manager.php 项目: cepharum/txf
 /**
  * Processes input of widget updating its internal state.
  *
  * @throws http_exception on trying to use widget without authorization
  * @return $this current instance
  */
 public function processInput()
 {
     if (!$this->isUserAuthorized()) {
         throw new http_exception(403, \de\toxa\txf\_L('You must not manage users!'));
     }
     $provider = user::getProvider();
     if (!$provider instanceof sql_user) {
         throw new http_exception(400, \de\toxa\txf\_L('This manager is suitable for managing SQL-based users, only!'));
     }
     list($action, $userId) = $this->detectMode();
     if ($this->isListing()) {
         $this->getBrowser()->processInput();
     } else {
         switch ($action) {
             case 'edit':
             case 'add':
                 $this->processInputOnEditing($provider, $userId);
                 break;
             case 'delete':
                 if ($userId === user::current()->getID()) {
                     throw new http_exception(403, \de\toxa\txf\_L('Deleting current user account rejected.'));
                 }
                 user::load($userId)->delete();
                 txf::redirectTo($this->getUrls()->list);
                 break;
             default:
                 // TODO implement all else actions (lock, unlock, ...)
                 txf::redirectTo($this->getUrls()->list);
         }
     }
     return $this;
 }
示例#3
0
 public function performDelete()
 {
     if (!user::current()->isAuthenticated()) {
         throw new http_exception(403);
     }
     $this->prepareControl();
     try {
         $this->getSelectedItem()->delete();
     } catch (datasource_exception $e) {
         view::flash(\de\toxa\txf\_L('Failed deleting selected item.'), 'error');
     } catch (\RuntimeException $e) {
         view::flash(\de\toxa\txf\_L('Selected item does not exist (anymore).'), 'error');
     }
     txf::redirectTo($this->getUrls()->list);
 }
示例#4
0
文件: editor.php 项目: cepharum/txf
 /**
  * Indicates whether editor is marked editable.
  *
  * @return bool
  */
 public function isEditable()
 {
     return user::current()->isAuthenticated() && $this->may['edit'];
 }
示例#5
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;
 }
示例#6
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;
 }