Commit 0efad943 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Get user settings through web login

parent 84db18c6
......@@ -17,6 +17,7 @@ var globals = {
'container': null,
'directory': null,
'pithos_url': null,
'weblogin': null,
'exclude': null
},
'status': {"progress": null, "paused": null}
......
......@@ -21,11 +21,60 @@
exclude = get_setting('exclude');
if (exclude) $('#exclude').val(
fs.readFileSync(exclude, encoding='utf-8'));
var weblogin = get_setting('weblogin');
var pithos_url = get_setting('pithos_url');
if (weblogin && pithos_url) {
$('#get_creds').show();
} else {
console.log('No pithos view, remove credential button');
$('#get_creds').hide();
}
});
function update_exclude(new_content) {
if (exclude) fs.writeFile(exclude, new_content);
}
function extract_credentials(cookie) {
var credentials = cookie.value.split('%7C');
var uuid = credentials[0];
var token = credentials[1];
//$('#uuid').html(uuid);
$('#token').val(token);
$('#token').trigger('change');
//set_setting('token', $(this).val())
}
var gui = require('nw.gui');
function extract_cookie(url) {
var cookie_name = '_pithos2_a';
var w = gui.Window.open(url, {
focus: true, width: 520, height: 841
});
w.cookies.getAll({name: cookie_name}, function(cookies) {
if (cookies.length) {
console.log('Already logged in');
extract_credentials(cookies[0]);
w.close();
} else {
console.log('Not logged in');
}
});
w.cookies.onChanged.addListener(function(info) {
if (info.cookie.name === cookie_name) {
console.log('Succesfully logged in');
extract_credentials(info.cookie);
w.close();
}
});
}
function get_credentials() {
var weblogin = get_setting('weblogin')
var pithos_url = get_setting('url');
extract_cookie(weblogin + '?next=' + pithos_url);
}
</script>
</head>
<body>
......@@ -60,6 +109,13 @@
<small class="error" style="visibility: hidden">Invalid entry</small>
</div>
</div>
<div class="clearfix">
<a id="get_creds"
class="button right" style="display: none;"
onclick="get_credentials();">Get credentials</a>
</div>
</fieldset>
<fieldset>
<legend>What to sync</legend>
......@@ -107,9 +163,9 @@
</div> -->
</div>
<div class="small-4 columns">
<!--<div class="small-4 columns">
<p class="panel">I have no idea what will happen if I put my credentials there...<br>My space could be used to explain what is going on here.</p>
</div>
</div>-->
</div>
</div>
......
......@@ -61,11 +61,12 @@ class WebSocketProtocol(WebSocket):
accepted = False
settings = dict(
token='token',
url=' https://accounts.okeanos.grnet.gr/identity/v2.0',
url='https://accounts.okeanos.grnet.gr/identity/v2.0',
container='pithos',
directory='/tmp/.',
exclude=abspath('exclude.cnf'),
pithos_url='https://pithos.okeanos.grnet.gr/ui/')
pithos_url='https://pithos.okeanos.grnet.gr/ui/',
weblogin='https://accounts.okeanos.grnet.gr/ui')
status = dict(progress=0, paused=False)
# Syncer-related methods
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment