Exemple #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;
     }
 }
 /**
  * create new view instances
  *  will copy existing view to populate controller path and module
  * @param String $sName
  */
 public function getNewView($sName)
 {
     if (is_null($oView)) {
         throw new Exception("Main view not set");
     }
     $oMainView = $this->oView;
     $oView = new FlexiView();
     $oView->addVar("#module", $oMainView->getVar("#module"));
     $oView->addVar("#method", $oMainView->getVar("#method"));
     $oView->addVar("#modulepath", $oMainView->getVar("#modulepath"));
     $oView->addVar("#moduleurl", $oMainView->getVar("#moduleurl"));
     $oView->addVar("#modulepath", $oMainView->getVar("#modulepath"));
     $this->setView($oView, $sName);
 }
 /**
  * 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);
     }
     global $modx;
     $oModel = $modx->newObject("modUser");
     $oModel->set("username", $sUserName);
     $oModel->set("password", md5($sPassword));
     $oProfileModel = $modx->newObject("modUserProfile");
     $oProfileModel->set("fullname", $sFullName);
     $oModel->addOne($oProfileModel);
     if (isset($aOptions["email"])) {
         $oProfileModel->set("email", $aOptions["email"]);
     }
     $oModel->save();
     $iUserId = $oModel->get("id");
     //$oGroupQuery = $modx->newQuery("modUserGroup");
     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");
         $oGroupModel = $modx->newObject("modWebGroupMember");
         $oGroupModel->set("webuser", $iUserId);
         $oGroupModel->set("webgroup", $iGroupNameId);
         $oGroupModel->save();
     }
     $sEmail = $oModel->getOne("Profile")->get("email");
     if (!empty($sEmail) && $bVerifyEmail) {
         $oView = new FlexiView();
         $oUserExtend = FlexiModelUtil::Instance()->getRedbeanFetchOne("select * from modx_userextend where userid=:userid", array(":userid" => $iUserId));
         $sVerifyCode = "";
         if (!empty($oUserExtend->id)) {
             $sVerifyCode = $oUserExtend->verifycode;
             $sMessage = $oView->render("user.verify", array("fullname" => $sFullName, "module" => "FlexiLogin", "method" => "verify", "params" => array("id" => $oModel->id, "r" => $sVerifyCode)));
             $oMail = FlexiMailer::getInstance();
             $oMail->setFrom(FlexiConfig::$sSupportEmail);
             $oMail->mail($sSubject, $sMessage, $sEmail);
         }
     }
     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;
 }