Пример #1
0
 public function onLogin(&$asLoginId, &$asLoginPass, &$asConfig = array())
 {
     global $modx;
     $sDBPass = md5($asLoginPass);
     FlexiLogger::debug(__METHOD__, "Trying to login: "******", " . $asLoginPass . "(" . $sDBPass . ")");
     $aParams = array("loginid" => &$asLoginId, "password" => &$asLoginPass, "config" => &$asConfig);
     FlexiEvent::triggerEvent("preLogin", $aParams);
     $sType = $asConfig["type"];
     if ($sType == "user") {
         $bean = FlexiModelUtil::getInstance()->getRedbeanFetchOne("select * from " . FlexiConfig::$sDBPrefix . "users" . " where user_name=:user_name and password=:password AND deleted = 'N'", array(":user_name" => $asLoginId, ":password" => $sDBPass));
         if (empty($bean["user_id"])) {
             FlexiLogger::error(__METHOD__, "User Id: " . $iUserId . "({$sType}) not found");
         } else {
             $bStatus = true;
         }
     } else {
         if ($sType == "seller") {
             $bean = FlexiModelUtil::getInstance()->getRedbeanFetchOne("select * from " . FlexiConfig::$sDBPrefix . "artists" . " where artist_name=:user_name and password=:password AND deleted = 'N'", array(":user_name" => $asLoginId, ":password" => $sDBPass));
             if (empty($bean["artist_id"])) {
                 FlexiLogger::error(__METHOD__, "User Id: " . $iUserId . "({$sType}) not found");
             } else {
                 $bStatus = true;
             }
         }
     }
     $mReturn = array("msg" => "");
     $aParams = array("status" => &$bStatus, "user" => &$bean, "loginid" => &$asLoginId, "password" => &$asLoginPass, "config" => &$asConfig, "return" => &$mReturn);
     FlexiEvent::triggerEvent("postLogin", $aParams);
     if ($bStatus) {
         FlexiLogger::debug(__METHOD__, "Login Success: " . $asLoginId . "({$sType})");
         if ($sType == "user") {
             $_SESSION["sess_username"] = $bean["user_name"];
             $_SESSION["sess_userid"] = $bean["user_id"];
         } else {
             if ($sType == "seller") {
                 $_SESSION["sess_artistname"] = $bean["artist_name"];
                 $_SESSION["sess_artistid"] = $bean["artist_id"];
             }
         }
         if ($bean["user_id"] == FlexiConfig::$iAdminId) {
             $adminbean = FlexiModelUtil::getInstance()->getRedbeanFetchOne("select * from " . FlexiConfig::$sDBPrefix . "settings limit 1");
             $_SESSION["sess_adminname"] = $adminbean["admin_name"];
         }
         return true;
     }
     FlexiLogger::debug(__METHOD__, "Login Failed: " . $asLoginId);
     return false;
 }
Пример #2
0
 public function onLogin(&$asLoginId, &$asLoginPass, &$asConfig = array())
 {
     global $modx;
     $sDBPass = md5($asLoginPass);
     FlexiLogger::debug(__METHOD__, "Trying to login: "******", " . $asLoginPass . "(" . $sDBPass . ")");
     $aParams = array("loginid" => &$asLoginId, "password" => &$asLoginPass, "config" => &$asConfig);
     FlexiEvent::triggerEvent("preLogin", $aParams);
     $oQuery = FlexiModelUtil::getDBQuery("ModxWebUsers u", "flexiphp/base/FlexiAdminUser")->where("u.username=? and u.password=?", array($asLoginId, $sDBPass));
     if (FlexiConfig::$bRequireEmailVerification) {
         $oQuery->leftJoin("u.Extend e");
         $oQuery->addWhere("e.verified=?", array(1));
     }
     $oUser = $oQuery->fetchOne();
     $bStatus = $oUser != null && $oUser !== false;
     $mReturn = array("msg" => "");
     $aParams = array("status" => &$bStatus, "user" => &$oUser, "loginid" => &$asLoginId, "password" => &$asLoginPass, "config" => &$asConfig, "return" => &$mReturn);
     FlexiEvent::triggerEvent("postLogin", $aParams);
     if ($bStatus) {
         FlexiLogger::debug(__METHOD__, "Login Success: " . $asLoginId);
         //success
         $_SESSION["webValidated"] = true;
         $_SESSION["webInternalKey"] = $oUser->id;
         $_SESSION['webShortname'] = $oUser->username;
         $_SESSION['userid'] = $oUser->id;
         $aGroupModel = FlexiModelUtil::getDBQuery("ModxWebGroups g", "flexiphp/base/FlexiAdminGroup")->where("g.webuser=? ", array($oUser->id))->execute();
         $aGroup = array();
         foreach ($aGroupModel as $oGroup) {
             foreach ($oGroup->GroupAccess as $oAccess) {
                 $aGroup[] = $oAccess->documentgroup;
             }
         }
         $_SESSION['webDocgroups'] = $aGroup;
         return true;
     }
     FlexiLogger::debug(__METHOD__, "Login Failed: " . $asLoginId);
     return false;
 }
