Exemple #1
0
 public function postValidate()
 {
     if (empty($this->username)) {
         $this->getErrorStack()->add("username", "notnull");
     } else {
         $oQuery = FlexiModelUtil::getDBQuery("ModxWebUsers")->where("username=?", array($this->username));
         if (!empty($this->id)) {
             $oQuery->addWhere("id<>?", array($this->id));
         }
         //echo $oQuery->getSQLQuery();
         //echo var_dump($this->username);
         $oResult = $oQuery->fetchOne();
         if ($oResult !== false) {
             $this->getErrorStack()->add("username", "duplicate");
         }
     }
     if (empty($this->password)) {
         $this->getErrorStack()->add("password", "notnull");
     }
 }
 /**
  * Get Doctrine query object
  * @param string name
  * @param string path (optional)
  * @return Doctrine_Record
  */
 public function getDBQuery($asName, $asPath = null)
 {
     $sPath = empty($asPath) ? $this->sModulePath : $asPath;
     return FlexiModelUtil::getDBQuery($asName, $sPath);
 }
 public function updateUser($iId, $sUserName, $sFullName = null, $sPassword = null, $aOptions = array(), $aGroups = array())
 {
     $this->checkMe();
     global $modx;
     $oModel = $this->getUserById($iId);
     $oModel->set("username", $sUserName);
     $oProfile = $oModel->getOne("Profile");
     if (is_null($oProfile)) {
         $oProfile = $oModel->addOne("Profile");
     }
     if ($sFullName != null) {
         $oProfile->set("fullname", $sFullName);
     }
     if ($sPassword != null) {
         $oMail = FlexiMailer::getInstance();
         $oMail->setFrom(FlexiConfig::$sSupportEmail);
         $oMail->mail($sSubject, $sMessage, $sEmail);
         $oModel->set("password", md5($sPassword));
     }
     if (isset($aOptions["email"])) {
         $oProfile->set("email", $aOptions["email"]);
     }
     $oModel->save();
     $aGroupId = array();
     foreach ($aGroups as $sGroup) {
         $oGroupNameModel = $modx->getObject("modUserGroup", array("name" => $sGroup));
         if (is_null($oGroupNameModel)) {
             throw new FlexiException("No group by: " . $sGroup, ERROR_EOF);
         }
         $iGroupNameId = $oGroupNameModel->get("id");
         $aGroupId[] = $iGroupNameId;
         $oGroupModel = $modx->getObject("modWebGroupMember", array("webgroup" => $iGroupNameId, "webuser" => $iId));
         if (is_null($oGroupModel)) {
             $oGroupModel = $modx->newObject("modWebGroupMember");
             $oGroupModel->set("webuser", $iId);
             $oGroupModel->set("webgroup", $iGroupNameId);
             $oGroupModel->save();
         }
     }
     if (count($aGroups) > 0) {
         //clearing all other groups
         $sGroupId = implode(",", $aGroupId);
         FlexiModelUtil::getDBQuery("ModxWebGroups", "flexiphp/base/FlexiAdminGroup")->delete("ModxWebGroups")->where("webgroup not in (" . $sGroupId . ")")->execute();
     }
     return $oModel;
 }
 public function getUserByLoginId($asLoginId, $sUserType = "user")
 {
     static $oUser = null;
     if ($oUser != null && $oUser->username == $asLoginId) {
         return $oUser;
     }
     $oUser = FlexiModelUtil::getDBQuery("ModxWebUsers u", "flexiphp/base/FlexiAdminUser")->where("u.username=?", array($asLoginId))->fetchOne();
     if ($oUser == null || $oUser === false) {
         return null;
     }
     return $oUser;
 }
 public function getUserById($iId)
 {
     $oModel = FlexiModelUtil::getDBQuery("ModxWebUsers", "flexiphp/base/FlexiAdminUser")->where("id=?", array($iId))->fetchOne();
     if ($oModel === false) {
         throw new FlexiException("User not found: " . $iId, ERROR_EOF);
     }
     return $oModel;
 }
 public function verifyUser($iId, $sCode)
 {
     $oModel = FlexiModelUtil::getDBQuery("ModxWebUsers", "flexiphp/base/FlexiAdminUser")->where("id=?", array($iId))->fetchOne();
     if ($oModel === false) {
         return false;
     }
     //echo "Comparing: " . $sCode . " vs " . $oModel->Extend->verifycode;
     try {
         //echo "same :)";
         if ($oModel->Extend->verifycode == $sCode) {
             $oModel->Extend->verified = 1;
             $oModel->Extend->replace();
             return true;
         }
     } catch (Exception $e) {
         //echo "error: " . $e->getMessage();
         FlexiLogger::error(__METHOD__, "Unable to save User verification");
         return false;
     }
 }