Skip to content
Browse files

Some code cleanup and clear fields of settings dialog

  • Loading branch information...
1 parent 397806e commit 8300a37b12df81c0c9f4b884bba00a99984db70c @gbraad committed
Showing with 18 additions and 7 deletions.
  1. +0 −3 README
  2. +18 −4 code.js
View
3 README
@@ -7,6 +7,3 @@ Deployed test version is available at
PhoneGap builds for WebOS and Android can be found at
http://build.phonegap.com/apps/135419/share
-
-Originally based on the JavaScript implementation as provided by Tin Isles:
-http://blog.tinisles.com/2011/10/google-authenticator-one-time-password-algorithm-in-javascript/
View
22 code.js
@@ -1,3 +1,6 @@
+// Originally based on the JavaScript implementation as provided by Tin Isles:
+// http://blog.tinisles.com/2011/10/google-authenticator-one-time-password-algorithm-in-javascript/
+
function dec2hex(s) {
return (s < 15.5 ? '0' : '') + Math.round(s).toString(16);
}
@@ -52,10 +55,10 @@ function updateOtp(secret) {
}
var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
- return otp = (otp).substr(otp.length - 6, 6);
+ return (otp).substr(otp.length - 6, 6).toString();
}
-function timer() {
+function timerTick() {
var epoch = Math.round(new Date().getTime() / 1000.0);
var countDown = 30 - (epoch % 30);
if (epoch % 30 == 0) {
@@ -75,7 +78,7 @@ function updateKeys() {
delLink.click(function () {
deleteAccount(index)
});
- var detLink = $('<a href="#"><h3 id="account' + index + '">' + account.name + '</h3><p id="key' + index + '">' + key + '</p></a>');
+ var detLink = $('<a href="#"><h3>' + key + '</h3><p>' + account.name + '</p></a>');
var accElem = $('<li>').append(detLink).append(delLink);
accountList.append(accElem);
@@ -86,7 +89,9 @@ function updateKeys() {
function deleteAccount(index) {
var accounts = getObject('accounts');
accounts.splice(index, 1);
+ // Persist in localstorage
setObject('accounts', accounts);
+
updateKeys();
}
@@ -99,10 +104,12 @@ function getObject(key) {
return value && JSON.parse(value);
}
+// Main function
$(function () {
// Check if local storage is supported
if (typeof (Storage) !== "undefined") {
if (!getObject('accounts')) {
+ // Default information
var account = [{
'name': 'alice@google.com',
'secret': 'JBSWY3DPEHPK3PXP'
@@ -111,8 +118,9 @@ $(function () {
}
updateKeys();
- setInterval(timer, 1000);
+ setInterval(timerTick, 1000);
} else {
+ // No support for localStorage
$('#updatingIn').text("x");
$('#account').text("No Storage support");
}
@@ -125,6 +133,12 @@ $(function () {
};
var accounts = getObject('accounts');
accounts.push(account);
+
+ // Empty fields
+ $('#keyAccount').val('');
+ $('#keySecret').val('');
+
+ // Persist in localstorage
setObject('accounts', accounts);
updateKeys();

0 comments on commit 8300a37

Please sign in to comment.
Something went wrong with that request. Please try again.