Пример #3
0
 public function onLogin(&$asLoginId, &$asLoginPass, &$asConfig = array())
 {
     global $modx;
     $sDBPass = md5($asLoginPass);
     $aParams = array("loginid" => &$asLoginId, "password" => &$asLoginPass, "config" => &$asConfig);
     FlexiEvent::triggerEvent("preLogin", $aParams);
     $aWhere = array("username" => $asLoginId, "password" => $sDBPass);
     $oQuery = $modx->newQuery("modUser")->where($aWhere);
     $oUser = $modx->getObject("modUser", $oQuery);
     if (is_null($oUser)) {
         return false;
     }
     $bStatus = false;
     if (FlexiConfig::$bRequireEmailVerification) {
         $oProfile = $oUser->getOne("Profile");
         if ($oProfile) {
             $oExtend = $oProfile->get("extend");
             if (!empty($oExtend)) {
                 if ($oExtend->get("verified") != 1) {
                     FlexiLogger::error(__METHOD__, "Account not verified: " . $oUser->get("id"));
                     return false;
                 }
             }
             //if extend has value
         }
         //if profile exists
         $bStatus = true;
     } else {
         $bStatus = true;
     }
     FlexiLogger::info(__METHOD__, "after verification");
     $mReturn = array("msg" => "");
     $aParams = array("status" => &$bStatus, "user" => &$oUser, "loginid" => &$asLoginId, "password" => &$asLoginPass, "config" => &$asConfig, "return" => &$mReturn);
     FlexiEvent::triggerEvent("postLogin", $aParams);
     if ($bStatus) {
         FlexiLogger::info(__METHOD__, "Login Success: " . $asLoginId . ", op context: " . $asConfig["context"]);
         $additionalContext = "";
         $loginContext = !empty($asConfig["context"]) ? $asConfig["context"] : "web";
         if (strpos($loginContext, ",") !== false) {
             $contexts = explode(",", $loginContext);
             $loginContext = array_shift($contexts);
             $additionalContext = implode(",", $contexts);
         }
         /* set default POST vars if not in form */
         $scriptProperties = array("username" => $asLoginId, "password" => $asLoginPass, "rememberme" => isset($asConfig["rememberme"]) ? $asConfig["rememberme"] : false, "session_cookie_lifetime" => isset($asConfig["session_cookie_lifetime"]) ? $asConfig["session_cookie_lifetime"] : null, "login_context" => $loginContext);
         if (!empty($additionalContext)) {
             $scriptProperties["add_contexts"] = $additionalContext;
         }
         FlexiLogger::debug(__METHOD__, "Login: "******"Trying to login: "******"url: " . $response['object']['url'];
         if (!empty($response) && is_array($response)) {
             if (!empty($response['success']) && isset($response['object'])) {
                 FlexiLogger::info(__METHOD__, "Modx2.Login Success: " . $asLoginId);
                 FlexiLogger::info(__METHOD__, "groups: " . implode(",", $modx->getAuthenticatedUser($loginContext)->getResourceGroups()));
             } else {
                 FlexiLogger::error(__METHOD__, "Modx2.Login Failed: " . $asLoginId . ", " . print_r($response, true));
             }
         }
         //success
         //      $_SESSION["webValidated"] = 1;
         //      $_SESSION["webInternalKey"] = $oUser->get("id");
         //      $_SESSION['webShortname'] = $oUser->get("username");
         //      $_SESSION['userid'] = $oUser->get("id");
         //
         //      //getting group names
         //      FlexiLogger::info(__METHOD__, "Logged in: " . $_SESSION['webShortname']);
         //      $aGroupModel = $oUser->getMany("UserGroupMembers");
         //      FlexiLogger::info(__METHOD__, "Doc groups: " . count($aGroupModel));
         //      $aGroup = array();
         //      foreach($aGroupModel as $oGroup) {
         //        foreach($oGroup->GroupAccess as $oAccess) {
         //          $aGroup[] = $oGroup->getOne("UserGroup")->get("name");
         //        }
         //      }
         //      $_SESSION['webDocgroups'] = $aGroup;
         return true;
     }
     FlexiLogger::debug(__METHOD__, "Login Failed: " . $asLoginId);
     return false;
 }
Пример #4
0
 /**
  * Only create class and run method with view rendering,
  *  no rendering of layout
  * @param String $sModule
  * @param String $sMethod
  * @param FlexiView $oView
  * @return array("control"=> object,"return" => boolean);
  */
 public function _run($asModule, $asMethod, $oView)
 {
     static $bTriggered = false;
     $sModule = empty($asModule) ? "default" : $asModule;
     $sMethod = empty($asMethod) ? "default" : $asMethod;
     //clean method
     $sMethodName = ucwords($sMethod);
     $sMethodName = str_replace(" ", "", $sMethodName);
     FlexiLogger::debug(__METHOD__, "module: " . $sModule . ", method: " . $sMethod);
     $oClass = self::getControllerInstance($sModule, $oView, $sMethodName, null);
     self::$oActiveControl = $oClass;
     //trigger event for 1st time only
     if (!$bTriggered) {
         //FlexiLogger::info(__METHOD__, "DOC: " . $modx->documentIdentifier);
         $aEventParams = array();
         if (FlexiConfig::$sFramework == "modx") {
             global $modx;
             $aEventParams = array("docid" => $modx->documentIdentifier);
         } else {
             if (FlexiConfig::$sFramework == "modx2") {
                 global $modx;
                 $aEventParams = array("docid" => $modx->resourceIdentifier, "method" => $modx->resourceMethod);
             }
         }
         FlexiEvent::triggerEvent("onLoadDocument", $aEventParams);
         $bTriggered = true;
     }
     if (is_null($oClass)) {
         FlexiLogger::error(__METHOD__, "module: " . $sModule . " does not exists");
         die("module: " . $sModule . " does not exists");
         return array("return" => false, "control" => &$oClass);
     }
     FlexiLogger::debug(__METHOD__, "calling _runControl");
     //render view as "body" var
     //echo "running control to body";
     $bResult = $oClass->_runControl($sMethod, null, "body");
     //manually render layout
     FlexiLogger::debug(__METHOD__, "called _runControl");
     return array("return" => $bResult, "control" => &$oClass);
 }