예제 #1
0
 public function createUserRecord(array $spotUser)
 {
     $result = new Dto_FormResult();
     $spotUser['userid'] = false;
     /*
      * Create a random password for this user
      */
     $spotUser['newpassword1'] = substr(Services_User_Util::generateUniqueId(), 1, 9);
     $spotUser['newpassword2'] = $spotUser['newpassword1'];
     /*
      * Validate several properties of the user, we share
      * this code with the user editor
      */
     $result->mergeResult($this->validateUserRecord($spotUser, false));
     /*
      * Make sure no other user exists with the same username
      */
     $userIdForName = $this->_userDao->findUserIdForName($spotUser['username']);
     if (!empty($userIdForName)) {
         $result->addError(sprintf(_("'%s' already exists"), $spotUser['username']));
     }
     # if
     if ($result->isSuccess()) {
         # Create a private and public key pair for this user
         $spotSigning = Services_Signing_Base::factory();
         $userKey = $spotSigning->createPrivateKey($this->_settings->get('openssl_cnf_path'));
         $spotUser['publickey'] = $userKey['public'];
         $spotUser['privatekey'] = $userKey['private'];
         # Actually add the user
         $spotUser['userid'] = $this->addUser($spotUser);
         /*
          * We assume the user was successfully added, all validation is done at
          * a higher level, and addUser() will throw an exception if something is
          * seriously wrong
          */
         $result->addData('userid', $spotUser['userid']);
         $result->addData('username', $spotUser['username']);
         $result->addData('password', $spotUser['newpassword1']);
         $result->addData('userrecord', $spotUser);
         $result->addInfo(sprintf(_("User <strong>&quot;%s&quot;</strong> successfully added"), $spotUser['username']));
         $result->addInfo(sprintf(_("Password: <strong>&quot;%s&quot;</strong>"), $spotUser['newpassword1']));
         $result->setResult('success');
     }
     # if
     return $result;
 }