saimod css&js support, 2 menus in sai(project&sys), fixed login

This commit is contained in:
Ulf Gebhardt 2013-05-23 22:08:03 +02:00
parent e68c4fed17
commit 02010010c9
17 changed files with 256 additions and 56 deletions

View File

@ -1,8 +1,8 @@
<?php
\SYSTEM\SAI\sai::getInstance()->register('\SYSTEM\SAI\saimod_sys_sai');
\SYSTEM\SAI\sai::getInstance()->register('\SYSTEM\SAI\saimod_sys_login');
\SYSTEM\SAI\sai::getInstance()->register('\SYSTEM\SAI\saimod_sys_error');
\SYSTEM\SAI\sai::getInstance()->register_sys('\SYSTEM\SAI\saimod_sys_sai');
\SYSTEM\SAI\sai::getInstance()->register_sys('\SYSTEM\SAI\saimod_sys_login');
\SYSTEM\SAI\sai::getInstance()->register_sys('\SYSTEM\SAI\saimod_sys_error');
//\SYSTEM\SAI\sai::getInstance()->register('\SYSTEM\SAI\saimod_sys_sys');
//\SYSTEM\SAI\sai::getInstance()->register('\SYSTEM\SAI\saimod_sys_api');
//\SYSTEM\SAI\sai::getInstance()->register('\SYSTEM\SAI\saimod_sys_page');

View File

