require_once 'config.inc'; require_once ENGINE . 'Default/smr.inc'; require_once get_file_loc('SmrMySqlDatabase.class.inc'); require_once get_file_loc('SmrAccount.class.inc'); require_once get_file_loc('SmrSession.class.inc'); $db = new SmrMySqlDatabase(); $db2 = new SmrMySqlDatabase(); // ******************************** // * // * C r e a t e S e s s i o n // * // ******************************** if (SmrSession::$account_id == 0) { if (isset($_REQUEST['loginType'])) { require_once LIB . 'Login/SocialLogin.class.inc'; $socialLogin = new SocialLogin($_REQUEST['loginType']); if (!$socialLogin->isValid()) { $msg = 'Error validating login.'; header('Location: ' . URL . '/login.php?msg=' . rawurlencode(htmlspecialchars($msg, ENT_QUOTES))); exit; } $loginType = $socialLogin->getLoginType(); $authKey = $socialLogin->getUserID(); $db->query('SELECT account_id,old_account_id FROM account JOIN account_auth USING(account_id) WHERE login_type = ' . $db->escapeString($loginType) . ' AND auth_key = ' . $db->escapeString($authKey) . ' LIMIT 1'); if ($db->nextRecord()) { // register session SmrSession::$account_id = $db->getInt('account_id'); SmrSession::$old_account_id = $db->getInt('old_account_id'); } else {
public function Controller_Validate($Sender) { $form_values = array('user_email' => $Sender->Form->GetValue('user_email'), 'user_login' => $Sender->Form->GetValue('user_login'), 'val_id' => $Sender->Form->GetValue('val_id')); $oasl = new SocialLogin(); $oa_profile = $oasl->get_validation_data($form_values['val_id']); if ($oa_profile === FALSE) { SafeRedirect(Url(Gdn::Router()->GetDestination('DefaultController'), TRUE)); } $to_validate = array_merge($form_values, $oa_profile); if ($Sender->Form->IsPostBack() == TRUE) { // Verify new user submitted data: // TODO explore vanilla validation: as in $Valid = Gdn_Validation::ValidateRule ($to_validate ['user_email'], 'Email', 'function:ValidateEmail'); $valid = TRUE; if (empty($to_validate['user_login'])) { $to_validate['user_login'] = $to_validate['identity_provider'] . 'User'; $valid = FALSE; } if ($oasl->get_user_id_by_username($to_validate['user_login']) !== FALSE) { $i = 1; $user_login_tmp = $to_validate['user_login'] . $i; while ($oasl->get_user_id_by_username($user_login_tmp) !== FALSE) { $user_login_tmp = $to_validate['user_login'] . $i++; } $to_validate['user_login'] = $user_login_tmp; $valid = FALSE; } if (empty($to_validate['user_email'])) { $Sender->Form->AddError('OA_SOCIAL_LOGIN_VALIDATION_FORM_EMAIL_NONE_EXPLAIN', 'user_email'); $valid = FALSE; } if ($oasl->get_user_id_by_email($to_validate['user_email']) !== FALSE) { $to_validate['user_email'] = ''; $Sender->Form->AddError('OA_SOCIAL_LOGIN_VALIDATION_FORM_EMAIL_EXISTS_EXPLAIN', 'user_email'); $valid = FALSE; } if ($valid) { $avatar = C(self::CONFIG_PREFIX . 'AvatarsEnable', 1); $redirect = C(self::CONFIG_PREFIX . 'Redirect', ''); $to_validate['redirect'] = empty($redirect) ? Url($to_validate['redirect'], TRUE) : $redirect; $oasl->delete_validation_data($to_validate['val_id']); $oasl->social_login_resume_handle_callback($to_validate, $avatar); } } $Sender = $this->set_validation_fields($Sender, $to_validate); $Sender->Render($this->GetView('oa_social_login_validate.php')); }
</table> </li> <li> <table class="Label AltColumns"> <thead> <tr> <th colspan="2"><?php echo T('OA_SOCIAL_LOGIN_ENABLE_NETWORKS'); ?> </th> </tr> </thead> <tbody> <tr> <td><?php foreach (SocialLogin::all_providers() as $id => $name) { echo '<label for="' . $this->Form->EscapeID(OneallSocialLogin::PROVIDER_PREFIX . $id, FALSE) . '" class="CheckBoxLabel oa_social_login_provider" >'; echo '<span class="oa_social_login_provider_' . $id . '" title="' . $name . '">' . $name . '</span>'; echo $this->Form->CheckBox(OneallSocialLogin::PROVIDER_PREFIX . $id); echo $name; echo '</label>'; } ?> </td> </tr> </tbody> </table> </li> </ul> </div>
switch ($_SESSION['login_method']) { case 'facebook': $socialLogin = new SocialLogin('facebook'); $socialLogin->app_id = ''; $socialLogin->app_secret_code = ''; $socialLogin->redirect_uri = 'http://test.local/sociallogin'; //The domain be setted in the Facebook App settings break; case 'linkedin': $socialLogin = new SocialLogin('linkedin'); $socialLogin->app_id = ''; $socialLogin->app_secret_code = ''; $socialLogin->redirect_uri = 'http://test.local/sociallogin'; break; case 'googleplus': $socialLogin = new SocialLogin('googleplus'); $socialLogin->app_id = ''; $socialLogin->app_secret_code = ''; $socialLogin->redirect_uri = 'http://localhost:8000/'; break; default: die; } echo '<pre>'; if (!isset($_GET['code'])) { $socialLogin->getAuthCode(); } else { if (isset($socialLogin)) { $socialLogin_response = $socialLogin->getAccessToken($_GET['code']); if (!isset($socialLogin_response->error->code)) { if (is_array($socialLogin_response)) {