Added Cookie login. Seems to work OK

This commit is contained in:
Karl Cordes 2010-01-10 16:34:31 -07:00
parent d7a76d9c53
commit 1d6aba8d90
5 changed files with 182 additions and 134 deletions

View file

@ -4,12 +4,19 @@
class AppController extends Controller { class AppController extends Controller {
var $components = array('Auth', 'RequestHandler'); var $components = array('Auth', 'RequestHandler');
var $helpers = array('Javascript', 'Time', 'Html', 'Form', 'Ajax'); var $helpers = array('Javascript', 'Time', 'Html', 'Form', 'Ajax');
function beforeFilter() { function beforeFilter() {
$this->set('currentuser', $this->Auth->user()); $this->set('currentuser', $this->Auth->user());
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'enquiries', 'action' => 'index');
$this->Auth->allow('display');
$this->Auth->authorize = 'controller';
/** /**
* Define the scheme for issue Types. * Define the scheme for issue Types.
*/ */
@ -27,5 +34,10 @@ var $components = array('Auth', 'RequestHandler');
} }
function isAuthorized() {
return true;
}
} }
?> ?>

View file

@ -3,7 +3,7 @@ class UsersController extends AppController {
var $name = 'Users'; var $name = 'Users';
var $helpers = array('Html', 'Form'); var $helpers = array('Html', 'Form');
var $components = array('Acl','Auth'); var $components = array('Acl','Auth', 'Cookie');
var $paginate = array( var $paginate = array(
'Users' => array('order' => array('User.name' => 'asc'), 'Users' => array('order' => array('User.name' => 'asc'),
'limit' => 20 'limit' => 20
@ -19,6 +19,38 @@ class UsersController extends AppController {
function login() { //Provided by the authComponent function login() { //Provided by the authComponent
$this->pageTitle = ': Login'; $this->pageTitle = ': Login';
$this->Session->setFlash(__('Please enter your Username and Password to continue', true)); $this->Session->setFlash(__('Please enter your Username and Password to continue', true));
/* Auth Cookie code from http://www.webdevelopment2.com/cakephp-auth-component-tutorial-3/ */
// code inside this function will execute only when autoRedirect was set to false (i.e. in a beforeFilter).
if ($this->Auth->user()) {
if (!empty($this->data) && $this->data['User']['remember_me']) {
$cookie = array();
$cookie['username'] = $this->data['User']['username'];
$cookie['password'] = $this->data['User']['password'];
$this->Cookie->write('Auth.User', $cookie, true, '+2 weeks');
unset($this->data['User']['remember_me']);
}
$this->redirect($this->Auth->redirect());
}
if (empty($this->data)) {
$cookie = $this->Cookie->read('Auth.User');
if (!is_null($cookie)) {
if ($this->Auth->login($cookie)) {
// Clear auth message, just in case we use it.
$this->Session->setFlash(__('Welcome back '.$cookie['username']), true);
$this->Session->del('Message.auth');
$this->redirect($this->Auth->redirect());
} else { // Delete invalid Cookie
$this->Cookie->del('Auth.User');
}
}
}
} }
@ -94,30 +126,30 @@ class UsersController extends AppController {
function initpermissions() { function initpermissions() {
$group = $this->User->Group; $group = $this->User->Group;
//Allow admins to everything //Allow admins to everything
$group->id = 6; $group->id = 6;
$this->Acl->allow($group, 'controllers'); $this->Acl->allow($group, 'controllers');
//Manager Permission //Manager Permission
$group->id = 5; $group->id = 5;
$this->Acl->allow($group, 'controllers'); $this->Acl->allow($group, 'controllers');
//User Permission //User Permission
$group->id = 4; $group->id = 4;
$this->Acl->deny($group, 'controllers'); $this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Enquires/add'); $this->Acl->allow($group, 'controllers/Enquires/add');
$this->Acl->allow($group, 'controllers/Enquires/edit'); $this->Acl->allow($group, 'controllers/Enquires/edit');
$this->Acl->allow($group, 'controllers/Enquires/view'); $this->Acl->allow($group, 'controllers/Enquires/view');
$this->Acl->allow($group, 'controllers/Quotes/add'); $this->Acl->allow($group, 'controllers/Quotes/add');
$this->Acl->allow($group, 'controllers/Quotes/edit'); $this->Acl->allow($group, 'controllers/Quotes/edit');
$this->Acl->allow($group, 'controllers/Quotes/view'); $this->Acl->allow($group, 'controllers/Quotes/view');
$this->Acl->allow($group, 'controllers/QuoteProducts/add'); $this->Acl->allow($group, 'controllers/QuoteProducts/add');
$this->Acl->allow($group, 'controllers/QuoteProducts/edit'); $this->Acl->allow($group, 'controllers/QuoteProducts/edit');
$this->Acl->allow($group, 'controllers/QuoteProducts/view'); $this->Acl->allow($group, 'controllers/QuoteProducts/view');
} }

9
vendors/xtcpdf.php vendored
View file

@ -90,7 +90,7 @@ class XTCPDF extends TCPDF {
$fourthColWidth = -10; $fourthColWidth = -10;
$pageNo = $this->PageNoFormatted(); $pageNo = $this->PageNoFormatted();
//$pageOf = $this->getAliasNbPages();
@ -98,13 +98,11 @@ class XTCPDF extends TCPDF {
$this->SetXY($boxXstart, 55); $this->SetXY($boxXstart, 55);
$heightNeeded = $this->getNumLines($companyName, $secondColWidth); $heightNeeded = $this->getNumLines($companyName, $secondColWidth);
//echo "Height needed: $heightNeeded";
$lineHeight = 6.40997; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs. $lineHeight = 6.40997; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs.
// $lineHeight = 0;
// $this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml);
$this->MultiCell($firstColWidth, $lineHeight*$heightNeeded, "QUOTATION TO:", 'LTR', 'L', 0, 0); $this->MultiCell($firstColWidth, $lineHeight*$heightNeeded, "QUOTATION TO:", 'LTR', 'L', 0, 0);
@ -112,7 +110,7 @@ class XTCPDF extends TCPDF {
$this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0); $this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0);
$this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "<a href=\"mailto:$fromEmail\">$fromName</a>", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this. $this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "<a href=\"mailto:$fromEmail\">$fromName</a>", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this.
// echo "Last height: ".$this->getLastH();
$this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0); $this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0);
$this->MultiCell($secondColWidth, 0, "<a href=\"mailto:$emailTo\">$emailTo</a>", 'LR','L', 0, 0, null, null, true, 0, true); $this->MultiCell($secondColWidth, 0, "<a href=\"mailto:$emailTo\">$emailTo</a>", 'LR','L', 0, 0, null, null, true, 0, true);
@ -249,7 +247,6 @@ class XTCPDF extends TCPDF {
$pageNo = $this->PageNoFormatted(); $pageNo = $this->PageNoFormatted();
$this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1); $this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1);
$this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1); $this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1);
$this->Ln();
$this->MultiCell($itemColwidth, 0, "ITEM\nNO.", 1, "C", 1, 0); $this->MultiCell($itemColwidth, 0, "ITEM\nNO.", 1, "C", 1, 0);

View file

@ -56,7 +56,7 @@ foreach ($quote['QuotePage'] as $quotePage):
<div class="related"> <div class="quoteproducts">
<h3><?php __('Products in this Quote');?></h3> <h3><?php __('Products in this Quote');?></h3>
<?php if (!empty($quoteProducts)):?> <?php if (!empty($quoteProducts)):?>
<table cellpadding = "0" cellspacing = "0" class="quoteproducts"> <table cellpadding = "0" cellspacing = "0" class="quoteproducts">

View file

@ -4,7 +4,7 @@
* *
* *
* Quotenik - Working CSS file based on the CakePHP default CSS. * Quotenik - Working CSS file based on the CakePHP default CSS.
* Modified by Karl Cordes 2008/2009 * Modified by Karl Cordes 2008/2009/2010
* *
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
@ -340,6 +340,13 @@ div.enquiriesindex {
} }
div.quoteproducts {
clear: both;
display: block;
padding-top: 3%;
}
/* Tables */ /* Tables */
table { table {
background: #fff; background: #fff;
@ -555,7 +562,7 @@ table.productoptions tr.defaultoption {
} }
table.quoteproducts { table.quoteproducts {
width: 70%; width: 60%;
text-align: left; text-align: left;
} }