Initial session support.

This commit is contained in:
Julien Fontanet
2013-01-04 10:57:25 +01:00
parent 91f38af97e
commit b2bfd4e411
10 changed files with 282 additions and 89 deletions

View File

@@ -11,7 +11,7 @@
"require": {
"php": ">=5.3.0",
"monolog/monolog": "~1.2",
"vates/gallic": "~0.2.4",
"vates/gallic": "dev-master",
"vates/xo-lib": "dev-master"
},
"autoload": {

15
composer.lock generated
View File

@@ -1,5 +1,5 @@
{
"hash": "5ad48a363a48c325678f1c0fc47f628a",
"hash": "c53a9b0dd6e704e02bed50b5894b3b56",
"packages": [
{
"name": "monolog/monolog",
@@ -60,24 +60,24 @@
},
{
"name": "vates/gallic",
"version": "v0.2.4",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/julien-f/gallic",
"reference": "v0.2.4"
"reference": "030f63592d85929cdd20d07122aa66a906b3aee3"
},
"dist": {
"type": "zip",
"url": "https://github.com/julien-f/gallic/archive/v0.2.4.zip",
"reference": "v0.2.4",
"url": "https://github.com/julien-f/gallic/archive/030f63592d85929cdd20d07122aa66a906b3aee3.zip",
"reference": "030f63592d85929cdd20d07122aa66a906b3aee3",
"shasum": ""
},
"require": {
"php": ">=5.2.0"
},
"time": "2012-12-17 14:25:36",
"time": "2013-01-04 09:42:19",
"type": "library",
"installation-source": "dist",
"installation-source": "source",
"autoload": {
"files": [
"src/Gallic.php"
@@ -148,6 +148,7 @@
],
"minimum-stability": "stable",
"stability-flags": {
"vates/gallic": 20,
"vates/xo-lib": 20
}
}

View File

@@ -24,6 +24,10 @@
return array(
'xo' => array(
'url' => 'tcp://localhost:1024',
),
'log' => array(
//'email' => 'your.email@provider.tld',
'file' => '#{root_dir}/log',

View File

@@ -34,26 +34,67 @@ final class Application extends Base
{
parent::__construct();
session_start();
$this->_di = $di;
}
/**
*
*/
function getCurrentUser()
{
return isset($_SESSION['user']['name'])
? $_SESSION['user']['name']
: false;
}
/**
*
*/
function getTemplate($template)
{
$template = $this->_di->get('template.manager')->build($template);
$template->filters += array(
'count' => 'count',
'json' => 'json_encode',
);
$template->functions += array(
'url' => array('TemplateUtils', 'url'),
);
$template->variables['user'] = $this->getCurrentUser();
return $template;
}
/**
*
*/
function logIn($name, $password)
{
$xo = $this->_di->get('xo');
if (!$xo->logIn($name, $password))
{
return false;
}
$_SESSION['user']['name'] = $name;
$_SESSION['user']['password'] = $password;
return true;
}
/**
*
*/
function logOut()
{
session_destroy();
return true;
}
/**
*
*/
function redirect($url)
{
header("Location: $url");
}
/**
* @var DI
*/

View File

@@ -107,9 +107,23 @@ final class DI extends Base
private function _init_template_manager()
{
return new Gallic_Template_Manager(
$tm = new Gallic_Template_Manager(
__DIR__.'/../templates',
0
);
$tm->defaultFilters += array(
'count' => 'count',
'json' => 'json_encode',
);
$tm->defaultFunctions += array(
'url' => array('TemplateUtils', 'url'),
);
return $tm;
}
private function _init_xo()
{
return new XO($this->get('config')->get('xo.url'));
}
}

View File

@@ -42,7 +42,7 @@
<link href="css/bootstrap-responsive.css" rel="stylesheet">
{* IE support. *}
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
{* HTML5 shim, for IE6-8 support of HTML5 elements *}
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
@@ -52,80 +52,116 @@
{* Our stylesheet and scripts. *}
<link rel="stylesheet" href="css/style.css">
<link rel="icon" href="img/favicon.ico" />
{* Children templates may used this block to add extra headers. *}
{block extra_html_headers}{/block}
</head>
<body style="padding-top: 60px">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.php"><img src="img/bannerb.png"></a><a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="divider-vertical"></li>
<li {if $pool}class="active"{/if}> <a href="pool.php"><i class="icon-cloud"></i> Pool</a>
</li>
<li {if $server}class="active"{/if}> <a href="servers.php"><i class="icon-cog"></i> Server</a>
</li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-bolt"></i> Vm <b class="caret"></b> </a>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.php"><img src="img/bannerb.png"></a>
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="divider-vertical"></li>
<li {if $pool}class="active"{/if}>
<a href="pool.php"><i class="icon-cloud"></i> Pool</a>
</li>
<li {if $server}class="active"{/if}>
<a href="servers.php"><i class="icon-cog"></i> Server</a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-bolt"></i> Vm <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="#"><i class="icon-reorder"></i> List</a></li>
<li><a href="#"><i class="icon-plus"></i> Add new...</a></li>
<li><a href="#"><i class="icon-plus"></i> Add new</a></li>
<li><a href="#"><i class="icon-cog"></i> Manage</a></li>
<li><a href="#"><i class="icon-file"></i> Templates</a></li>
<li class="divider"></li>
<li><a href="#"><i class="icon-wrench"></i> Options...</a></li>
<li><a href="#"><i class="icon-wrench"></i> Options</a></li>
</ul>
</li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-hdd"></i> Storage <b class="caret"></b></a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-hdd"></i> Storage <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="#"><i class="icon-reorder"></i> List</a></li>
<li><a href="#"><i class="icon-plus"></i> Add new...</a></li>
<li><a href="#"><i class="icon-plus"></i> Add new</a></li>
<li><a href="#"><i class="icon-cog"></i> Manage</a></li>
<li class="divider"></li>
<li><a href="#"><i class="icon-wrench"></i> Options...</a></li>
<li><a href="#"><i class="icon-wrench"></i> Options</a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right">
<li class="divider-vertical"></li>
<li {if $admin}class="active"{/if}><a rel="tooltip" data-original-title="Settings" href="admin.php"><i class="icon-wrench"></i></a></li>
<li><a id="msg" rel="tooltip" data-original-title="No unread notifications" href="#"><i class="icon-bell"></i></a></li>
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown"><i class="icon-signin"></i> Log In <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<!-- Login form here -->
<form>
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input class="span2" type="text" placeholder="User">
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-key"></i></span>
<input class="span2" type="password" placeholder="Password"></input><br/><br/>
</div>
<button type="submit" class="btn btn-info"><i class="icon-signin icon-small"></i> Log In</button>
</form>
</div>
</ul>
<form class="input-prepend navbar-search pull-right navbar-search" action="">
<span class="add-on"><i class="icon-search"></i></span>
<input type="text" class="span2 inputIcon" placeholder="Search">
</form>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</li>
</ul>
<ul class="nav pull-right">
<li class="divider-vertical"></li>
<li {if $admin}class="active"{/if}>
<a rel="tooltip" data-original-title="Settings" href="admin.php"><i class="icon-wrench"></i></a>
</li>
<li>
<a id="msg" rel="tooltip" data-original-title="No unread notifications" href="#"><i class="icon-bell"></i></a>
</li>
<li class="dropdown">
{**
* Session.
*}
{if $user}
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{$user} <strong class="caret"></strong>
</a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<form action="{url to="session"}" method="post">
<button type="submit" class="btn btn-primary btn-block">
<i class="icon-signout icon-small"></i> Log Out
</button>
</form>
</div>
{else}
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<i class="icon-signin"></i> Log In <strong class="caret"></strong>
</a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<form action="session.php" method="post">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input class="span2" type="text" placeholder="User" name="name">
</div>
<!-- end of navbar -->
<div class="input-prepend">
<span class="add-on"><i class="icon-key"></i></span>
<input class="span2" type="password" placeholder="Password" name="password" /><br /><br />
</div>
<button type="submit" class="btn btn-primary">
<i class="icon-signin icon-small"></i> Log In
</button>
</form>
</div>
{/if}
</li>
</ul>
<form class="input-prepend navbar-search pull-right navbar-search" action="">
<span class="add-on"><i class="icon-search"></i></span>
<input type="text" class="span2 inputIcon" placeholder="Search">
</form>
</div>{* /.nav-collapse *}
</div>{* /.container *}
</div>{* /.navbar-inner *}
</div>{* /.navbar *}
{block body}{/block}
<!-- JS Placed at the end of the document so the pages load faster -->
{* JS Placed at the end of the document so the pages load faster *}
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/xo.js"></script>

View File

@@ -0,0 +1,44 @@
{**
* This file is a part of Xen Orchestra Web.
*
* Xen Orchestra Web is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Xen Orchestra Web is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xen Orchestra Web. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Olivier Lambert <olivier.lambert@vates.fr>
* @license http://www.gnu.org/licenses/agpl-3.0-standalone.html GNU AGPLv3
*
* @package Xen Orchestra Web
*}
{extends "/_base.html"}
{block title}Xen Orchestra - Home{/block}
{block body}
<div class="row-fluid">
<div class="span10 offset1 text-error">
<h2>{if $error}{$error}{else}Unknown error{/if}</h2>
<p>
{if $message}
{$message}
{else}
We are sorry but an unknown error just occured.
{/if}
</p>
<p>
You may {if $referer}go back to the <a href="{$referer}">previous page</a>{else}return to the <a href="./">homepage</a>{/if} or <a href="https://vates.fr/en/contacts.php">contact us</a> for more information.
</p>
</div>
</div>
{/block}

View File

@@ -143,7 +143,7 @@
</tbody>
</table>
</div>
<!-- One server details. TODO: dynamic in PHP -->
{* One server details. TODO: dynamic in PHP *}
<div class="offset3 span8 well">
<h3 class="center">Cluster 1</h3>
<ul class="nav nav-tabs">
@@ -163,7 +163,7 @@
<div class="bar" style="width: 15%;">VM3<br/>(1024M)</div>
</div>
</div>
<!-- One server details. TODO: dynamic in PHP -->
{* One server details. TODO: dynamic in PHP *}
<div class="offset3 span8 well">
<h3 class="center">Cluster 2</h3>
<ul class="nav nav-tabs">

View File

@@ -21,19 +21,23 @@
* @package Xen Orchestra Web
*/
$(function (){
$('a:first-child').tooltip({placement:'bottom'});
$('a').tooltip();
});
!function ()
{
$('a:first-child').tooltip({placement:'bottom'});
$('a').tooltip();
/** Blink Bell
* TODO: blink only when notifications
*/
function blink(selector){
$(selector).fadeOut('slow', function(){
$(this).fadeIn('slow', function(){
blink(this);
});
});
}
blink('#msg');
/**
* Blink Bell
*
* TODO: blink only when notifications.
*/
function blink(selector)
{
$(selector).fadeOut('slow', function () {
$(this).fadeIn('slow', function () {
blink(this);
});
});
}
//blink('#msg');
}();

49
src/www/session.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
/**
* This file is a part of Xen Orchestra Web.
*
* Xen Orchestra Web is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Xen Orchestra Web is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xen Orchestra Web. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Olivier Lambert <olivier.lambert@vates.fr>
* @license http://www.gnu.org/licenses/agpl-3.0-standalone.html GNU AGPLv3
*
* @package Xen Orchestra Web
*/
$application = require(__DIR__.'/../bootstrap.php');
if (!isset($_SERVER['HTTP_REFERER']))
{
$application->getTemplate('/_generic/error.html')->render();
return;
}
if (isset($_POST['name'], $_POST['password']))
{
if (!$application->logIn($_POST['name'], $_POST['password']))
{
$application->getTemplate('/_generic/error.html')->render(array(
'error' => 'Log in failed',
// @todo 'message' => '',
'referer' => $_SERVER['HTTP_REFERER'],
));
return;
}
}
else
{
$application->logOut();
}
$application->redirect($_SERVER['HTTP_REFERER']);