/** * Get logged in user * @return FlexiLoginUserModel */ public function getLoggedInUser() { if (is_null($this->oUser)) { $oUser = FlexiModelUtil::getModelInstance("FlexiLoginUserModel", "flexiphp/base/Flexi"); global $modx; $oUser->iUserId = $modx->getLoginUserID(); //var_dump("userid: " . $oUser->iUserId); //TODO demo //$oUser->iUserId = 1; $oUserInfo = $modx->getWebUserInfo($oUser->iUserId); //var_dump($oUserInfo); //var_dump($oUserInfo); $oUser->sUserFullName = $oUserInfo["fullname"]; $oUser->sUserName = $oUserInfo["username"]; $oUser->sPassword = $oUserInfo["password"]; //var_dump($modx->getWebUserInfo(1)); $this->setUser($oUser); return $this->getUser(); } return null; }
public function getModelInstance($asName, $asPath = null) { $sPath = empty($asPath) ? $this->sModulePath : $asPath; return FlexiModelUtil::getModelInstance($asName, $sPath); }
/** * Api to create user * @param String $sUserName * @param String $sPassword * @param String $sFullName * @param array of Strings $aGroups * @param array $aOptions * @return Doctrine_Record */ public function createUser($sUserName, $sPassword, $sFullName = "", $aGroups = array(), $aOptions = array(), $bSendEmail = true) { //var_dump($aOptions); $this->checkMe(); $bVerifyEmail = isset($aOptions["verifyemail"]) ? $aOptions["verifyemail"] : FlexiConfig::$bRequireEmailVerification; if ($bVerifyEmail && empty(FlexiConfig::$sSupportEmail)) { throw new FlexiException("Support e-mail not set: " . FlexiConfig::$sSupportEmail, ERROR_CONFIGURATION); } $oModel = FlexiModelUtil::getModelInstance("ModxWebUsers", "flexiphp/base/FlexiAdminUser"); $oModel->username = $sUserName; $oModel->password = md5($sPassword); $oModel->Attributes->fullname = $sFullName; if (isset($aOptions["email"])) { $oModel->Attributes->email = $aOptions["email"]; //$oModel->Attributes->replace(); } $oModel->save(); $iUserId = $oModel->id; $oGroupNameQuery = FlexiModelUtil::getDBQuery("ModxWebgroupNames", "flexiphp/base/FlexiAdminGroup"); foreach ($aGroups as $sGroup) { $oGroupNameModel = $oGroupNameQuery->where("name=?", array($sGroup))->fetchOne(); if ($oGroupNameModel === false) { throw new FlexiException("No group by: " . $sGroup, ERROR_EOF); } $iGroupNameId = $oGroupNameModel->id; $oGroupModel = FlexiModelUtil::getModelInstance("ModxWebGroups", "flexiphp/base/FlexiAdminGroup"); $oGroupModel->webuser = $iUserId; $oGroupModel->webgroup = $iGroupNameId; $oGroupModel->save(); } //echo "verify: " . ($bVerifyEmail ? "true" : "false"); if (!empty($oModel->Attributes->email) && $bVerifyEmail) { $oView = new FlexiView(); $sMessage = $oView->render("user.verify", array("fullname" => $sFullName, "module" => "FlexiLogin", "method" => "verify", "params" => array("id" => $oModel->id, "r" => $oModel->Extend->verifycode))); $sSubject = "Verification required"; $oMail = FlexiMailer::getInstance(); $oMail->setFrom(FlexiConfig::$sSupportEmail); $oMail->mail($sSubject, $sMessage, $oModel->Attributes->email); // sendMailMessage($oModel->Attributes->email, $oModel->username, $sPassword, $oModel->Attributes->fullname); } return $oModel; }