function socialConnectLogin($uid = false, $network_code = false) { require_once _base_ . '/lib/lib.usermanager.php'; $res = ''; $lang = DoceboLanguage::createInstance('login'); $user_manager = new UserManager(); if (!empty($uid) && !empty($network_code)) { session_regenerate_id(); $_SESSION['connect_social']['uid'] = $uid; $_SESSION['connect_social']['network_code'] = $network_code; } $can_connect = false; if (isset($_SESSION['connect_social']) && isset($_SESSION['connect_social']['uid']) && !empty($_SESSION['connect_social']['uid'])) { // read data from session, in case we are on the second step (login attempt) $uid = $_SESSION['connect_social']['uid']; $network_code = $_SESSION['connect_social']['network_code']; $can_connect = true; } // check form submission: if (isset($_POST['undo'])) { // go back to index Util::jump_to('index.php'); } else { if (isset($_POST['login']) && !$can_connect) { // we don't have the social uid to be connected with user account.. Util::jump_to('index.php?modname=login&op=social_connect_login&err=2'); } else { if (isset($_POST['login'])) { // login and connect account $user = DoceboUser::createDoceboUserFromLogin(Get::pReq('login_userid', DOTY_STRING), Get::pReq('login_pwd', DOTY_STRING), 'public_area'); if ($user) { DoceboUser::setupUser($user); $social = new Social(); $social->connectAccount($network_code, $uid); unset($_SESSION['connect_social']); Util::jump_to('index.php?r=lms/elearning/show'); } else { Util::jump_to('index.php?modname=login&op=social_connect_login&err=1'); } } } } switch (Get::gReq('err', DOTY_INT, 0)) { case 1: $res .= UIFeedback::error(Lang::t('_NOACCESS', 'login'), true); break; case 2: $res .= UIFeedback::error(Lang::t('_NO_SOCIAL_ACCOUNT_TO_CONNECT', 'login') . ' <a href="index.php">' . Lang::t('_TRY_AGAIN', 'login') . '</a>', true); break; } $GLOBALS['page']->add(getTitleArea($lang->def('_LOGIN'), 'login') . '<div class="std_block">' . getBackUi('index.php', $lang->def('_BACK')), 'content'); if ($can_connect) { $res .= Get::img('social/' . $network_code . '-24.png') . ' '; $res .= str_replace('[network_code]', Lang::t($network_code, 'social'), Lang::t('_YOU_ARE_CONNECTING_SOCIAL_ACCOUNT', 'social')) . " <b>" . $uid . "</b>"; } $res .= Form::openForm('scl_form', 'index.php?modname=login&op=social_connect_login') . Form::openElementSpace() . Form::getTextfield(Lang::t('_USERNAME', 'login'), 'login_userid', 'login_userid', 255) . Form::getPassword(Lang::t('_PASSWORD', 'login'), 'login_pwd', 'login_pwd', 255) . Form::closeElementSpace() . Form::openButtonSpace() . Form::getButton('login', 'login', Lang::t('_LOGIN', 'login')) . Form::getButton('undo', 'undo', Lang::t('_UNDO', 'login')) . Form::closeButtonSpace() . Form::closeForm(); $GLOBALS['page']->add($res, 'content'); // std_block $GLOBALS['page']->add('</div>', 'content'); // std_block }
$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); } else { Util::jump_to('index.php?access_fail=2');