prototype cryptographic login
parent
4cd9bd5534
commit
94fbc2dca4
@ -0,0 +1,62 @@
|
|||||||
|
<ch!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<script data-main="main" src="/bower_components/requirejs/require.js"></script>
|
||||||
|
|
||||||
|
<title>Cryptpad/user/</title>
|
||||||
|
<link rel="icon" type="image/png"
|
||||||
|
href="/customize/main-favicon.png"
|
||||||
|
data-main-favicon="/customize/main-favicon.png"
|
||||||
|
data-alt-favicon="/customize/alt-favicon.png"
|
||||||
|
id="favicon" />
|
||||||
|
<link rel="stylesheet" href="/customize/main.css" />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#bar {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
font-size: 20px;
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="bar">
|
||||||
|
<input id="uname" type="text" placeholder="your username">
|
||||||
|
<input id="password" type="password" placeholder="your password">
|
||||||
|
<button id="login" class="action login">---</button>
|
||||||
|
</div>
|
||||||
|
<div id="main"></div>
|
||||||
|
|
||||||
|
<table id="userstore" class="recent scroll" style="display:none">
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Link</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Last Accessed</th>
|
||||||
|
<th></th> <!-- remove column -->
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table id="localstore" class="recent scroll" style="display:none">
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Link</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Last Accessed</th>
|
||||||
|
<th></th> <!-- remove column -->
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
@ -0,0 +1,116 @@
|
|||||||
|
define([
|
||||||
|
'/api/config?cb=' + Math.random().toString(16).slice(2),
|
||||||
|
'/customize/messages.js',
|
||||||
|
'/common/cryptpad-common.js',
|
||||||
|
'/bower_components/chainpad-crypto/crypto.js',
|
||||||
|
|
||||||
|
], function (Config, Messages, Cryptpad, Crypto) {
|
||||||
|
var $ = window.jQuery;
|
||||||
|
|
||||||
|
|
||||||
|
var APP = window.APP = {
|
||||||
|
Cryptpad: Cryptpad,
|
||||||
|
spinner: Cryptpad.spinner(document.body),
|
||||||
|
};
|
||||||
|
|
||||||
|
var login = function (uname, passwd, cb) {
|
||||||
|
Cryptpad.User.genSecret(uname, passwd, function (err, secret) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
Cryptpad.User.session(secret, function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
cb(err, secret);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var $uname = $('#uname');
|
||||||
|
var $passwd = $('#password');
|
||||||
|
var $login = $('#login');
|
||||||
|
|
||||||
|
var lockInputs = function (bool) {
|
||||||
|
[$uname, $passwd].forEach(function ($e) {
|
||||||
|
$e.attr('disabled', bool);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var ready = function (loggedIn) {
|
||||||
|
APP.loggedIn = loggedIn;
|
||||||
|
|
||||||
|
$login
|
||||||
|
.text(loggedIn?'log out': 'log in')
|
||||||
|
.click(function () {
|
||||||
|
if (APP.loggedIn) {
|
||||||
|
Cryptpad.User.session(null, function (err) {
|
||||||
|
$login.text('log in');
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var uname = $uname.val();
|
||||||
|
var passwd = $passwd.val();
|
||||||
|
|
||||||
|
if (!uname) {
|
||||||
|
console.log("expected a username");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!passwd) {
|
||||||
|
console.log("expected a password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
login(uname, passwd, function (err, secret) {
|
||||||
|
console.log(secret);
|
||||||
|
if (secret) {
|
||||||
|
$login.text('log out');
|
||||||
|
APP.loggedIn = true;
|
||||||
|
lockInputs(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
lockInputs(loggedIn);
|
||||||
|
[$uname, $passwd]
|
||||||
|
.forEach(function ($e, i) {
|
||||||
|
$e.on('keyup', function (e) {
|
||||||
|
if (!(e.which === 13 && $e.val())) { return; }
|
||||||
|
if (i === 0) {
|
||||||
|
$passwd.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$login.click();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var change = Cryptpad.find(Cryptpad, ['store','change']);
|
||||||
|
if (typeof(change) === 'function') {
|
||||||
|
change(function (data) {
|
||||||
|
if (data.key === Cryptpad.User.localKey) {
|
||||||
|
// HERE
|
||||||
|
console.log("Login data modified");
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Cryptpad.ready(function (err, env) {
|
||||||
|
console.log("Cryptpad is ready!");
|
||||||
|
console.log(env);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (env.userStore) {
|
||||||
|
console.log("You're logged in!");
|
||||||
|
ready(true);
|
||||||
|
} else {
|
||||||
|
ready(false);
|
||||||
|
console.log("Not logged in");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue