Example #1
0
 public static function saveRegisterXML($param)
 {
     $object = kernel::getInstance('SecurityManager');
     $metaData = new BasicMetaData();
     $metaData->set('register', $param);
     MetaManager::getInstance()->storeMeta($object, $metaData);
     return 1;
 }
Example #2
0
 public static function register($params)
 {
     /* verify permissions again */
     $meta = MetaManager::getInstance()->retrieveMeta(kernel::getInstance('SecurityManager'))->getAll();
     if (isset($meta['register']) && $meta['register'] == 'false') {
         return 'unable to register';
     }
     $procManager = ProcManager::getInstance();
     $savedLoginContext = $procManager->getCurrentProcess()->getLoginContext();
     try {
         $name = $params[0];
         $surname = $params[1];
         $username = $params[2];
         $password = $params[3];
         $email = $params[4];
         if (!$name || !$surname || !$username || !$password || !$email) {
             return 'incomplete';
         }
         $myUManager = UMManager::getInstance();
         // check existence
         $exists = false;
         try {
             $myUManager->getUserByName($username);
             $exists = true;
         } catch (EyeNoSuchUserException $e) {
         }
         if ($exists) {
             throw new EyeUserAlreadyExistsException('User with name "' . $username . '" already exists.');
         }
         $meta = new BasicMetaData();
         $meta->set('eyeos.user.email', $email);
         $userIds = MetaManager::getInstance()->searchMeta(new EyeosUser(), $meta);
         if (count($userIds) != 0) {
             throw new EyeUserAlreadyExistsException('User with email "' . $email . '" already exists.');
         }
         //create the user
         $user = $myUManager->getNewUserInstance();
         $user->setName($username);
         $user->setPassword($password, true);
         $user->setPrimaryGroupId($myUManager->getGroupByName(SERVICE_UM_DEFAULTUSERSGROUP)->getId());
         $myUManager->createUser($user);
         //login in the system with new user, if this works, for sure the user exists, even with the
         //most complex and strange errors
         $myUManager = UMManager::getInstance();
         $subject = new Subject();
         $loginContext = new LoginContext('eyeos-login', $subject);
         $cred = new EyeosPasswordCredential();
         $cred->setUsername($username);
         $cred->setPassword($password, true);
         $subject->getPrivateCredentials()->append($cred);
         $loginContext->login();
         //we are logged in, so we are going to change the credentials of login
         $procManager = ProcManager::getInstance();
         $procList = $procManager->getProcessesList();
         $currentProcess = $procManager->getCurrentProcess();
         $procManager->setProcessLoginContext($currentProcess->getPid(), $loginContext);
         foreach ($procList as $key => $value) {
             if (strtolower($value) == 'login') {
                 //we are in another login in execution, this is a refresh, lets see
                 //if the login was correct with the old login.
                 $loginProcess = $procManager->getProcessByPid($key);
                 $procManager->setProcessLoginContext($loginProcess->getPid(), $loginContext);
             }
         }
         // save basic metadata from form
         $userMeta = MetaManager::getInstance()->retrieveMeta($user);
         $userMeta->set('eyeos.user.firstname', strip_tags($name));
         $userMeta->set('eyeos.user.lastname', strip_tags($surname));
         $userMeta->set('eyeos.user.email', $email);
         $userMeta = MetaManager::getInstance()->storeMeta($user, $userMeta);
         return 'success';
     } catch (Exception $e) {
         // ROLLBACK
         // restore login context (root probably)
         $procManager->setProcessLoginContext($procManager->getCurrentProcess()->getPid(), $savedLoginContext);
         ////		delete invalid user created
         //			if (isset($user) && $user instanceof IPrincipal) {
         //				try {
         //					UMManager::getInstance()->deletePrincipal($user);
         //				} catch (Exception $e2) {}
         //			}
         throw $e;
     }
 }
Example #3
0
 public static function resendPassword($params)
 {
     $mail = $params[0];
     $meta = new BasicMetaData();
     $meta->set('eyeos.user.email', $mail);
     $userIds = MetaManager::getInstance()->searchMeta(new EyeosUser(), $meta);
     if (count($userIds) == 0) {
         return 0;
     } else {
         for ($i = 0; $i < count($userIds); $i++) {
             $myUManager = UMManager::getInstance();
             $user = $myUManager->getUserById($userIds[$i]);
             $settings = MetaManager::getInstance()->retrieveMeta($user);
             if ($settings->get('eyeos.user.email') == $mail) {
                 $subject = new Subject();
                 $loginContext = new LoginContext('eyeos-login', $subject);
                 $cred = new EyeosPasswordCredential();
                 $cred->setUsername($user->getName());
                 $cred->setPassword($user->getPassword(), false);
                 $subject->getPrivateCredentials()->append($cred);
                 $loginContext->login();
                 $procManager = ProcManager::getInstance();
                 $lc = $procManager->getCurrentProcess()->getLoginContext();
                 if (!$lc) {
                     $lc = new LoginContext('eyeos-login');
                 }
                 $procManager->setProcessLoginContext($procManager->getCurrentProcess()->getPid(), $loginContext);
                 $password = self::generatePassword();
                 $user->setPassword($password, true);
                 $myUManager->updatePrincipal($user);
                 $procManager->setProcessLoginContext($procManager->getCurrentProcess()->getPid(), $lc);
                 self::sendMailModificationPassword($mail, $user->getName(), $password);
                 return 1;
             }
         }
     }
 }