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
......@@ -2,8 +2,39 @@
<html>
<head>
<title></title>
<link href="static/css/bootstrap.edited.css" rel="stylesheet"/>
<!--<link href="static/css/bootstrap.min.css" rel="stylesheet"/>-->
<link href="static/css/bootstrap.min.css" rel="stylesheet"/>
<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>
<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>
<script id="service" type="text/html">
{{! Service page template }}
......@@ -117,33 +148,33 @@
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<div class="span3">
<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 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="#"><i class="icon-plus-sign"></i>Add new service</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/201"><i class="icon-"></i>inst-1</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">
<!--<li><form class="form-search">
<i class="icon-search"></i>
<input type="text" class="input-mini search-query">
</form></li>
</form></li>-->
</ul>
</div>
</div>
<section class="span10" id="main">
<section class="span9" id="main">
<!--Body content-->
</section>
</div>
......@@ -155,7 +186,6 @@
<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>
</body>
......
......@@ -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
}*/
......@@ -7,34 +7,79 @@
var methods = {
init: function() {
// Initialize slapos in this context
$(this).slapos({host: ''});
$(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 == "form") { self.form('displayForm'); }
else if(d.route == "service" && d.id) { self.form('displayData', d.id); }
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);
}, {408: function(){ $(this).form('render', 'service-error', {id:id})}});
}, {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', 'simple-form');
$(this).form('render', 'form.new.instance');
var data = {};
$(this).find("form").submit(function(){
$.redirect({route:'disp', id:$(this).find("input:text").val()});
$(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));
}
......
......@@ -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']; }
......
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