Ejemplo n.º 1
0
 /**
  * Returns class instance
  *
  * @return YNSOCIALCONNECT_BOL_AgentsService
  */
 public static function getInstance()
 {
     if (!isset(self::$classInstance)) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Ejemplo n.º 2
0
 public function index($params)
 {
     //	init
     if (OW::getUser()->isAuthenticated()) {
         $this->redirect(OW_URL_HOME);
         //throw new AuthenticateException();
     }
     if (!isset($params['service']) || !strlen(trim($params['service']))) {
         $this->redirect(OW_URL_HOME);
         //throw new Redirect404Exception();
     }
     $oBridge = YNSOCIALCONNECT_CLASS_SocialBridge::getInstance();
     //	process
     $sService = isset($params['service']) ? strtolower($params['service']) : null;
     $type = 'bridge';
     $sIdentity = null;
     $data = NULL;
     if ($oBridge->hasProvider($sService)) {
         //	process Facebook, Twitter, LinkedIn
         $profile = null;
         //check enable API
         $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($sService);
         if ($clientConfig) {
             $core = new YNSOCIALBRIDGE_CLASS_Core();
             $oProvider = $core->getInstance($sService);
             $values = array('service' => $sService, 'userId' => OW::getUser()->getId());
             $tokenDto = $oProvider->getToken($values);
             if (!empty($_SESSION['socialbridge_session'][$sService])) {
                 try {
                     $profile = $oProvider->getOwnerInfo($_SESSION['socialbridge_session'][$sService]);
                 } catch (Exception $e) {
                     $profile = null;
                 }
             } else {
                 if ($tokenDto) {
                     $profile = $oProvider->getOwnerInfo(array('access_token' => $tokenDto->accessToken, 'secret_token' => $tokenDto->secretToken, 'user_id' => $tokenDto->uid));
                 }
             }
             //
             if ($profile) {
                 $sIdentity = isset($profile['identity']) ? $profile['identity'] : null;
                 ////	filter data
                 $profile = YNSOCIALCONNECT_CLASS_SocialConnect::getInstance()->filterProfile($profile, $sService);
                 $data = $profile;
             }
         }
     } else {
         //	process with other services
         $type = 'not_bridge';
         $sIdentity = isset($_REQUEST['identity']) ? $_REQUEST['identity'] : null;
         $data = $_REQUEST;
     }
     $provider = YNSOCIALCONNECT_BOL_ServicesService::getInstance()->getProvider($sService);
     $aUser = YNSOCIALCONNECT_BOL_AgentsService::getInstance()->getUserByIdentityAndService($sIdentity, $sService, $provider->id, $data);
     $sUrlRedirect = '';
     if (NULL == $aUser && NULL == $sIdentity) {
         if ($oBridge->hasProvider($sService)) {
             $type = 'close_not_loading';
             $this->assign('type', $type);
             $this->assign('sUrlRedirect', $sUrlRedirect);
         }
     }
     if ($aUser) {
         //	login again
         //	logining which happen in YNSOCIALCONNECT_BOL_AgentsDao after execute checkExistingAgent
         //	now, redirect by url in session
         // @formatter:off
         if (isset($_SESSION['ynsc_session']) && isset($_SESSION['ynsc_session']['urlRedirect']) && strlen(trim($_SESSION['ynsc_session']['urlRedirect'])) > 0) {
             $sUrlRedirect = $_SESSION['ynsc_session']['urlRedirect'];
         } else {
             $sUrlRedirect = OW_URL_HOME;
         }
         // @formatter:on
         //	update login statistic
         YNSOCIALCONNECT_BOL_ServicesService::getInstance()->updateStatistics($sService, 'login');
     } else {
         //	sign up now
         //	saved data to session
         try {
             OW::getSession()->set(self::SESSION_SIGNUP_DATA, array('service' => $sService, 'identity' => $sIdentity, 'user' => $data));
         } catch (Exception $e) {
         }
         $sUrlRedirect = OW::getRouter()->urlForRoute('base_join');
         //	mapping profile in session
         $questions = $this->__mappingProfile($data, $sService);
         //	update later signup statistic in quick signup
         //	check existed user by email
         $checkExist = false;
         $checkEmail = false;
         if (isset($data['email'])) {
             $email = $data['email'];
             $aUser = BOL_UserService::getInstance()->findByEmail($email);
             if ($aUser) {
                 //	redirect to synchronize page
                 $sUrlRedirect = OW::getRouter()->urlFor('YNSOCIALCONNECT_CTRL_UserSync', 'index');
                 $checkExist = true;
             }
             if ($data['email']) {
                 $checkEmail = true;
             }
         }
         $plugin = OW::getPluginManager()->getPlugin('ynsocialconnect');
         $key = strtolower($plugin->getKey());
         if (!OW::getConfig()->getValue($key, 'signup_mode') && !$checkExist && $checkEmail && $questions['username']) {
             $username = $questions['username'];
             $password = uniqid();
             $user = BOL_UserService::getInstance()->createUser($username, $password, $questions['email'], null, true);
             BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($questions), $user->id);
             OW_User::getInstance()->login($user->id);
             $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('userId' => $user->id, 'quick_signup' => true));
             OW::getEventManager()->trigger($event);
             $sUrlRedirect = OW_URL_HOME;
         }
     }
     $this->assign('type', $type);
     $this->assign('sUrlRedirect', $sUrlRedirect);
     // 	end
 }
