Skip to content

Instantly share code, notes, and snippets.

@timothyclemans
Created April 23, 2014 10:24
Show Gist options
  • Save timothyclemans/11209978 to your computer and use it in GitHub Desktop.
Save timothyclemans/11209978 to your computer and use it in GitHub Desktop.
[wearscript] WearScriptOS
<html style="width:100%; height:100%; overflow:hidden">
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body style="background:#000; overflow:hidden; margin:0; color:#FFF; margin:40px; font-size:40px;">
<div id="main"></div>
<script>
// 1. Display "Tap the touchpad to login with your QR code."
// 2. Scan QR code
// 3. Get password
// 4. Check password: if correct call callback else re get password
var password = {};
password.gestures = {'TAP': 'A', 'TWO_TAP': 'B', 'THREE_TAP': 'C', 'SWIPE_LEFT': 'D', 'SWIPE_RIGHT': 'E'};
password.getPassword = function() {
password.i = 0;
password.password = '';
password.len = 8; // standard length of a password
$('#main').text('Password: ');
WS.gestureCallback('onGesture', function(name) {
password.password += password.gestures[name]; // Convert the touchpad gesture to a uppercase letter A through E and add it the password str
WS.log(password.password);
$('#main').append('*'); // display * each time user touchs the touchpad
password.i += 1;
if (password.i == password.len) // if # of characters == predefined length of passwords in general
{
if (password.password == 'DDDDDDDD') {
//WS.say('correct password');
launchHomeScreen();
} else {
$('#main').text('Wrong password. Tap the touchpad to retry logging in.');
WS.gestureCallback('onGesture', function(name) {
if (name == 'TAP') {
password.getPassword();
}
});
}
}
});
};
function launchHomeScreen() {
$('#main').text('Home screen 5 patients');
WS.gestureCallback('onGesture', function (name) {
WS.log('lock() gesture callback, gesture name: '+name);
if (name == 'TAP') {
WS.qr(function(data){
password.user_id = data;
password.getPassword();
});
}
});
}
function lock() {
WS.log('locking')
// Display "Tap the touchpad to login"
$('#main').text('Tap the touchpad to login with your QR code.');
WS.gestureCallback('onGesture', function (name) {
WS.log('lock() gesture callback, gesture name: '+name);
if (name == 'TAP') {
WS.qr(function(data){
password.user_id = data;
password.getPassword();
});
}
});
}
function server() {
}
function main() {
WS.serverConnect('{{WSUrl}}', 'server');
lock();
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment