public function checkExistingAgent($sIdentity, $sService, $iServiceId = null, $profile = array()) { if (NULL == $sIdentity || NULL == $sService) { return NULL; } $authAdapter = new YNSOCIALCONNECT_CLASS_AuthAdapter($sIdentity, $sService); if ($authAdapter->isRegistered()) { // already registered $authResult = OW::getUser()->authenticate($authAdapter); if ($authResult->isValid()) { $agent = $this->getAgentByIdentityAndService($sIdentity, $sService, $iServiceId); if (NULL == $agent) { // add new agent if (null == $iServiceId) { $provider = YNSOCIALCONNECT_BOL_ServicesService::getInstance()->getProvider($sService); $iServiceId = $provider->getId(); } $entity = new YNSOCIALCONNECT_BOL_Agents(); $entity->userId = (int) $authResult->getUserId(); $entity->identity = $sIdentity; $entity->serviceId = $iServiceId; $entity->ordering = 0; $entity->status = 'login'; $entity->login = '******'; $entity->data = base64_encode(serialize($profile)); $entity->tokenData = base64_encode(serialize($profile)); $entity->token = time(); $entity->createdTime = time(); $entity->loginTime = time(); $entity->logoutTime = time(); $this->save($entity); // already registerd in OxWall return array('type' => 'oxwall', 'result' => $authResult); } else { // already registed in YNSocialConnect (OxWall also) return array('type' => 'both', 'result' => $agent); } } } // not yet registered in OxWall and YNSocialConnect return false; }
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))); }
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); }
public function onUserRegister(OW_Event $event) { // init $params = $event->getParams(); $signupData = OW::getSession()->get(YNSOCIALCONNECT_CTRL_Sync::SESSION_SIGNUP_DATA); if (NULL != $params && is_array($params) && NULL != $signupData) { // process //// update ow_base_remote_auth $authAdapter = new YNSOCIALCONNECT_CLASS_AuthAdapter($signupData['identity'], $signupData['service']); $authAdapter->register($params['userId']); //// update agent table in social connect $provider = YNSOCIALCONNECT_BOL_ServicesService::getInstance()->getProvider($signupData['service']); $entity = new YNSOCIALCONNECT_BOL_Agents(); $entity->userId = (int) $params['userId']; $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 $oBridge = YNSOCIALCONNECT_CLASS_SocialBridge::getInstance(); if ($oBridge->hasProvider(strtolower($signupData['service']))) { $core = new YNSOCIALBRIDGE_CLASS_Core(); $obj = $core->getInstance($signupData['service']); $obj->saveToken(); } ////update signup statistic YNSOCIALCONNECT_BOL_ServicesService::getInstance()->updateStatistics($signupData['service'], 'signup'); ////add user linking $entityUserlinking = new YNSOCIALCONNECT_BOL_Userlinking(); $entityUserlinking->userId = (int) $params['userId']; $entityUserlinking->identity = $signupData['identity']; $entityUserlinking->serviceId = $provider->id; YNSOCIALCONNECT_BOL_UserlinkingService::getInstance()->save($entityUserlinking); // end if (isset($_SESSION['socialbridge_session'][$signupData['service']])) { unset($_SESSION['socialbridge_session'][$signupData['service']]); } //// clear session OW::getSession()->delete(YNSOCIALCONNECT_CTRL_Sync::SESSION_SIGNUP_DATA); // update avatar //// if avatar doesn't exist, update with profile image if (in_array($signupData['service'], array('facebook', 'linkedin', 'twitter'))) { $useProfilePhoto = OW::getSession()->get(YNSOCIALCONNECT_CMP_ViewInJoinPage::SESSION_USE_PROFILE_PHOTO); if ($useProfilePhoto == null || $useProfilePhoto != 'not_use') { $avatar = BOL_AvatarService::getInstance()->findByUserId($params['userId']); if (!$avatar) { $profilePicture = YNSOCIALCONNECT_CLASS_SocialConnect::getInstance()->getPhotoUrlFromTokenData($signupData['user'], $signupData['service']); // with facebook, linkedin, twitter if ($profilePicture != null) { $pluginfilesDir = Ow::getPluginManager()->getPlugin('ynsocialconnect')->getPluginFilesDir(); $tmpImgPath = $pluginfilesDir . 'img_' . uniqid() . '.jpg'; YNSOCIALCONNECT_CLASS_SocialConnect::getInstance()->fetchImage($profilePicture, $tmpImgPath); BOL_AvatarService::getInstance()->setUserAvatar($params['userId'], $tmpImgPath); @unlink($tmpImgPath); } } } } if (isset($params['quick_signup']) && $params['quick_signup']) { $userId = (int) $params['userId']; $event = new OW_Event('feed.action', array('pluginKey' => 'base', 'entityType' => 'user_join', 'entityId' => $userId, 'userId' => $userId, 'replace' => true), array('string' => OW::getLanguage()->text('base', 'feed_user_join'), 'view' => array('iconClass' => 'ow_ic_user'))); OW::getEventManager()->trigger($event); } } }