Ejemplo n.º 3
0
 public function index()
 {
     $this->setPageHeading(OW::getLanguage()->text('ynsocialconnect', 'h_synchronize_user'));
     //	init
     if (OW::getUser()->isAuthenticated()) {
         $this->redirect(OW_URL_HOME);
         //throw new AuthenticateException();
     }
     $oBridge = YNSOCIALCONNECT_CLASS_SocialBridge::getInstance();
     $signupData = OW::getSession()->get(YNSOCIALCONNECT_CTRL_Sync::SESSION_SIGNUP_DATA);
     //	process
     $form = new YNSOCIALCONNECT_CLASS_UserSyncForm();
     $email = $signupData['user']['email'];
     if (!$email) {
         $email = '';
     }
     if (OW::getRequest()->isPost() && $form->isValid($_POST)) {
         $data = $form->getValues();
         if ($data['form_name'] == YNSOCIALCONNECT_CLASS_UserSyncForm::FORM_NAME) {
             if (isset($_POST['no'])) {
                 //	sign up
                 $this->redirect(OW::getRouter()->urlForRoute('base_join'));
             }
             if (isset($_POST['synchronize'])) {
                 //	synchronize with existed account
                 $aUser = BOL_UserService::getInstance()->findByEmail($email);
                 $sUrlRedirect = '';
                 if ($aUser) {
                     ////		update ow_base_remote_auth
                     $authAdapter = new YNSOCIALCONNECT_CLASS_AuthAdapter($signupData['identity'], $signupData['service']);
                     $authAdapter->register($aUser->id);
                     ////	add agent
                     $provider = YNSOCIALCONNECT_BOL_ServicesService::getInstance()->getProvider($signupData['service']);
                     $entity = new YNSOCIALCONNECT_BOL_Agents();
                     $entity->userId = (int) $aUser->id;
                     $entity->identity = $signupData['identity'];
                     $entity->serviceId = $provider->id;
                     $entity->ordering = 0;
                     $entity->status = 'login';
                     $entity->login = '******';
                     $entity->data = base64_encode(serialize($signupData['user']));
                     $entity->tokenData = base64_encode(serialize($signupData['user']));
                     $entity->token = time();
                     $entity->createdTime = time();
                     $entity->loginTime = time();
                     $entity->logoutTime = time();
                     YNSOCIALCONNECT_BOL_AgentsService::getInstance()->save($entity);
                     //		add token in social bridge
                     if ($oBridge->hasProvider(strtolower($signupData['service']))) {
                         $core = new YNSOCIALBRIDGE_CLASS_Core();
                         $oProvider = $core->getInstance($signupData['service']);
                         $values = array('service' => strtolower($signupData['service']), 'userId' => $aUser->id);
                         $tokenDto = $oProvider->getToken($values);
                         if (!$tokenDto) {
                             //
                             $obj = $core->getInstance($signupData['service']);
                             $obj->saveToken();
                         }
                     }
                     ////	update statistics with "sync" type
                     YNSOCIALCONNECT_BOL_ServicesService::getInstance()->updateStatistics($signupData['service'], 'sync');
                     ////		add user linking
                     $entityUserlinking = new YNSOCIALCONNECT_BOL_Userlinking();
                     $entityUserlinking->userId = (int) $aUser->id;
                     $entityUserlinking->identity = $signupData['identity'];
                     $entityUserlinking->serviceId = $provider->id;
                     YNSOCIALCONNECT_BOL_UserlinkingService::getInstance()->save($entityUserlinking);
                     ////	clear sign up session
                     OW::getSession()->delete(YNSOCIALCONNECT_CTRL_Sync::SESSION_SIGNUP_DATA);
                     ////	redirect
                     $authResult = OW::getUser()->authenticate($authAdapter);
                     if ($authResult->isValid()) {
                         if (isset($_SESSION['ynsc_session']) && isset($_SESSION['ynsc_session']['urlRedirect']) && strlen(trim($_SESSION['ynsc_session']['urlRedirect'])) > 0) {
                             $sUrlRedirect = $_SESSION['ynsc_session']['urlRedirect'];
                         } else {
                             $sUrlRedirect = OW_URL_HOME;
                         }
                         $this->redirect($sUrlRedirect);
                     } else {
                         $this->redirect(OW_URL_HOME);
                     }
                 }
             }
         }
     }
     // 	end
     //// 	clear session
     if (isset($_SESSION['socialbridge_session'][$signupData['service']])) {
         unset($_SESSION['socialbridge_session'][$signupData['service']]);
     }
     $this->addForm($form);
     $this->assign('email', $email);
     $this->assign('question', OW::getLanguage()->text('ynsocialconnect', 'txt_sync_question', array('email' => $email)));
 }
