Пример #1
0
 public function login($params)
 {
     $backUri = empty($_GET['backUri']) ? '' : urldecode($_GET['backUri']);
     $backUrl = OW_URL_HOME . $backUri;
     $language = OW::getLanguage();
     $fbUser = $this->service->fbRequireUser();
     $authAdapter = new FBCONNECT_CLASS_AuthAdapter($fbUser);
     // Login and redirect if already registered
     if ($authAdapter->isRegistered()) {
         $authResult = OW::getUser()->authenticate($authAdapter);
         if ($authResult->isValid()) {
             OW::getFeedback()->info($language->text('fbconnect', 'login_success_msg'));
         } else {
             OW::getFeedback()->error($language->text('fbconnect', 'login_failure_msg'));
         }
         $this->redirect($backUrl);
     }
     //Register if not registered
     $questions = $this->service->requestQuestionValueList($fbUser);
     if (empty($questions["email"]) || empty($questions["username"])) {
         OW::getFeedback()->error($language->text('fbconnect', 'join_incomplete'));
         $this->redirect($backUrl);
     }
     $username = $questions['username'];
     $password = uniqid();
     $userByEmail = BOL_UserService::getInstance()->findByEmail($questions['email']);
     if ($userByEmail !== null) {
         OW::getUser()->login($userByEmail->id);
         OW::getFeedback()->info($language->text('fbconnect', 'login_success_msg'));
         $this->redirect($backUrl);
     }
     $validUsername = UTIL_Validator::isUserNameValid($username);
     $username = $validUsername ? $username : uniqid("user_");
     try {
         $user = BOL_UserService::getInstance()->createUser($username, $password, $questions['email'], null, true);
         if (!$validUsername) {
             $user->username = "******" . $user->id;
             BOL_UserService::getInstance()->saveOrUpdate($user);
         }
         unset($questions['username']);
         unset($questions['email']);
     } catch (Exception $e) {
         switch ($e->getCode()) {
             case BOL_UserService::CREATE_USER_DUPLICATE_EMAIL:
                 OW::getFeedback()->error($language->text('fbconnect', 'join_dublicate_email_msg'));
                 $this->redirect($backUrl);
                 break;
             case BOL_UserService::CREATE_USER_INVALID_USERNAME:
                 OW::getFeedback()->error($language->text('fbconnect', 'join_incorrect_username'));
                 $this->redirect($backUrl);
                 break;
             default:
                 OW::getFeedback()->error($language->text('fbconnect', 'join_incomplete'));
                 $this->redirect($backUrl);
         }
     }
     if (!empty($questions['picture_big'])) {
         BOL_AvatarService::getInstance()->setUserAvatar($user->id, $questions['picture_big']);
         unset($questions['picture_small']);
         unset($questions['picture_medium']);
         unset($questions['picture_big']);
     }
     BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($questions), $user->id);
     $authAdapter->register($user->id);
     $authResult = OW_Auth::getInstance()->authenticate($authAdapter);
     if ($authResult->isValid()) {
         $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('method' => 'facebook', 'userId' => $user->id, 'params' => $_GET));
         OW::getEventManager()->trigger($event);
         OW::getFeedback()->info($language->text('fbconnect', 'join_success_msg'));
     } else {
         OW::getFeedback()->error($language->text('fbconnect', 'join_failure_msg'));
     }
     $this->redirect($backUrl);
 }
