issue #0001591 : Big change in the operation

This commit is contained in:
Michael RICOIS 2013-04-18 14:47:00 +00:00
parent 71ecb298b9
commit 0d2ad7af8b
7 changed files with 148 additions and 121 deletions

View File

@ -36,61 +36,6 @@ class UserController extends Zend_Controller_Action
$identity->acceptationCGU = $InfosLogin->result->acceptationCGU;; $identity->acceptationCGU = $InfosLogin->result->acceptationCGU;;
return $identity; return $identity;
} }
/**
* Recueillir l'information des clients
* @return array
*/
protected function getClientStat()
{
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$userAgent = $bootstrap->getResource('useragent');
$device_all = $userAgent->getDevice();
$browser_name = $device_all->getFeature('browser_name');
$browser_version = $device_all->getFeature('browser_version');
$device_type=($device_all->getFeature('is_mobile')==1)?'1':'0';
$stat_data = array(
'browserName' => $browser_name,
'browserVersion' => $browser_version,
'isMobile' => $device_type
);
return $stat_data;
}
/**
* Remplir l'information des clients dans la bdd
* @param Identifiant de l'utilisateur
* @param ID de l'utilisateur
* @param Résolution d'écran de l'utilisateur
*/
protected function insertClientStat($login, $idClient, $screenSize)
{
$stat_data = array(
'idClient' => $idClient,
'login' => $login,
'dateInsert' => date('Y-m-d'),
'screenSize' => $screenSize
);
$stat_data = array_merge($stat_data, $this->getClientStat());
$client_stat = new Application_Model_ClientStat();
$client_stat->insert($stat_data);
}
/**
* Affiche la statistique des clients
*/
protected function showClientStat()
{
$stat_data = $this->getClientStat();
$this->view->assign('device_type', $stat_data['isMobile']);
$this->view->assign('browser_info', $stat_data['browserName'].' '.$stat_data['browserVersion']);
}
public function init() public function init()
{ {
@ -104,13 +49,14 @@ class UserController extends Zend_Controller_Action
*/ */
public function indexAction() public function indexAction()
{ {
$this->showClientStat();
$user = new Scores_Utilisateur(); $user = new Scores_Utilisateur();
if (!$user->checkPerm('MONPROFIL')){ if (!$user->checkPerm('MONPROFIL')){
$this->_forward('perms', 'error'); $this->_forward('perms', 'error');
} }
$this->view->assign('device_type', $user->getBrowserInfo()->mobile);
$this->view->assign('browser_info', $user->getBrowserInfo()->name.' '.$user->getBrowserInfo()->version);
$this->view->headLink()->appendStylesheet('/themes/default/styles/form.css', 'all'); $this->view->headLink()->appendStylesheet('/themes/default/styles/form.css', 'all');
$this->view->headScript()->appendFile('/themes/default/scripts/user.js', 'text/javascript'); $this->view->headScript()->appendFile('/themes/default/scripts/user.js', 'text/javascript');
@ -126,7 +72,8 @@ class UserController extends Zend_Controller_Action
$login = $request->getParam('login', ''); $login = $request->getParam('login', '');
$op = $request->getParam('op'); $op = $request->getParam('op');
if ($request->isPost()) { //Save data
if ( $request->isPost() ) {
$options = $request->getParam('frmOptions', ''); $options = $request->getParam('frmOptions', '');
$action = $options['action']; $action = $options['action'];
@ -382,42 +329,47 @@ class UserController extends Zend_Controller_Action
$form = new Form_Login(); $form = new Form_Login();
$this->view->form = $form; $this->view->form = $form;
$request = $this->getRequest(); $request = $this->getRequest();
if ($request->isPost()) { if ( $request->isPost() ) {
$formData = $request->getPost (); $formData = $request->getPost ();
if ($form->isValid($formData)) { if ($form->isValid($formData)) {
$login = $form->getValue('login'); $login = $form->getValue('login');
$pass = $form->getValue('pass'); $pass = $form->getValue('pass');
$screenSize = 'unknown';
if($form->getValue('screenSize'))
$screenSize = $form->getValue('screenSize');
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
$authAdapter = new Scores_AuthAdapter($login, md5($login.'|'.$pass)); $authAdapter = new Scores_AuthAdapter($login, md5($login.'|'.$pass));
$result = $auth->authenticate($authAdapter); $result = $auth->authenticate($authAdapter);
if (!$result->isValid()){
$this->view->message = ''; //Auth is valid
Zend_Registry::get('firebug')->info($result); if ( $result->isValid() ) {
foreach ($result->getMessages() as $message) {
$this->view->message.= $message."<br/>"; //Save browser information
} $screenSize = $request->getParam('screenSize', 'unknow');
} else { $user = new Scores_Utilisateur();
$user = new Scores_Utilisateur(); $info = get_browser();
$user_request = $this->getRequest(); $isMobile = ($info->ismobiledevice==1) ? 1 : 0;
$this->insertClientStat($user_request->getParam('login', $user->getLogin()), $user->setBrowserInfo($info->platform, $info->browser, $info->version, $isMobile, $screenSize);
$user_request->getParam('idclient', $user->getId()),
$screenSize); //Get previous url if user has been disconnected
$url = ''; $url = '';
if (Zend_Session::namespaceIsset('login')){ if (Zend_Session::namespaceIsset('login')){
$session = new Zend_Session_Namespace('login'); $session = new Zend_Session_Namespace('login');
if (isset($session->url)) { if (isset($session->url)) {
$url = $session->url; $url = $session->url;
} }
} }
if (!empty($url) && $url!='/user/login' && $url!='/user/logout' && $url!='/localauth'){ if (!empty($url) && $url!='/user/login' && $url!='/user/logout' && $url!='/localauth'){
$this->_redirect($url); $this->_redirect($url);
} }
$this->_redirect('/'); $this->_redirect('/');
}
//Auth error
else {
$this->view->message = '';
Zend_Registry::get('firebug')->info($result);
foreach ($result->getMessages() as $message) {
$this->view->message.= $message."<br/>";
}
} }
} }
} }
@ -501,4 +453,23 @@ class UserController extends Zend_Controller_Action
$this->_redirect('/'); $this->_redirect('/');
} }
public function browserAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
//Load bootstrap
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
//Get useragent and device informations
$userAgent = $bootstrap->getResource('useragent');
$device = $userAgent->getDevice();
//Display
print_r(get_browser());
print_r($device->getAllFeatures());
}
} }

View File

@ -1,8 +1,8 @@
<?php <?php
class Application_Model_ClientStat extends Zend_Db_Table_Abstract class Application_Model_ClientStat extends Zend_Db_Table_Abstract
{ {
protected $_name = 'clientStat'; protected $_name = 'client_stat';
/** /**
* Retourne quantité des lignes de certain valeur * Retourne quantité des lignes de certain valeur
* @param string $col_name * @param string $col_name
@ -11,8 +11,7 @@ class Application_Model_ClientStat extends Zend_Db_Table_Abstract
*/ */
public function statCnt($col_name, $col_val) public function statCnt($col_name, $col_val)
{ {
$sql = $this->select() $sql = $this->select()->where("$col_name='$col_val'");
->where("$col_name='$col_val'");
$rows = $this->fetchAll($sql); $rows = $this->fetchAll($sql);
return count($rows); return count($rows);
} }

View File

@ -88,12 +88,12 @@ if ($this->isAdmin || $this->isSuperAdmin){
?> ?>
</div> </div>
<h2>Statistique</h2> <h2>Informations</h2>
<div class="paragraph"> <div class="paragraph">
<div class="infoTitle StyleInfoLib">Type d'appareil actuel</div> <div class="infoTitle StyleInfoLib">Type d'appareil actuel</div>
<div class="infoData"> <div class="infoData">
<?php echo (($this->device_type==0)?'Ordinateur':'Mobile'); ?> <?=($this->device_type==0) ? 'Poste de travail': 'Mobile'?>
</div> </div>
<div class="infoTitle StyleInfoLib">Résolution d'écran actuel</div> <div class="infoTitle StyleInfoLib">Résolution d'écran actuel</div>
@ -102,7 +102,7 @@ if ($this->isAdmin || $this->isSuperAdmin){
</div> </div>
<div class="infoTitle StyleInfoLib">Navigateur actuel</div> <div class="infoTitle StyleInfoLib">Navigateur actuel</div>
<div class="infoData"><?php echo ($this->browser_info); ?></div> <div class="infoData"><?=$this->browser_info?></div>
</div> </div>
<h2>Moteur de recherche</h2> <h2>Moteur de recherche</h2>

View File

@ -41,20 +41,27 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
$authAdapter = new Scores_AuthAdapter($login, $hach, $iponly); $authAdapter = new Scores_AuthAdapter($login, $hach, $iponly);
$result = $auth->authenticate($authAdapter); $result = $auth->authenticate($authAdapter);
if (!$result->isValid()) { if ( $result->isValid() ) {
$messageF = '';
foreach ($result->getMessages() as $message) { //Store identity in sesssion
$messageF.= $message."<br/>"; $storage = new Zend_Auth_Storage_Session();
} $session = new Zend_Session_Namespace($storage->getNamespace());
$request->setModuleName('default') $auth->setStorage($storage);
->setControllerName('user')
->setActionName('logout') $user = new Scores_Utilisateur();
->setParam('message', $messageF); $info = get_browser();
$isMobile = ($info->ismobiledevice==1) ? 1 : 0;
$user->setBrowserInfo($info->platform, $info->browser, $info->version, $isMobile);
} else { } else {
$storage = new Zend_Auth_Storage_Session(); $messageF = '';
$session = new Zend_Session_Namespace($storage->getNamespace()); foreach ($result->getMessages() as $message) {
//$session->setExpirationSeconds(86400); $messageF.= $message."<br/>";
$auth->setStorage($storage); }
$request->setModuleName('default')
->setControllerName('user')
->setActionName('logout')
->setParam('message', $messageF);
} }
//Sinon on reste sur le standard //Sinon on reste sur le standard
@ -72,12 +79,15 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
} }
//Check CGU //Check CGU
if ( $request->getControllerName()!='aide' && $request->getActionName()!='cgu' if ( $request->getControllerName()!='aide'
&& $request->getControllerName()!='user' && $request->getActionName()!='logout') { && $request->getActionName()!='cgu'
if ( empty($identity->acceptationCGU) || $identity->acceptationCGU=='0000-00-00 00:00:00' ) { && $request->getControllerName()!='user'
&& $request->getActionName()!='logout') {
if ( empty($identity->acceptationCGU)
|| $identity->acceptationCGU=='0000-00-00 00:00:00' ) {
$request->setModuleName('default') $request->setModuleName('default')
->setControllerName('aide') ->setControllerName('aide')
->setActionName('cgu'); ->setActionName('cgu');
} }
} }

View File

@ -6,8 +6,7 @@ class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstrac
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
$theme = 'default'; $theme = 'default';
if ( $auth->hasIdentity() ) { if ( $auth->hasIdentity() ) {
$theme = !empty($auth->getIdentity()->theme) ? $theme = !empty($auth->getIdentity()->theme) ? $auth->getIdentity()->theme : 'default';
$auth->getIdentity()->theme : 'default';
} }
//Sauvegarde des paramètres du themes pour gérer les scripts et styles à utiliser //Sauvegarde des paramètres du themes pour gérer les scripts et styles à utiliser
@ -22,11 +21,16 @@ class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstrac
$layoutPath = APPLICATION_PATH . '/views/' . $theme; $layoutPath = APPLICATION_PATH . '/views/' . $theme;
$viewPath = APPLICATION_PATH . '/views/' . $theme; $viewPath = APPLICATION_PATH . '/views/' . $theme;
//Surcharge des chemins de la vue et du layout //Load bootstrap
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
//Get useragent and device informations
$userAgent = $bootstrap->getResource('useragent');
$device = $userAgent->getDevice();
//Override path for view and layout
$view = $bootstrap->bootstrap('View')->getResource('View'); $view = $bootstrap->bootstrap('View')->getResource('View');
$view->setBasePath($viewPath); $view->setBasePath($viewPath);
$layout = $bootstrap->bootstrap('Layout')->getResource('Layout'); $layout = $bootstrap->bootstrap('Layout')->getResource('Layout');
$layout->setLayout('main'); $layout->setLayout('main');
$layout->setLayoutPath($layoutPath); $layout->setLayoutPath($layoutPath);
@ -49,8 +53,6 @@ class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstrac
->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => '/favicon.ico')); ->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => '/favicon.ico'));
$isIE6 = false; $isIE6 = false;
$userAgent = $bootstrap->getResource('useragent');
$device = $userAgent->getDevice();
if ( $device->getFeature('browser_name')=='Internet Explorer' if ( $device->getFeature('browser_name')=='Internet Explorer'
&& $device->getFeature('browser_version')=='6.0' ) { && $device->getFeature('browser_version')=='6.0' ) {
$isIE6 = true; $isIE6 = true;

View File

@ -196,4 +196,48 @@ class Scores_Utilisateur
return $hasPref; return $hasPref;
} }
/**
* Get browser information
*/
public function getBrowserInfo()
{
return $this->identity->browser;
}
/**
* Set browser information
* @param string $name
* @param string $version
* @param int $mobile
* @param string $screenSize
*/
public function setBrowserInfo($platform, $name, $version, $mobile, $screenSize = 'unknow')
{
//Save info to session
$browserInfo = new stdClass();
$browserInfo->platform = $platform;
$browserInfo->name = $name;
$browserInfo->version = $version;
$browserInfo->mobile = $mobile;
$browserInfo->screenSize = $screenSize;
$this->identity->browser = $browserInfo;
$auth = Zend_Auth::getInstance();
$auth->getStorage()->write($this->identity);
//Save info to database
$data = array(
'idClient' => $this->getIdClient(),
'login' => $this->getLogin(),
'dateInsert' => date('Y-m-d H:i:s'),
'platform' => $platform,
'browserName' => $name,
'browserVersion' => $version,
'isMobile' => $mobile,
'screenSize' => $screenSize
);
$clientstatM = new Application_Model_ClientStat();
$id = $clientstatM->insert($data);
Zend_Registry::get('firebug')->info('Insertion : '.$id);
}
} }

View File

@ -1,11 +1,12 @@
CREATE TABLE IF NOT EXISTS `clientStat` ( CREATE TABLE IF NOT EXISTS `client_stat` (
`idStat` int(11) NOT NULL AUTO_INCREMENT, `idStat` int(11) NOT NULL AUTO_INCREMENT,
`idClient` char(5) NOT NULL , `idClient` char(5) NOT NULL,
`login` varchar(20) NOT NULL, `login` varchar(20) NOT NULL,
`platform` varchar(20) NOT NULL,
`browserName` varchar(22) NOT NULL, `browserName` varchar(22) NOT NULL,
`browserVersion` varchar(15) NOT NULL, `browserVersion` varchar(15) NOT NULL,
`isMobile` varchar(1) NOT NULL, `isMobile` varchar(1) NOT NULL,
`screenSize` varchar(9) NOT NULL, `screenSize` varchar(9) NOT NULL,
`dateInsert` date NOT NULL, `dateInsert` datetime NOT NULL,
PRIMARY KEY (`idStat`) PRIMARY KEY (`idStat`)
) ENGINE=MyISAM COMMENT='statistique des navigateurs des clients'; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='statistique des navigateurs des clients' ;