@ -10,7 +10,7 @@ class saimod_sys_error extends \SYSTEM\SAI\SaiModule {
$now = microtime(true);
$result = '<table class="table table-hover table-condensed" style="position:absolute; left:0;overflow: auto;">'.
$result = '<table class="table table-hover table-condensed" style="overflow: auto;">'.
'<tr>'.'<th>'.'time ago in sec'.'</th>'.'<th>'.'time'.'</th>'.'<th>'.'class'.'</th>'.'<th>'.'message'.'</th>'.'<th>'.'code'.'</th>'.'<th>'.'file'.'</th>'.'<th>'.'line'.'</th>'.'<th>'.'ip'.'</th>'.'<th>'.'querytime'.'</tr>';
while($r = $res->next()){
$result .= '<tr class="'.self::tablerow_class($r['class']).'">'.'<td>'.(int)($now - strtotime($r['time'])).'</td>'.'<td>'.$r['time'].'</td>'.'<td>'.$r['class'].'</td>'.'<td>'.$r['message'].'</td>'.'<td>'.$r['code'].'</td>'.'<td>'.$r['file'].'</td>'.'<td>'.$r['line'].'</td>'.'<td>'.$r['ip'].'</td>'.'<td>'.$r['querytime'].'</tr>';
@ -38,4 +38,7 @@ class saimod_sys_error extends \SYSTEM\SAI\SaiModule {
public static function html_li_menu(){return '<li><a href="#" id=".SYSTEM.SAI.saimod_sys_error">SYS Error</a></li>';}
public static function right_public(){return false;}
public static function right_right(){return \SYSTEM\SECURITY\Security::check(\SYSTEM\system::getSystemDBInfo(), \SYSTEM\SECURITY\RIGHTS::SYS_SAI);}
public static function src_css(){}
public static function src_js(){}
}

View File

@ -0,0 +1,21 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/* jQuery on document ready */
$(document).ready(function() {
$("#submitButton").click(function(){
$.get('./api.php?call=account&action=login&username='+$('#username').val()+'&password_sha='+$.sha1($('#password').val())+'&password_md5='+hex_md5($('#password').val()), function (data) {
if(data === 1){
$("#loginStatusMsg").html('Login successful!!');
} else {
$("#loginStatusMsg").html('Wrong username or password!');
}
});
});
});

View File

@ -1,18 +1,32 @@
Please login for developer access.
</br>
<font color="red">${message}</font>
<form id='login' action='?action=developer&sai_mod=.SYSTEM.SAI.saimod_sys_login' method='post' accept-charset='UTF-8'>
<fieldset>
<legend>Login</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >UserName:</label>
<input type='text' name='username' id='username' maxlength="50" />
<label for='password' >Password:</label>
<input type='password' name='password' id='password' maxlength="50" />
<input type='submit' name='Submit' value='Submit' />
</fieldset>
<form class="textbox" style="padding:10px" id="login_form">
<div class="control-group">
<div class="controls">
<input type="text"
size="30"
style="margin-bottom: 15px;"
id="bt_login_user"
placeholder="${loginUsername}"
minlength="3" data-validation-minlength-message="${login_username_too_short}"
maxlength="16" data-validation-maxlength-message="${login_username_too_long}"
required data-validation-required-message="${login_username_required}"/>
</div>
<div class="controls">
<input type="password"
size="30"
style="margin-bottom: 15px;"
id="bt_login_password"
placeholder="${loginPassword}"
minlength="5" data-validation-minlength-message="${login_password_too_short}"
maxlength="16" data-validation-maxlength-message="${login_password_too_short}"
required data-validation-required-message="${login_password_required}"/>
</div>
<div class="help-block"></div>
<input type="hidden" />
<button class="btn btn-primary" style="clear: left; height: 32px; font-size: 13px;"
type="submit"
id="login_submit">${login}</button>
</div>
</form>

View File

@ -0,0 +1,32 @@
Please login for developer access.
</br>
<form class="textbox" style="padding:10px" id="login_form">
<div class="control-group">
<div class="controls">
<input type="text"
size="30"
style="margin-bottom: 15px;"
id="bt_login_user"
placeholder="${loginUsername}"
minlength="3" data-validation-minlength-message="${login_username_too_short}"
maxlength="16" data-validation-maxlength-message="${login_username_too_long}"
required data-validation-required-message="${login_username_required}"/>
</div>
<div class="controls">
<input type="password"
size="30"
style="margin-bottom: 15px;"
id="bt_login_password"
placeholder="${loginPassword}"
minlength="5" data-validation-minlength-message="${login_password_too_short}"
maxlength="16" data-validation-maxlength-message="${login_password_too_short}"
required data-validation-required-message="${login_password_required}"/>
</div>
<div class="help-block"></div>
<input type="hidden" />
<button class="btn btn-primary" style="clear: left; height: 32px; font-size: 13px;"
type="submit"
id="login_submit">${login}</button>
</div>
</form>

View File

@ -1 +0,0 @@
Login successful.

View File

@ -0,0 +1,12 @@
You are logged in
</br>
<form class="textbox" style="padding:10px" id="logout_form">
<div class="control-group">
<div class="help-block"></div>
<input type="hidden" />
<button class="btn btn-primary" style="clear: left; height: 32px; font-size: 13px;"
type="submit"
id="logout_submit">${logout}</button>
</div>
</form>

View File

@ -0,0 +1,34 @@
$(document).ready(function() {
//jqBootstrapValidation
$("#login_form input").not("[type=submit]").jqBootstrapValidation({
preventSubmit: true,
submitError: function($form, event, errors) {},
submitSuccess: function($form, event){
$.get('./api.php?call=account&action=login&username='+$('#bt_login_user').val()+'&password_sha='+$.sha1($('#bt_login_password').val())+'&password_md5='+hex_md5($('#bt_login_password').val()), function (data) {
if(data == 1){
$('.help-block').html("Login successfull.</br>");
location.reload(true);
} else {
$('.help-block').html("Login not successfull.</br> User & Password combination wrong.")
}
});
event.preventDefault();
}
});
$("#logout_form input").not("[type=submit]").jqBootstrapValidation({
preventSubmit: true,
submitError: function($form, event, errors) {},
submitSuccess: function($form, event){
$.get('./api.php?call=account&action=logout', function (data) {
if(data == 1){
$('.help-block').html("Logout successfull.</br>");
location.reload(true);
} else {
$('.help-block').html("Logout not successfull.</br>")
}
});
event.preventDefault();
}
});
});

View File

@ -8,12 +8,29 @@ class saimod_sys_login extends \SYSTEM\SAI\SaiModule {
if( isset($_POST['username']) && isset($_POST['password']) &&
\SYSTEM\SECURITY\Security::login(\SYSTEM\system::getSystemDBInfo(), $_POST['username'], sha1($_POST['password']), md5($_POST['password']))){
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_login/login_success.tpl'), array());}
$vars = array();
$vars['message'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? 'You are already logged in! Maybe you dont have the required rights ;-).' : 'Not logged in!';
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_login/login.tpl'), $vars);
$vars['login'] = 'Login';
$vars['logout'] = 'Logout';
$vars['loginUsername'] = 'Username';
$vars['loginPassword'] = 'Password';
$vars['login_username_too_short'] = 'Username to short.';
$vars['login_password_too_short'] = 'Password to short.';
if(\SYSTEM\SECURITY\Security::isLoggedIn()){
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_login/logout.tpl'), $vars);
} else {
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_login/login.tpl'), $vars);}
}
public static function html_li_menu(){return '<li><a href="#" id=".SYSTEM.SAI.saimod_sys_login">SYS Login</a></li>';}
public static function right_public(){return true;}
public static function right_right(){}
public static function src_css(){}
public static function src_js(){return \SYSTEM\LOG\JsonResult::toString(
array( \SYSTEM\WEBPATH(new \PPAGE(),'default_page/js/jqBootstrapValidation.js'),
\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_login/sai_sys_login_submit.js'),
\SYSTEM\WEBPATH(new \PPAGE(),'default_page/js/crypto/md5.js'),
\SYSTEM\WEBPATH(new \PPAGE(),'default_page/js/crypto/jquery.sha1.js')
));}
}

View File

@ -7,4 +7,7 @@ class saimod_sys_sai extends \SYSTEM\SAI\SaiModule {
public static function html_li_menu(){return '<li class="active"><a href="#" id=".SYSTEM.SAI.saimod_sys_sai">SYS SAI</a></li>';}
public static function right_public(){return true;}
public static function right_right(){}
public static function src_css(){}
public static function src_js(){}
}

View File

@ -6,18 +6,27 @@ class default_module extends \SYSTEM\PAGE\Page {
private $module = null;
private $post_get = null;
private $css = null;
private $js = null;
public function __construct($module,$post_get){
$this->module = $module;
$this->post_get = $post_get;}
$this->post_get = $post_get;
$this->css = isset($post_get['css']) ? $post_get['css'] : null;
$this->js = isset($post_get['js']) ? $post_get['js'] : null;
}
public function html(){
if($this->module != null){
$mods = \SYSTEM\SAI\sai::getInstance()->getModules();
$mods = \SYSTEM\SAI\sai::getInstance()->getAllModules();
if( $this->module &&
\array_search($this->module, $mods) !== false &&
( \call_user_func(array($this->module, 'right_public')) ||
\call_user_func(array($this->module, 'right_right')))){
if($this->css != null){
return \call_user_func(array($this->module, 'src_css'));}
if($this->js != null){
return \call_user_func(array($this->module, 'src_js'));}
return \call_user_func(array($this->module, 'html_content'),array($this->post_get));}
}

View File

@ -4,7 +4,19 @@ namespace SYSTEM\SAI;
class default_page extends \SYSTEM\PAGE\Page {
private function menu(){
private function menu_sys(){
$result = '';
$mods = \SYSTEM\SAI\sai::getInstance()->getSysModules();
foreach($mods as $mod){
if(\call_user_func(array($mod, 'right_public')) ||
\call_user_func(array($mod, 'right_right'))){
$result .= \call_user_func(array($mod, 'html_li_menu'));}
}
return $result;
}
private function menu_proj(){
$result = '';
$mods = \SYSTEM\SAI\sai::getInstance()->getModules();
@ -13,7 +25,7 @@ class default_page extends \SYSTEM\PAGE\Page {
\call_user_func(array($mod, 'right_right'))){
$result .= \call_user_func(array($mod, 'html_li_menu'));}
}
return $result.'</ul>';
return $result;
}
private function css(){
@ -23,11 +35,9 @@ class default_page extends \SYSTEM\PAGE\Page {
}
private function js(){
//if(!\SYSTEM\SECURITY\Security::check(\SYSTEM\system::getSystemDBInfo() , \SYSTEM\SECURITY\RIGHTS::SYS_SAI)){
// $login = new \SYSTEM\SAI\login_page();
// return $login->html();}
$result = '<script src="'.\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'page/default_page/js/libs/jquery.min.js').'" type="text/javascript"></script>'.
'<script src="'.\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'page/default_page/js/libs/bootstrap.min.js').'" type="text/javascript"></script>'.
'<script src="'.\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'page/default_page/js/loadcssjs.js').'" type="text/javascript"></script>'.
'<script src="'.\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'page/default_page/js/index.js').'" type="text/javascript"></script>';
return $result;
}
@ -38,14 +48,10 @@ class default_page extends \SYSTEM\PAGE\Page {
$vars['css'] = $this->css();
$vars['js'] = $this->js();
$vars['menu'] = $this->menu();
$vars['menu_sys'] = $this->menu_sys();
$vars['menu_proj'] = $this->menu_proj();
$vars['navimg'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_SAI_CONFIG_NAVIMG);
//$vars['PATH_IMG'] = SYSTEM\WEBPATH(new PPAGE(),'default_developer/img/');
//$vars['PATH_LIB'] = SYSTEM\WEBPATH(new PLIB());
//$vars['PATH_JS'] = SYSTEM\WEBPATH(new PJS());
//$vars = array_merge($vars, SYSTEM\locale::getStrings(\SYSTEM\DBD\locale_string::VALUE_CATEGORY_DASENSE));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'page/default_page/sai.tpl'), $vars);
}
}

View File

@ -3,34 +3,41 @@
$(document).ready(function() {
// initialize content
$('div#content-wrapper').load('./?action=developer&sai_mod=.SYSTEM.SAI.saimod_sys_sai', function() {
$('.carousel').carousel();
});
loadModuleContent('.SYSTEM.SAI.saimod_sys_sai');
/**
* generic navigation control
*/
$('div#developer-navbar ul#developer-nav li a').click(function () {
var id = $(this).attr("id");
//load content -> menu
$('#sai_navbar ul li a, #project_navbar ul li a').click(function () {
var id = $(this).attr("id");
if(id !== undefined){
console.log("Module: "+id);
console.log("Module: "+id);
$('div#developer-navbar ul#developer-nav li').each(function(){
$(this).removeClass('active');
});
$('#sai_navbar li, #project_navbar li').each(function(){
$(this).removeClass('active');});
$(this).parent().addClass('active');
loadModuleContent(id);
}
});
$('.brand').click(function(){
location.reload();
});
});
});
function loadModuleContent(id){
$('div#content-wrapper').load('./?action=developer&sai_mod='+id, function(){
init();
$('div#content-wrapper').load('./?action=developer&sai_mod='+id, function(){});
$.getJSON('./?action=developer&sai_mod='+id+'&css=1', function (data) {
if(data){
for(var i=0; i < data['result'].length; i++){
loadCSS(data['result'][i]);}
}
});
$.getJSON('./?action=developer&sai_mod='+id+'&js=1', function (data) {
if(data){
for(var i=0; i < data['result'].length; i++){
loadJS(unescape(data['result'][i]));}
}
});
}

View File

@ -0,0 +1,18 @@
function loadJS(jssrc) {
if(jssrc){
var snode = document.createElement('script');
snode.setAttribute('type','text/javascript');
snode.setAttribute('src',jssrc);
document.getElementsByTagName('head')[0].appendChild(snode);
}
}
function loadCSS(csssrc) {
if(csssrc){
var snode = document.createElement('link');
snode.setAttribute('type','text/css');
snode.setAttribute('rel', 'stylesheet');
snode.setAttribute('href',csssrc);
document.getElementsByTagName('head')[0].appendChild(snode);
}
}

View File

@ -10,18 +10,26 @@
</head>
<body>
<div id="developer-navbar" class="navbar">
<div id="sai_navbar" class="navbar">
<div class="navbar-inner">
<div class="brand-logo">
<img src="${navimg}" height="24" width="24">
</div>
<a class="brand" href="#">developer</a>
<ul id="developer-nav" class="nav">
${menu}
<ul class="nav">
${menu_sys}
</ul>
</div>
</div>
<div id="project_navbar" style="width:150px;float:left;">
<div class="navbar-inner">
<ul class="nav nav-list">
${menu_proj}
</ul>
</div>
</div>
<div id="content">
<div id="content-wrapper"></div>
<hr>

View File

@ -13,5 +13,11 @@ abstract class SaiModule {
//check your rights here -> returns true or false
public static function right_right(){
throw new RuntimeException("Unimplemented!");}
//array with paths as json
public static function src_js(){
throw new RuntimeException("Unimplemented!");}
//array with paths as json
public static function src_css(){
throw new RuntimeException("Unimplemented!");}
}

View File

@ -5,6 +5,7 @@ namespace SYSTEM\SAI;
class sai {
private $modules = array(); //only strings!
private $modules_sys = array(); //only strings!
//SINGLETON!
static private $instance = null;
@ -16,13 +17,23 @@ class sai {
private function __construct(){}
private function __clone(){}
public function register($module){
public function register($module){
if( !\class_exists($module) ||
!\is_array($parents = \class_parents($module)) ||
!\array_search('SYSTEM\SAI\SaiModule', $parents)){
throw new \Exception('Problem with your Sysmodule class: '.$module);}
$this->modules[] = $module;}
public function register_sys($module){
if( !\class_exists($module) ||
!\is_array($parents = \class_parents($module)) ||
!\array_search('SYSTEM\SAI\SaiModule', $parents)){
throw new \Exception('Problem with your Sysmodule class: '.$module);}
$this->modules_sys[] = $module;}
public function getModules(){
return $this->modules;}
public function getSysModules(){
return $this->modules_sys;}
public function getAllModules(){
return array_merge($this->modules_sys,$this->modules);}
}