Пример #2
0
 public function login($params)
 {
     $backUri = empty($_GET['backUri']) ? '' : urldecode($_GET['backUri']);
     $backUrl = OW_URL_HOME . $backUri;
     $language = OW::getLanguage();
     $fbUser = $this->service->fbRequireUser();
     $authAdapter = new FBCONNECT_CLASS_AuthAdapter($fbUser);
     // Login and redirect if already registered
     if ($authAdapter->isRegistered()) {
         $authResult = OW::getUser()->authenticate($authAdapter);
         if ($authResult->isValid()) {
             OW::getFeedback()->info($language->text('fbconnect', 'login_success_msg'));
         } else {
             OW::getFeedback()->error($language->text('fbconnect', 'login_failure_msg'));
         }
         $this->redirect($backUrl);
     }
     //Register if not registered
     $questions = $this->service->requestQuestionValueList($fbUser);
     $username = $questions['username'];
     $password = uniqid();
     $userByEmail = BOL_UserService::getInstance()->findByEmail($questions['email']);
     if ($userByEmail !== null) {
         OW::getUser()->login($userByEmail->id);
         OW::getFeedback()->info($language->text('fbconnect', 'login_success_msg'));
         $this->redirect($backUrl);
     }
     try {
         $user = BOL_UserService::getInstance()->createUser($username, $password, $questions['email'], null, true);
         unset($questions['username']);
         unset($questions['email']);
     } catch (Exception $e) {
         switch ($e->getCode()) {
             case BOL_UserService::CREATE_USER_DUPLICATE_EMAIL:
                 OW::getFeedback()->error($language->text('fbconnect', 'join_dublicate_email_msg'));
                 $this->redirect($backUrl);
                 break;
             case BOL_UserService::CREATE_USER_INVALID_USERNAME:
                 OW::getFeedback()->error($language->text('fbconnect', 'join_incorrect_username'));
                 $this->redirect($backUrl);
                 break;
             default:
                 OW::getFeedback()->error($language->text('fbconnect', 'join_incomplete'));
                 $this->redirect($backUrl);
         }
     }
     if (!empty($questions['picture_small'])) {
         $avatarSaveResult = 0;
         $avatar = new BOL_Avatar();
         $avatar->hash = time();
         $avatar->userId = $user->id;
         $avatarService = BOL_AvatarService::getInstance();
         $pfSmallPicDir = $avatarService->getAvatarPluginFilesPath($user->id, 1, $avatar->hash);
         $pfMediumPicDir = $avatarService->getAvatarPluginFilesPath($user->id, 2, $avatar->hash);
         $pfBigPicDir = $avatarService->getAvatarPluginFilesPath($user->id, 3, $avatar->hash);
         $smallPicDir = $avatarService->getAvatarPath($user->id, 1, $avatar->hash);
         $mediumPicDir = $avatarService->getAvatarPath($user->id, 2, $avatar->hash);
         $bigPicDir = $avatarService->getAvatarPath($user->id, 3, $avatar->hash);
         $storage = OW::getStorage();
         if (rename($questions['picture_small'], $pfSmallPicDir)) {
             $avatarSaveResult += (int) $storage->copyFile($pfSmallPicDir, $smallPicDir);
         }
         if (!empty($questions['picture_medium'])) {
             if (rename($questions['picture_medium'], $pfMediumPicDir)) {
                 $avatarSaveResult += (int) $storage->copyFile($pfMediumPicDir, $mediumPicDir);
             }
         } else {
             $avatarSaveResult += (int) $storage->copyFile($pfSmallPicDir, $mediumPicDir);
         }
         if (!empty($questions['picture_big'])) {
             if (rename($questions['picture_big'], $pfBigPicDir)) {
                 $avatarSaveResult += (int) $storage->copyFile($pfBigPicDir, $bigPicDir);
             }
         } else {
             $avatarSaveResult += (int) $storage->copyFile($pfSmallPicDir, $bigPicDir);
         }
         if ($avatarSaveResult) {
             $avatarService->updateAvatar($avatar);
         }
         unset($questions['picture_small']);
         unset($questions['picture_medium']);
         unset($questions['picture_big']);
     }
     BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($questions), $user->id);
     $authAdapter->register($user->id);
     $authResult = OW_Auth::getInstance()->authenticate($authAdapter);
     if ($authResult->isValid()) {
         $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('method' => 'facebook', 'userId' => $user->id, 'params' => $_GET));
         OW::getEventManager()->trigger($event);
         OW::getFeedback()->info($language->text('fbconnect', 'join_success_msg'));
     } else {
         OW::getFeedback()->error($language->text('fbconnect', 'join_failure_msg'));
     }
     $this->redirect($backUrl);
 }