示例#1
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new Monkeys_Ldap();
     }
     return self::$_instance;
 }
示例#2
0
 protected function _validateTargetUser()
 {
     if (Zend_Registry::isRegistered('targetUser')) {
         // used by unit tests to inject the target user
         $this->targetUser = Zend_Registry::get('targetUser');
     } else {
         $userId = $this->_getParam('userid');
         if (is_null($userId)) {
             $this->targetUser = $this->user;
         } elseif ($this->_getParam('userid') == 0) {
             $users = new Users_Model_Users();
             $this->targetUser = $users->createRow();
         } else {
             if ($userId != $this->user->id && $this->user->role != Users_Model_User::ROLE_ADMIN) {
                 $this->_helper->FlashMessenger->addMessage($this->view->translate('Error: Invalid user id'));
                 $this->_redirect('profile/edit');
             }
             $users = new Users_Model_Users();
             $this->targetUser = $users->getRowInstance($userId);
             if ($this->_config->ldap->enabled) {
                 $ldap = Monkeys_Ldap::getInstance();
                 $ldapUserData = $ldap->get("cn={$this->targetUser->username},{$this->_config->ldap->baseDn}");
                 $this->targetUser->overrideWithLdapData($ldapUserData, true);
             }
         }
     }
     $this->view->targetUser = $this->targetUser;
 }
 public function deleteAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNeverRender(true);
     if ($this->_config->ldap->enabled && $this->_config->ldap->keepRecordsSynced) {
         $ldap = Monkeys_Ldap::getInstance();
         $ldap->delete($this->targetUser);
     }
     $this->targetUser->delete();
     echo $this->view->translate('User has been deleted successfully');
 }
    public function deleteAction()
    {
        if ($this->user->role == Users_Model_User::ROLE_ADMIN || $this->_config->ldap->enabled && !$this->_config->ldap->keepRecordsSynced) {
            throw new Monkeys_AccessDeniedException();
        }
        $mail = self::getMail();
        $mail->setFrom($this->_config->email->supportemail);
        $mail->addTo($this->_config->email->supportemail);
        $mail->setSubject('Community-ID user deletion');
        $userFullname = $this->user->getFullName();
        $reasonsChecked = array();
        if ($this->_getParam('reason_test')) {
            $reasonsChecked[] = 'This was just a test account';
        }
        if ($this->_getParam('reason_foundbetter')) {
            $reasonsChecked[] = 'I found a better service';
        }
        if ($this->_getParam('reason_lackedfeatures')) {
            $reasonsChecked[] = 'Service lacked some key features I needed';
        }
        if ($this->_getParam('reason_none')) {
            $reasonsChecked[] = 'No particular reason';
        }
        if ($reasonsChecked) {
            $reasonsChecked = implode("\r\n", $reasonsChecked);
        } else {
            $reasonsChecked = 'None (no checkbox was ticked).';
        }
        $comment = $this->_getParam('reason_comments');
        $body = <<<EOT
Dear Admin:

The user {$userFullname} has deleted his account, giving the following feedback:

Reasons checked:
{$reasonsChecked}

Comment:
{$comment}
EOT;
        $mail->setBodyText($body);
        try {
            $mail->send();
        } catch (Zend_Mail_Exception $e) {
            if ($this->_config->logging->level == Zend_Log::DEBUG) {
                $this->_helper->FlashMessenger->addMessage($this->view->translate('Account was deleted, but feedback form couldn\'t be sent to admins'));
            }
        }
        $users = $this->_getUsers();
        $users->deleteUser($this->user);
        if ($this->_config->ldap->enabled && $this->_config->ldap->keepRecordsSynced) {
            $ldap = Monkeys_Ldap::getInstance();
            $ldap->delete($this->user);
        }
        Zend_Auth::getInstance()->clearIdentity();
        $this->_helper->FlashMessenger->addMessage($this->view->translate('Your acccount has been successfully deleted'));
        $this->_redirect('');
    }
示例#5
0
 public function getUserWithUsername($username, $generateNewIfMissing = false, Zend_View $view = null)
 {
     $select = $this->select()->where('username=?', $username);
     $user = $this->fetchRow($select);
     $ldapOptions = Zend_Registry::get('config')->ldap;
     if ($ldapOptions->enabled) {
         $ldap = Monkeys_Ldap::getInstance();
         try {
             $ldapUserData = $ldap->get("cn={$username},{$ldapOptions->baseDn}");
         } catch (Exception $e) {
             if ($e->getCode() == Monkeys_Ldap::EXCEPTION_SEARCH) {
                 return false;
             }
             throw $e;
         }
         if ($user) {
             // this fields are always overridden from what comes from LDAP, because they might change
             $user->overrideWithLdapData($ldapUserData);
         } else {
             // user is registered in LDAP, but not in CID's db
             $user = $this->createRow();
             $user->registration_date = date('Y-m-d');
             $user->overrideWithLdapData($ldapUserData);
             if ($user->role != Users_Model_User::ROLE_ADMIN) {
                 preg_match('#(.*)/users/login/authenticate#', Zend_OpenId::selfURL(), $matches);
                 $user->generateOpenId($matches[1]);
             }
             if ($generateNewIfMissing) {
                 $user->save();
                 $profileId = $user->createDefaultProfile($view);
                 $user->generatePersonalInfo($ldapUserData, $profileId);
             }
         }
     }
     return $user;
 }
 public function accepteulaAction()
 {
     $users = new Users_Model_Users();
     if ($this->_request->getParam('token') == '' || !($user = $users->getUserWithToken($this->_request->getParam('token')))) {
         $this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid token'));
         $this->_redirect('');
         return;
     }
     $user->role = Users_Model_User::ROLE_REGISTERED;
     $user->accepted_eula = 1;
     $user->registration_date = date('Y-m-d');
     $user->token = '';
     if ($this->_config->ldap->enabled) {
         $ldap = Monkeys_Ldap::getInstance();
         $ldap->add($user);
         // clear unencrypted password
         $user->setPassword('');
     }
     $user->save();
     $auth = Zend_Auth::getInstance();
     $auth->getStorage()->write($user);
     $this->_redirect('/users/profile');
 }