Beispiel #1
0
 public function methodResendVerify()
 {
     $sUserId = $this->getRequest("txtLogin");
     $oLogin = FlexiConfig::getLoginHandler();
     //var_dump($sUserId);
     $oUser = $oLogin->getUserByLoginId($sUserId);
     if ($oUser == null || $oUser === false) {
         $this->oView->addVar("status", 1);
         return true;
     }
     $sEmail = $oUser->Attributes->email;
     if (!empty($sEmail)) {
         $sFullName = $oUser->Attributes->fullname;
         $oView = new FlexiView();
         $sMessage = $oView->render("user.verify", array("fullname" => $sFullName, "module" => "FlexiLogin", "method" => "verify", "params" => array("id" => $oUser->id, "r" => $oUser->Extend->verifycode)));
         $sSubject = "resend: Verification required";
         $oMail = FlexiMailer::getInstance();
         $oMail->setFrom(FlexiConfig::$sSupportEmail);
         $oMail->mail($sSubject, $sMessage, $oUser->Attributes->email);
         $this->oView->addVar("status", 2);
         return true;
     } else {
         $this->oView->addVar("status", 3);
         return true;
     }
 }
 public function informError($sMsg)
 {
     //echo, write to file, and mail?
     $aLine = explode("\n", $sMsg);
     $sResult = "";
     foreach ($aLine as $sLine) {
         $sResult .= "[" . get_class($this) . "]:" . $sLine . "<br/>\n";
     }
     echo $sResult;
     FlexiLogger::error(__METHOD__, $sResult);
     if (!empty($this->sInformEmail)) {
         $sHeader = "From: " . FlexiConfig::$sSupportEmail . "\n" . "Reply-to: " . FlexiConfig::$sSupportEmail;
         $oMail = FlexiMailer::getInstance();
         $oMail->mail(FlexiConfig::$sBaseURLDir . ":Error", $sResult, $this->sInformEmail, "text");
     }
 }
 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;
 }
Beispiel #4
0
 /**
  * @param $bNew boolean
  * @return FlexiMailer
  */
 public static function getInstance($bNew = false)
 {
     if (self::$oInstance == null || $bNew) {
         self::$oInstance = new FlexiMailer();
     }
     return self::$oInstance;
 }
 /**
  * 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;
 }
 /**
  * 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 = FlexiModeUtil::getRedbeanModel(FlexiConfig::$sDBPrefix . "users");
     $oModel->user_name = $sUserName;
     $oModel->password = md5($sPassword);
     $oModel->first_name = $sFullName;
     $oModel->email = $aOptions["email"];
     $oModel->date_registered = FlexiDateUtil::getSQLDateNow();
     $oModel->deleted = "N";
     FlexiModelUtil::getInstance()->insertRedBean($oModel);
     if (!empty($oModel->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;
 }