Commit 3e8436aa authored by Thomas Lechauve's avatar Thomas Lechauve

Authentication process implemented (with OAuth2)

The fake server has been commented so instance information page won't
appear anymore.
parent ea194c88
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="static/css/bootstrap.edited.css" rel="stylesheet"/>
<!--<link href="static/css/bootstrap.min.css" rel="stylesheet"/>-->
<title></title>
<link href="static/css/bootstrap.min.css" rel="stylesheet"/>
<script id="service" type="text/html">
{{! Service page template }}
<article>
<form class="form-horizontal">
<fieldset>
<legend>
{{ instance_id }}
<div class="pull-right">
<div class="btn">Bang</div>
<div class="btn">Destroy</div>
<div class="btn">Certificates</div>
</div>
</legend>
<div class="control-group">
<label class="control-label">Reference</label>
<div class="controls">
<span class="uneditable-input">{{ instance_id }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Software release</label>
<div class="controls">
<span class="uneditable-input">{{ software_release }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Software type</label>
<div class="controls">
<span class="uneditable-input">{{ software_type }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Status</label>
<div class="controls">
<div class="btn-group">
<button class="btn">Stop</button>
<button class="btn btn-success disabled">Started</button>
</div>
</div>
</div>
</fieldset>
</form>
<script id="form.new.instance" type="text/html">
<article>
<form class="form-horizontal">
<fieldset>
<legend>Request a new instance</legend>
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<input type="text" class="input-large" required name="title"/>
</div>
</div>
<div class="control-group">
<label class="control-label">Software release</label>
<div class="controls">
<input type="text" class="input-xlarge" required name="software_release"/>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" name="submit">Request</button>
</div>
</fieldset>
</form>
</article>
</script>
<table class="table">
<caption>Connection parameters</caption>
{{# connection}}
<tr><td>key</td><td>{{ key }}</td></tr>
{{/ connection}}
</table>
<script id="auth" type="text/html">
<article>
<p>Authentification needed. Are you agree to be redirect to login ?</p>
<a href="http://{{ host }}?response_type=token&client_id={{ client_id }}&redirect_uri={{ redirect }}">Redirect</a>
</article>
</script>
<form>
<fieldset>
<legend>
Parameter XML
<div class="pull-right">
<button type="submit" class="btn btn-primary">Save changes</button>
<button class="btn">Cancel</button>
</div>
</legend>
<textarea name="xml" style="width: 98%; height: 110px;">
<script id="service" type="text/html">
{{! Service page template }}
<article>
<form class="form-horizontal">
<fieldset>
<legend>
{{ instance_id }}
<div class="pull-right">
<div class="btn">Bang</div>
<div class="btn">Destroy</div>
<div class="btn">Certificates</div>
</div>
</legend>
<div class="control-group">
<label class="control-label">Reference</label>
<div class="controls">
<span class="uneditable-input">{{ instance_id }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Software release</label>
<div class="controls">
<span class="uneditable-input">{{ software_release }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Software type</label>
<div class="controls">
<span class="uneditable-input">{{ software_type }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Status</label>
<div class="controls">
<div class="btn-group">
<button class="btn">Stop</button>
<button class="btn btn-success disabled">Started</button>
</div>
</div>
</div>
</fieldset>
</form>
<table class="table">
<caption>Connection parameters</caption>
{{# connection}}
<tr><td>key</td><td>{{ key }}</td></tr>
{{/ connection}}
</table>
<form>
<fieldset>
<legend>
Parameter XML
<div class="pull-right">
<button type="submit" class="btn btn-primary">Save changes</button>
<button class="btn">Cancel</button>
</div>
</legend>
<textarea name="xml" style="width: 98%; height: 110px;">
<?xml version="1.0" encoding="utf-8"?>
<instance>
<parameter id="nbd_ip">2a01:e35:2e27:460:e2cb:4eff:fed9:48dc</parameter>
<parameter id="nbd_port">1024</parameter>
<parameter id="nbd_ip">2a01:e35:2e27:460:e2cb:4eff:fed9:48dc</parameter>
<parameter id="nbd_port">1024</parameter>
</instance>
</textarea>
</fieldset>
</form>
</article>
</script>
<script id="simple-form" type="text/html">
<form class="form-inline">
<fieldset>
<div class="input-append">
<input required class="span2" size="16" type="text"/>
<button class="btn" type="submit">Go !</button>
</div>
</fieldset>
</form>
</script>
</textarea>
</fieldset>
</form>
</article>
</script>
<script id="simple-form" type="text/html">
<form class="form-inline">
<fieldset>
<div class="input-append">
<input required class="span2" size="16" type="text"/>
<button class="btn" type="submit">Go !</button>
</div>
</fieldset>
</form>
</script>
<script id="service-error" type="text/html">
<div class="alert alert-error" style="text-align: center;">
<h4>Service : {{ id }} not found !</h4>
</div>
</script>
<script id="service-error" type="text/html">
<div class="alert alert-error" style="text-align: center;">
<h4>Service : {{ id }} not found !</h4>
</div>
</script>
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<!--<a href="#" class="brand">Vifib</a>-->
<img src="static/img/vifib_logo.gray.png" style="max-height: 40px" />
</div>
<div class="span10">
<ul class="nav">
<li><a href="#">Dashboard</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<!--<a href="#" class="brand">Vifib</a>-->
<img src="static/img/vifib_logo.gray.png" style="max-height: 40px" />
</div>
<div class="span10">
<ul class="nav">
<li><a href="#">Dashboard</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Servers</li>
<li><a href="#"><i class="icon-list"></i>List all servers</a></li>
<li><a href="#"><i class="icon-plus-sign"></i>Add new server</a></li>
<li><a href="#"><i class="icon-star"></i>Favorites</a></li>
<li class="nav-header">Services</li>
<li><a href="#"><i class="icon-list"></i>List all services</a></li>
<li><a href="#"><i class="icon-plus-sign"></i>Add new service</a></li>
<li><a href="#"><i class="icon-star"></i>Favorites</a></li>
<ul style="list-style: none">
<li><a href="#service/200"><i class="icon-"></i>inst-0</a></li>
<li><a href="#service/201"><i class="icon-"></i>inst-1</a></li>
</ul>
<li class="nav-header">Account</li>
<li><a href="#"><i class="icon-inbox"></i>Invoices</a></li>
<li><a href="#"><i class="icon-cog"></i>Settings</a></li>
<li class="nav-header">Quick search</li>
<li><form class="form-search">
<i class="icon-search"></i>
<input type="text" class="input-mini search-query">
</form></li>
</ul>
</div>
</div>
<section class="span10" id="main">
<!--Body content-->
</section>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Servers</li>
<li autofocus="autofocus"><a href="#"><i class="icon-list"></i>List all servers</a></li>
<li><a href="#"><i class="icon-plus-sign"></i>Add new server</a></li>
<li><a href="#"><i class="icon-star"></i>Favorites</a></li>
<li class="nav-header">Services</li>
<li><a href="#"><i class="icon-list"></i>List all services</a></li>
<li><a href="#service"><i class="icon-plus-sign"></i>Add new service</a></li>
<li><a href="#"><i class="icon-star"></i>Favorites</a></li>
<ul style="list-style: none">
<li><a href="#service/200"><i class="icon-"></i>inst-0</a></li>
<li><a href="#service/401"><i class="icon-"></i>inst-1</a></li>
</ul>
<li class="nav-header">Account</li>
<li><a href="#"><i class="icon-inbox"></i>Invoices</a></li>
<li><a href="#"><i class="icon-cog"></i>Settings</a></li>
<li class="nav-header">Quick search</li>
<!--<li><form class="form-search">
<i class="icon-search"></i>
<input type="text" class="input-mini search-query">
</form></li>-->
</ul>
</div>
</div>
<section class="span9" id="main">
<!--Body content-->
</section>
</div>
</div>
<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="static/js/ICanHaz.min.js"></script>
<script type="text/javascript" src="static/js/modernizr-2.5.3.js"></script>
<script type="text/javascript" src="static/js/sinon-1.3.2.js"></script>
<script type="text/javascript" src="static/js/slapOs.js"></script>
<script type="text/javascript" src="static/js/fake.js"></script>
<script type="text/javascript" src="static/js/renderer.js"></script>
<script type="text/javascript" src="static/js/urlHandler.js"></script>
<script type="text/javascript" src="static/js/form.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="static/js/ICanHaz.min.js"></script>
<script type="text/javascript" src="static/js/modernizr-2.5.3.js"></script>
<script type="text/javascript" src="static/js/sinon-1.3.2.js"></script>
<script type="text/javascript" src="static/js/slapOs.js"></script>
<script type="text/javascript" src="static/js/fake.js"></script>
<script type="text/javascript" src="static/js/urlHandler.js"></script>
<script type="text/javascript" src="static/js/form.js"></script>
</body>
</html>
\ No newline at end of file
</html>
......@@ -68,17 +68,18 @@ var inst1 =
tap_interface: "tap2"}
};
var fakeserver = sinon.fakeServer.create();
/*var fakeserver = sinon.fakeServer.create();
// Get instance
fakeserver.respondWith("GET", "/instance/200",[200, {"Content-Type":"application/json; charset=utf-8"}, JSON.stringify(inst0)]);
fakeserver.respondWith("GET", "/instance/201",[200, {"Content-Type":"application/json; charset=utf-8"}, JSON.stringify(inst1)]);
// Get instance FAIL
fakeserver.respondWith("GET", "/instance/408",[408, {"Content-Type":"application/json; charset=utf-8"}, "NOT FOUND"]);
fakeserver.respondWith("GET", "/instance/401",[401, {"Content-Type":"application/json; charset=utf-8"}, "NEED AUTH"]);
var tmp = $.ajax;
$.ajax = function(url, options){
/*$.ajax = function(url, options){
var result = tmp(url, options);
fakeserver.respond();
return result;
}
\ No newline at end of file
}*/
......@@ -4,51 +4,96 @@
* Date: 4/17/12
*/
;(function($) {
var methods = {
init: function() {
// Initialize slapos in this context
$(this).slapos({host: ''});
// Bind to urlChange event
return this.each(function(){
var self = $(this);
$.subscribe("urlChange", function(e, d){
if(d.route == "form") { self.form('displayForm'); }
else if(d.route == "service" && d.id) { self.form('displayData', d.id); }
});
});
},
displayData: function(id){
$(this).html("<p>Ajax loading...</p>")
.slapos('getInstance', id, function(data){
$(this).form('render', 'service', data);
}, {408: function(){ $(this).form('render', 'service-error', {id:id})}});
},
displayForm: function() {
$(this).form('render', 'simple-form');
$(this).find("form").submit(function(){
$.redirect({route:'disp', id:$(this).find("input:text").val()});
return false;
});
},
render: function(template, data){
$(this).html(ich[template](data, true));
}
};
$.fn.form = function(method){
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.form' );
}
};
var methods = {
init: function() {
// Initialize slapos in this context
$(this).slapos({host: '10.0.1.139:12002/erp5/portal_vifib_rest_api_v1'});
// Bind to urlChange event
return this.each(function(){
var self = $(this);
$.subscribe("urlChange", function(e, d){
if(d.route == "service" && d.id) { self.form('displayData', d.id); }
else if(d.route == "service") { self.form('displayForm'); }
});
$.subscribe("auth", function(e, d){
$(this).form("authenticate", d);
});
});
},
authenticate: function(data){
for(var d in data){
$(this).slapos('store', d, data[d]);
}
},
displayData: function(id){
$(this).html("<p>Ajax loading...</p>")
.slapos('getInstance', id, function(data){
$(this).form('render', 'service', data);
}, {401: function(){
$(this).form('render', 'auth', {
'host':'t139:12002/erp5/web_site_module/hosting/request-access-token',
'client_id': 'client',
'redirect':escape(window.location.href)
})
}});
},
displayForm: function() {
$(this).form('render', 'form.new.instance');
var data = {};
$(this).find("form").submit(function(){
$(this).find('input').serializeArray().map(function(elem){
data[elem["name"]] = elem["value"];
});
$(this).form('displayAsking', data);
return false;
});
},
displayAsking: function(data){
var request = {
software_type: "type_provided_by_the_software",
slave: false,
status: "started",
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: ["abc", "def"],
},
sla: {
computer_id: "COMP-0",
}
};
$.extend(request, data);
$(this).html("<p>Requesting a new instance "+request["title"]+" ...</p>")
.slapos('newInstance', request, function(data){
$(this).html(data);}, {401: function(){
$(this).form('render', 'auth', {
'host':'t139:12002/erp5/web_site_module/hosting/request-access-token',
'client_id': 'client',
'redirect':escape(window.location.href)
})
}
});
},
render: function(template, data){
$(this).html(ich[template](data, true));
}
};
$.fn.form = function(method){
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.form' );
}
};
})(jQuery);
$("#main").form();
......@@ -7,6 +7,11 @@
;
// Hash parser utility
$.parseHash = function(hashTag){
var tokenized = $.extractAuth(hashTag);
if( tokenized ){
console.log(tokenized);
$.publish('auth', tokenized);
}
var splitted = hashTag.substr(1).split('/');
return {
route : splitted[0],
......@@ -15,6 +20,21 @@ $.parseHash = function(hashTag){
}
};
$.extractAuth = function(hashTag){
var del = hashTag.indexOf('&');
if( del != -1){
var splitted = hashTag.substring(del+1).split('&');
var result = {};
for( p in splitted ){
var s = splitted[p].split('=');
result[s[0]] = s[1];
}
return result;
}
return false;
};
$.genHash = function(url){
if('id' in url){ url['id'] = '/' + url['id']; }
if('method' in url){ url['method'] = '/' + url['method']; }
......@@ -45,4 +65,4 @@ $.redirect = function(url){ $.publish('redirect', url); };
$.subscribe('redirect', $.redirectHandler)
$(window).bind('hashchange', $.hashHandler);
$(window).bind('load', $.hashHandler);
\ No newline at end of file
$(window).bind('load', $.hashHandler);
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