Permalink
Browse files

logging, fixes

  • Loading branch information...
ianb committed Feb 2, 2012
1 parent c2dfbc1 commit 3e87f7503ed12d55ef111b0e1e655818cbd3e8b7
Showing with 46 additions and 16 deletions.
  1. +1 −1 index.php
  2. +39 −14 login.js
  3. +6 −1 login.php
View
@@ -7,4 +7,4 @@
Welcome to this site!
-<? include('footer.php'); ?>
+<? include('footer.php'); ?>
View
@@ -3,14 +3,6 @@ var SETTINGS = {
verificationPage: '/verify.php'
};
-var cookie = document.cookie + '';
-var match = /serverstatus="?([^" ;.]+)/.exec(cookie);
-if (match) {
- var serverStatus = JSON.parse(base64urldecode(match[1]));
-} else {
- var serverStatus = {};
-}
-
if ((! console) || (! console.log)) {
if (! console) {
console = {};
@@ -20,6 +12,16 @@ if ((! console) || (! console.log)) {
}
}
+var cookie = document.cookie + '';
+var match = /serverstatus="?([^" ;.]+)/.exec(cookie);
+if (match) {
+ var serverStatus = JSON.parse(base64urldecode(match[1]));
+ console.log('Got existing serverstatus', serverStatus);
+} else {
+ var serverStatus = {};
+ console.log('No serverstatus');
+}
+
function needPurchase() {
alert('You will be redirected to the purchase page');
location.href = SETTINGS.purchasePage;
@@ -34,15 +36,15 @@ function startLoginProcess() {
if (status.receiptVerified && status.receiptUsers) {
// We have a confirmed receipt and set of users, we just need to
// get a login that matches one of those users
- console.log('Have receipt, need users', status);
+ console.log('Have verified receipt, need users', status);
getUser(receiptUsers, function (assertions) {
sendServerData({assertions: assertions});
});
return;
}
if (status.receiptVerified && (! status.receiptUsers)) {
// This shouldn't happen!
- console.warn("Server send receiptVerified, but not receiptUsers, yes also says the verification is not complete");
+ console.warn("Server send receiptVerified, but not receiptUsers, yet also says the verification is not complete");
}
// From here we get the receipt if we can, then try to verify it
navigator.mozApps.amInstalled(function (app) {
@@ -52,9 +54,9 @@ function startLoginProcess() {
needPurchase();
return;
}
- console.log('got app', app);
var installData = app.install_data || app.installData || {};
var receipts = app.receipts || installData.receipts || [installData.receipt] || [];
+ console.log('got receipts', receipts);
if ((! receipts) || (! receipts.length)) {
console.log('No receipts in app');
needPurchase();
@@ -70,6 +72,7 @@ function startLoginProcess() {
}
if (! users.length) {
// FIXME: I don't think this can happen so long as receipts are valid
+ console.log('No users found for receipt, will try to repurchase');
needPurchase();
return;
}
@@ -104,11 +107,23 @@ function base64urldecode(arg) {
function getUser(users, callback) {
gUsersRequired = users;
gUserCallback = callback;
+ var userEl = document.getElementById('login-user');
+ userEl.innerHTML = '';
+ if (users.length) {
+ userEl.appendChild(document.createTextNode('You must confirm your identity as ' + users[0]));
+ }
+ document.getElementById('login-section').style.display = '';
}
var gUsersRequired = null;
var gUserCallback = null;
+function notifyComplete() {
+ document.getElementById('login-section').style.display = 'none';
+ document.getElementById('complete-section').style.display = '';
+ // FIXME: and do the redirect
+}
+
function sendServerData(data) {
console.log('sending data', data, 'to', SETTINGS.verificationPage);
var req = new XMLHttpRequest();
@@ -121,13 +136,20 @@ function sendServerData(data) {
console.warn('Got non-200 response from server', req);
return;
}
- var data = JSON.parse(req.responseText);
+ try {
+ var data = JSON.parse(req.responseText);
+ } catch (e) {
+ console.log('Got invalid JSON:', e);
+ throw e;
+ }
+ console.log('Got response:', data);
if (data.complete) {
// FIXME: keep track of actual destination here
alert('Everthing is cool, redirecting back to the site');
location.href = '/';
} else {
// What then?
+ alert('Reloading, because otherwise unsure what to do');
location.reload();
}
};
@@ -137,6 +159,7 @@ function sendServerData(data) {
body.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
}
}
+ console.log('Sending serialized data:', data.join('&'));
req.send(data.join('&'));
}
@@ -147,17 +170,19 @@ function runLogin() {
}
if (! serverStatus.complete) {
startLoginProcess();
+ } else {
+ notifyComplete();
}
var el = document.getElementById('login');
el.addEventListener('click', function () {
var idOptions = {};
if (gUsersRequired && gUsersRequired.length) {
idOptions.requiredEmail = gUsersRequired[0];
}
- console.log('calling navigator.id.get(callback,', idOptions);
+ console.log('calling navigator.id.get(callback,', idOptions, ')');
navigator.id.get(function (assertion) {
console.log('got assertion', assertion);
- gUserCallack([assertion]);
+ gUserCallback([assertion]);
}, idOptions);
}, false);
}
View
@@ -10,8 +10,13 @@
include('header.php');
?>
-<div id="login-section">
+<div id="login-section" style="display: none">
+<span id="login-user"></span>
<a href="#" id="login"><img src="https://browserid.org/i/sign_in_blue.png"></a>
</div>
+<div id="complete-section" style="display: none">
+Thank you for your purchase and confirmation!
+</div>
+
<? include('footer.php'); ?>

0 comments on commit 3e87f75

Please sign in to comment.