Skip to content

Instantly share code, notes, and snippets.

@jellis
Created November 26, 2014 01:13
Show Gist options
  • Save jellis/91bb1e5f75503d39a378 to your computer and use it in GitHub Desktop.
Save jellis/91bb1e5f75503d39a378 to your computer and use it in GitHub Desktop.
<?php
session_start();
require_once('lib.php');
/**
* So you can check with javascript something like
* if (data.type == 'error') // Hasn't worked
* if (data.type == 'success') // Work with data.value (this will be person)
*/
$response = ['type' => 'error'];
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
if (!empty($_POST) && isset($_POST['email']) && isset($_POST['passwd']) && isset($_POST['partnerId'])) {
$person = authenticate($_POST['email'], $_POST['passwd'], $_POST['partnerId']);
}
// Person is empty or false
if (!$person) {
$_SESSION = [];
session_destroy();
} else { // This "login" stuff
$_SESSION['user'] = $person['email_user_id'];
$_SESSION['person'] = $person;
$_SESSION['sid'] = base64_encode($person['email_user_id']);
$_SESSION['psid'] = base64_encode($person['person_id']);
$response = [
'type' => 'success',
'value' => $person
];
}
}
echo json_encode($response);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment