コード例 #1
0
ファイル: email.php プロジェクト: cepharum/txf
 public function validate($input, $property, model_editor $editor)
 {
     parent::validate($input, $property, $editor);
     if ($input != '') {
         if (!mail::isValidAddress($input)) {
             throw new \InvalidArgumentException(\de\toxa\txf\_L('This is not a valid e-mail address.'));
         }
     }
     return true;
 }
コード例 #2
0
ファイル: ldap_user.php プロジェクト: cepharum/txf
 protected function search($userIdOrLoginName)
 {
     if (mail::isValidAddress($userIdOrLoginName)) {
         $match = $this->server->searchSub(sprintf($this->setup->read('searchByMail', '(mailPublic=%s)'), $userIdOrLoginName), $this->setup->basedn);
     } else {
         if (strpos($userIdOrLoginName, '=') !== false) {
             $match = $this->server->searchBase($userIdOrLoginName);
         } else {
             if (ctype_digit($userIdOrLoginName)) {
                 $match = $this->server->searchSub(sprintf($this->setup->read('searchById', '(uidNumber=%d)'), $userIdOrLoginName), $this->setup->basedn);
             } else {
                 if (uuid::isValid($userIdOrLoginName)) {
                     $match = $this->server->searchSub(sprintf($this->setup->read('searchByUuid', '(entryUUID=%s)'), $userIdOrLoginName), $this->setup->basedn);
                 } else {
                     $match = $this->server->searchSub(sprintf($this->setup->read('searchByLogin', '(uid=%s)'), $userIdOrLoginName), $this->setup->basedn);
                 }
             }
         }
     }
     if ($match->current()) {
         $this->userDN = $match->current()->getDN();
         return $this;
     }
     throw new unauthorized_exception('no such user', unauthorized_exception::USER_NOT_FOUND);
 }
コード例 #3
0
ファイル: manager.php プロジェクト: cepharum/txf
 /**
  * Processes input while editing/adding user record.
  *
  * @param sql_user $provider provider used on creating new user record
  * @param int|false $userId ID of user to edit, false/0 on adding new user
  * @return sql_user|null edited or created user, null if creating user failed
  */
 protected function processInputOnEditing($provider, $userId)
 {
     if ($userId) {
         $user = user::load($userId);
         $userData = array('id' => $user->getID(), 'loginname' => $user->getLoginName(), 'name' => $user->getName(), 'email' => $user->getProperty('email'));
     } else {
         $user = null;
         $userData = array();
     }
     $form = $this->getForm($userData);
     if ($form->hasInput()) {
         if (input::vget('submit') == 'cancel') {
             txf::redirectTo($this->getUrls()->list);
         }
         /*
          * read in and normalize all provided information on user
          */
         $loginName = $user ? $userData['loginname'] : trim(input::vget('loginname'));
         $name = trim(input::vget('name'));
         $email = trim(input::vget('email'));
         $passwordA = trim(input::vget('password'));
         $passwordB = trim(input::vget('repeat'));
         /*
          * validate all information on user
          */
         if ($loginName === '') {
             $form->setRowError('loginname', \de\toxa\txf\_L('Provide login name of user!'));
         } else {
             if (strlen($loginName) > 64) {
                 $form->setRowError('loginname', \de\toxa\txf\_L('Provided login name is too long!'));
             }
         }
         if ($name && strlen($name) > 128) {
             $form->setRowError('loginname', \de\toxa\txf\_L('Provided full name is too long!'));
         }
         if ($email) {
             if (strlen($name) > 128) {
                 $form->setRowError('loginname', \de\toxa\txf\_L('Provided mail address is too long!'));
             } else {
                 if (!\de\toxa\txf\mail::isValidAddress($email)) {
                     $form->setRowError('email', \de\toxa\txf\_L('Provided mail address is invalid!'));
                 }
             }
         }
         // validate optionally provided password
         if (!$user || $passwordA || $passwordB) {
             if ($passwordA === '' || $passwordB === '') {
                 if ($user) {
                     $form->setRowError('password', \de\toxa\txf\_l('Provide new password twice for excluding typos.'));
                 } else {
                     $form->setRowError('password', \de\toxa\txf\_l('Provide password of new user and repeat for excluding typos.'));
                 }
             } else {
                 if ($passwordA !== $passwordB) {
                     $form->setRowError('password', \de\toxa\txf\_L('Doubly entered passwords don\'t match.'));
                 } else {
                     try {
                         if (is_callable($this->passwordValidator)) {
                             call_user_func($this->passwordValidator, $passwordA);
                         } else {
                             $this->passwordValidatorDefault($passwordA);
                         }
                     } catch (\InvalidArgumentException $e) {
                         $form->setRowError('password', $e->getMessage());
                     }
                 }
             }
         }
         /*
          * save changes to datasource
          */
         $hasError = $form->hasAnyRowError();
         if (!$hasError) {
             exception::enterSensitive();
             if ($user) {
                 try {
                     $user->datasource()->transaction()->wrap(function (datasource\connection $conn) use($user, $name, $email, $passwordA) {
                         $user->setProperty('name', $name);
                         $user->setProperty('email', $email);
                         if (trim($passwordA) !== '') {
                             $user->changePassword($passwordA);
                             if ($user->getUUID() === user::current()->getUUID()) {
                                 try {
                                     user::current()->authenticate($passwordA);
                                 } 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');
                                 }
                             }
                         }
                         view::flash(\de\toxa\txf\_L('Successfully changed information on selected user.'));
                         return true;
                     });
                 } catch (\Exception $e) {
                     $hasError = true;
                     view::flash(\de\toxa\txf\_L('Failed to save information on user in datasource.'), 'error');
                 }
             } else {
                 try {
                     $user = $provider->create(array('loginname' => $loginName, 'name' => $name, 'password' => $passwordA, 'email' => $email, 'lock' => ''));
                     view::flash(\de\toxa\txf\_L('Successfully created new user.'));
                 } catch (\Exception $e) {
                     $hasError = true;
                     view::flash(\de\toxa\txf\_L('Failed to create new user record in datasource.'), 'error');
                 }
             }
             exception::leaveSensitive();
         }
         if (!$hasError) {
             txf::redirectTo($this->getUrls()->list);
         }
     }
     return $user;
 }