Ejemplo n.º 4
0
 public function linking($params)
 {
     if (!OW::getUser()->isAuthenticated()) {
         $this->redirect(OW_URL_HOME);
         //throw new AuthenticateException();
     }
     if (!isset($params['service']) || !strlen(trim($params['service']))) {
         $this->redirect(OW_URL_HOME);
         //throw new Redirect404Exception();
     }
     //	init
     $oBridge = YNSOCIALCONNECT_CLASS_SocialBridge::getInstance();
     $sService = isset($params['service']) ? strtolower($params['service']) : null;
     $sIdentity = null;
     $data = NULL;
     $type = 'bridge';
     $sUrlRedirect = OW::getRouter()->urlForRoute('ynsocialconnect_user_user_linking');
     //	process
     if ($oBridge->hasProvider($sService)) {
         //	process Facebook, Twitter, LinkedIn
         $profile = null;
         //check enable API
         $clientConfig = YNSOCIALBRIDGE_BOL_ApisettingService::getInstance()->getConfig($sService);
         if ($clientConfig) {
             $core = new YNSOCIALBRIDGE_CLASS_Core();
             $oProvider = $core->getInstance($sService);
             if (!empty($_SESSION['socialbridge_session'][$sService])) {
                 try {
                     $profile = $oProvider->getOwnerInfo($_SESSION['socialbridge_session'][$sService]);
                 } catch (Exception $e) {
                     $profile = null;
                 }
             }
             //
             if ($profile) {
                 $sIdentity = isset($profile['identity']) ? $profile['identity'] : null;
                 ////	filter data
                 $profile = YNSOCIALCONNECT_CLASS_SocialConnect::getInstance()->filterProfile($profile, $sService);
                 $data = $profile;
             }
         }
     } else {
         //	process with other services
         $type = 'not_bridge';
         $sIdentity = isset($_REQUEST['identity']) ? $_REQUEST['identity'] : null;
         $data = $_REQUEST;
     }
     if (NULL == $sIdentity) {
         $type = 'close_not_loading';
     } else {
         ////		update ow_base_remote_auth
         $authAdapter = new YNSOCIALCONNECT_CLASS_AuthAdapter($sIdentity, $sService);
         $authAdapter->register(OW::getUser()->getId());
         ////		update agent table in social connect
         $provider = YNSOCIALCONNECT_BOL_ServicesService::getInstance()->getProvider($sService);
         $entity = new YNSOCIALCONNECT_BOL_Agents();
         $entity->userId = (int) OW::getUser()->getId();
         $entity->identity = $sIdentity;
         $entity->serviceId = $provider->id;
         $entity->ordering = 0;
         $entity->status = 'linking';
         $entity->login = '******';
         $entity->data = base64_encode(serialize($data));
         $entity->tokenData = base64_encode(serialize($data));
         $entity->token = time();
         $entity->createdTime = time();
         $entity->loginTime = time();
         $entity->logoutTime = time();
         YNSOCIALCONNECT_BOL_AgentsService::getInstance()->save($entity);
         ////		delete old token and add new token in social bridge
         if ($oBridge->hasProvider($sService)) {
             //	remove old token
             $values = array('service' => $sService, 'userId' => OW::getUser()->getId());
             $tokenDto = $oProvider->getToken($values);
             if ($tokenDto) {
                 YNSOCIALBRIDGE_BOL_TokenService::getInstance()->delete($tokenDto);
             }
             //	add new token
             $oProvider->saveToken();
         }
         ////		add user linking
         $entityUserlinking = new YNSOCIALCONNECT_BOL_Userlinking();
         $entityUserlinking->userId = (int) OW::getUser()->getId();
         $entityUserlinking->identity = $sIdentity;
         $entityUserlinking->serviceId = $provider->id;
         YNSOCIALCONNECT_BOL_UserlinkingService::getInstance()->save($entityUserlinking);
     }
     //	end
     //// 	clear session
     if (isset($_SESSION['socialbridge_session'][$sService])) {
         unset($_SESSION['socialbridge_session'][$sService]);
     }
     $this->assign('type', $type);
     $this->assign('sUrlRedirect', $sUrlRedirect);
 }
Ejemplo n.º 5
0
 public function onUserUnregister(OW_Event $event)
 {
     $params = $event->getParams();
     $userId = (int) $params['userId'];
     //	delete agent
     YNSOCIALCONNECT_BOL_AgentsService::getInstance()->deleteByUserId($userId);
     //	delete ALL user linking
     YNSOCIALCONNECT_BOL_UserlinkingService::getInstance()->deleteByUserId($userId);
 }