Example #1
0
 } else {
     if (!isset($_GET['back'])) {
         $social->linkedinRequestToken($conf['linkedin_key'], $conf['linkedin_secret']);
         die;
         // don't remove this ;)
     } else {
         // linkedin callback
         $sign_in = $social->linkedinAccess($conf['linkedin_key'], $conf['linkedin_secret']);
     }
 }
 if ($sign_in) {
     $user_data = $social->getLinkedinUserInfo($conf['linkedin_key'], $conf['linkedin_secret']);
     if ($user_data) {
         if (Docebo::user()->isAnonymous()) {
             // sign in the user
             $user = DoceboUser::createDoceboUserFromField('linkedin_id', $user_data['id'], 'public_area');
             if ($user) {
                 DoceboUser::setupUser($user);
                 // TODO: save this in a secured cookie
                 $user->preference->setPreference('social.linkedin_key', $_SESSION['user_linkedin_key']);
                 $user->preference->setPreference('social.linkedin_secret', $_SESSION['user_linkedin_secret']);
                 Util::jump_to('index.php?r=lms/elearning/show');
             } else {
                 //Util::jump_to('index.php?access_fail=2');
                 socialConnectLogin($user_data['id'], 'linkedin');
                 return;
             }
         } else {
             // user is already logged in, so connect the account with user
             $social->connectAccount('linkedin', $user_data['id']);
             Util::jump_to('index.php?r=lms/elearning/show');
     die;
     break;
     // 2. $_REQUEST['code'] -> RETURN OK FROM FACEBOOK AUTH
 // 2. $_REQUEST['code'] -> RETURN OK FROM FACEBOOK AUTH
 case isset($_REQUEST['code']):
     $token = $facebookService->requestAccessToken($_GET['code']);
     $objUserInfo = json_decode($facebookService->request('/me'), true);
     if (!empty($objUserInfo["id"])) {
         if ($_SESSION['fb_from'] == "register") {
             $_SESSION['fb_info'] = $objUserInfo;
             Util::jump_to(Get::rel_path('base') . '/index.php?modname=login&op=register');
             die;
         }
         if (Docebo::user()->isAnonymous()) {
             // sign in the user
             $user = DoceboUser::createDoceboUserFromField('facebook_id', $objUserInfo["id"], 'public_area');
             if ($user) {
                 DoceboUser::setupUser($user);
                 Util::jump_to('index.php?r=lms/elearning/show');
             } else {
                 socialConnectLogin($objUserInfo["id"], 'facebook');
                 return;
             }
         } else {
             // user is already logged in, so connect the account with user
             $res = $social->connectAccount('facebook', $objUserInfo["id"]);
             if ($res == true) {
                 Util::jump_to(_folder_lms_ . '/index.php?' . 'feedback_code=_SOCIALCONNECTOK&feedback_type=inf&feedback_extra=' . $objUserInfo["id"]);
             } else {
                 Util::jump_to(_folder_lms_ . '/index.php?' . 'feedback_code=_SOCIALCONNECTKO&feedback_type=err&feedback_extra=' . $objUserInfo["id"]);
             }
     $openid = new LightOpenID();
     $openid->identity = 'https://www.google.com/accounts/o8/id';
     $openid->required = array('contact/email', 'namePerson/first', 'namePerson/last');
     header('Location: ' . str_replace('&', '&', $openid->authUrl()));
 } elseif ($_GET['openid_mode'] == 'cancel') {
     Util::jump_to('index.php?access_fail=3');
 } else {
     $openid = new LightOpenID();
     $_GET['openid_return_to'] = $_REQUEST['openid_return_to'];
     // to avoid having & instead of &
     if ($openid->validate()) {
         $user_data = $social->getGoogleUserInfo();
         if (!empty($user_data['email'])) {
             if (Docebo::user()->isAnonymous()) {
                 // sign in the user
                 $user = DoceboUser::createDoceboUserFromField('google_id', $user_data['email'], 'public_area');
                 if ($user) {
                     DoceboUser::setupUser($user);
                     Util::jump_to('index.php?r=lms/elearning/show');
                 } else {
                     //Util::jump_to('index.php?access_fail=2');
                     socialConnectLogin($user_data['email'], 'google');
                     return;
                 }
             } else {
                 // user is already logged in, so connect the account with user
                 $social->connectAccount('google', $user_data['email']);
                 Util::jump_to('index.php?r=lms/elearning/show');
                 die;
             }
             print_r($user_data);
 switch (TRUE) {
     // 1. no params $_REQUEST -> GOTO URL AUTH
     case !isset($_REQUEST['code']) && !isset($_REQUEST['error']) || isset($_REQUEST['connect']):
         $authUrl = $googleService->getAuthorizationUri();
         header('Location: ' . $authUrl);
         die;
         break;
         // 2. $_REQUEST['code'] -> RETURN OK FROM GOOGLE AUTH
     // 2. $_REQUEST['code'] -> RETURN OK FROM GOOGLE AUTH
     case isset($_REQUEST['code']):
         $token = $googleService->requestAccessToken($_GET['code']);
         $objUserInfo = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         if (!empty($objUserInfo["email"])) {
             if (Docebo::user()->isAnonymous()) {
                 // sign in the user
                 $user = DoceboUser::createDoceboUserFromField('google_id', $objUserInfo["email"], 'public_area');
                 if ($user) {
                     DoceboUser::setupUser($user);
                     Util::jump_to('index.php?r=lms/elearning/show');
                 } else {
                     socialConnectLogin($objUserInfo["email"], 'google');
                     return;
                 }
             } else {
                 // user is already logged in, so connect the account with user
                 $res = $social->connectAccount('google', $objUserInfo["email"]);
                 if ($res == true) {
                     Util::jump_to(_folder_lms_ . '/index.php?' . 'feedback_code=_SOCIALCONNECTOK&feedback_type=inf&feedback_extra=' . $objUserInfo["email"]);
                 } else {
                     Util::jump_to(_folder_lms_ . '/index.php?' . 'feedback_code=_SOCIALCONNECTKO&feedback_type=err&feedback_extra=' . $objUserInfo["email"]);
                 }