Exemplo n.º 1
0
 public function getUser()
 {
     $status = $this->setOnlineStatus();
     if ($this->user != null) {
         return $this->user;
     }
     // for test
     $this->user = new GuestUser();
     try {
         if (isset($_COOKIE["ut"])) {
             if (isset($_COOKIE["uh"]) && isset($_COOKIE["ud"])) {
                 if ($_COOKIE["ut"] == UserGroups::$USER) {
                     $user = new CustomerUser($_COOKIE["ud"]);
                 } else {
                     if ($_COOKIE["ut"] == UserGroups::$ADMIN) {
                         $user = new AdminUser($_COOKIE["ud"]);
                     } else {
                         if ($_COOKIE["ut"] == UserGroups::$COMPANY) {
                             $user = new CompanyUser($_COOKIE["ud"]);
                         } else {
                             if ($_COOKIE["ut"] == UserGroups::$SERVICE_COMPANY) {
                                 $user = new ServiceCompanyUser($_COOKIE["ud"]);
                             }
                         }
                     }
                 }
             }
         }
         if (isset($user) && $user->validate($_COOKIE["uh"])) {
             $this->user = $user;
         }
         if ($this->user && $this->user->getLevel() != UserGroups::$GUEST) {
             $hash = $_COOKIE["uh"];
             if (!$status) {
                 $hash = $this->updateUserHash($_COOKIE["ud"]);
                 $this->updateUserUniqueId($user);
             }
             $this->user->setUniqueId($hash, false);
         }
     } catch (InvalidUserException $ex) {
     }
     return $this->user;
 }
Exemplo n.º 2
0
 public function service()
 {
     $userManager = new UserManager($this->config, $this->args);
     if (isset($_REQUEST['login_type'])) {
         $json_profile = $_REQUEST['json_profile'];
         $social_user_id = $this->secure($_REQUEST['social_user_id']);
         $first_name = $this->secure($_REQUEST['first_name']);
         $last_name = $this->secure($_REQUEST['last_name']);
         $custDto = $userManager->getUserByEmail($social_user_id);
         if (!isset($custDto)) {
             $userId = $userManager->createUser($social_user_id, uniqid(), $first_name, '', $last_name, $_REQUEST['login_type']);
             $userManager->setActive($userId);
             $userManager->setUserSocialProfile($userId, $json_profile);
             $custDto = $userManager->getUserByEmail($social_user_id);
             //bonus to inviter
             $invitation_code = $this->secure($_COOKIE["invc"]);
             $inviterId = $userManager->setSubUser($invitation_code, $userId);
             if ($inviterId > 0) {
                 $invbonus = intval($this->getCmsVar("bonus_points_for_every_accepted_invitation"));
                 $userManager->addUserPoints($inviterId, $invbonus, "{$invbonus} bonus for invitation accept from user number: {$userId}");
             }
         }
         $userType = UserGroups::$USER;
     } else {
         $email = strtolower($userManager->secure($_REQUEST["user_email"]));
         $pass = $userManager->secure($_REQUEST["user_pass"]);
         $custDto = $userManager->getCustomerByEmailAndPassword($email, $pass);
         $userType = $userManager->getCustomerType($email, $pass);
         if ($userType == UserGroups::$USER && $custDto->getActive() == 0) {
             $jsonArr = array('status' => "err", "errText" => sprintf($this->getPhrase(380), $custDto->getEmail()));
             echo json_encode($jsonArr);
             return false;
         }
     }
     if ($custDto) {
         if ($userType !== UserGroups::$ADMIN && $custDto->getBlocked() == 1) {
             $jsonArr = array('status' => "err", "errText" => $this->getPhraseSpan(411) . ' ' . $this->getCmsVar("pcstore_support_phone_number"));
             echo json_encode($jsonArr);
             return false;
         }
         $user = null;
         if ($userType === UserGroups::$ADMIN) {
             $user = new AdminUser($custDto->getId());
         } else {
             if ($userType === UserGroups::$USER) {
                 $user = new CustomerUser($custDto->getId());
                 $this->setcookie('ul', $custDto->getLanguageCode());
             } else {
                 if ($userType === UserGroups::$COMPANY) {
                     $user = new CompanyUser($custDto->getId());
                     $companyManager = CompanyManager::getInstance($this->config, $this->args);
                     $companyManager->updateCompanyRating($custDto);
                     $this->setcookie('ul', $custDto->getLanguageCode());
                 } else {
                     if ($userType === UserGroups::$SERVICE_COMPANY) {
                         $user = new ServiceCompanyUser($custDto->getId());
                         $companyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
                         $this->setcookie('ul', $custDto->getLanguageCode());
                     }
                 }
             }
         }
         $user->setUniqueId($custDto->getHash());
         $this->sessionManager->setUser($user, true, true);
         $jsonArr = array('status' => "ok");
         echo json_encode($jsonArr);
         return true;
     } else {
         $jsonArr = array('status' => "err", "errText" => $this->getPhrase(412));
         echo json_encode($jsonArr);
         return false;
     }
 }