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,27 +4,39 @@
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());
/**
* Define the scheme for issue Types. $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
*/ $this->Auth->loginRedirect = array('controller' => 'enquiries', 'action' => 'index');
$this->set('issueTypes', array(1=>"Bug Report", 2=>"Feature Request", 3=>"Other IT Help")); $this->Auth->allow('display');
$this->Auth->authorize = 'controller';
$priorities = array(1 => 'Low',2=>"Medium",3=>"High", 4=>"Critical");
$this->set('issuePriorities', $priorities);
/**
* Define the scheme for issue Types.
*/
$this->set('issueTypes', array(1=>"Bug Report", 2=>"Feature Request", 3=>"Other IT Help"));
$priorities = array(1 => 'Low',2=>"Medium",3=>"High", 4=>"Critical");
$this->set('issuePriorities', $priorities);
if($this->RequestHandler->isAjax()) { if($this->RequestHandler->isAjax()) {
Configure::write('debug', 0); Configure::write('debug', 0);
} }
} }
function isAuthorized() {
return true;
}
} }

View file

@ -1,129 +1,161 @@
<?php <?php
class UsersController extends AppController { 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
), ),
'Enquiry' => array('order' => array('Enquiry.id' => 'desc'), 'limit' => 250) 'Enquiry' => array('order' => array('Enquiry.id' => 'desc'), 'limit' => 250)
); );
function beforeFilter() { function beforeFilter() {
$this->Auth->allow('add'); $this->Auth->allow('add');
$this->set('currentuser', $this->Auth->user()); $this->set('currentuser', $this->Auth->user());
} }
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));
}
function logout() {
$this->redirect($this->Auth->logout());
}
function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
function view($id = null) { /* Auth Cookie code from http://www.webdevelopment2.com/cakephp-auth-component-tutorial-3/ */
if (!$id) { // code inside this function will execute only when autoRedirect was set to false (i.e. in a beforeFilter).
$this->Session->setFlash(__('Invalid User.', true)); if ($this->Auth->user()) {
$this->redirect(array('action'=>'index')); if (!empty($this->data) && $this->data['User']['remember_me']) {
} $cookie = array();
$this->set('user', $this->User->read(null, $id)); $cookie['username'] = $this->data['User']['username'];
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.user_id' => $id))); $cookie['password'] = $this->data['User']['password'];
$this->Cookie->write('Auth.User', $cookie, true, '+2 weeks');
$statuses = $this->User->Enquiry->Status->find('all'); unset($this->data['User']['remember_me']);
$status_list = array(); }
foreach ($statuses as $status) { $this->redirect($this->Auth->redirect());
$status_list[] = array($status['Status']['id'], $status['Status']['name']); }
} if (empty($this->data)) {
$this->set('status_list', $status_list); $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');
}
function add() {
$this->set('groups', $this->User->Group->find('list'));
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('The User has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid User', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('The User has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->User->read(null, $id);
$this->set('groups', $this->User->Group->find('list'));
}
}
function delete($id = null) { }
if (!$id) { }
$this->Session->setFlash(__('Invalid id for User', true)); }
$this->redirect(array('action'=>'index'));
}
if ($this->User->del($id)) {
$this->Session->setFlash(__('User deleted', true));
$this->redirect(array('action'=>'index'));
}
}
function initpermissions() {
$group = $this->User->Group;
//Allow admins to everything
$group->id = 6;
$this->Acl->allow($group, 'controllers');
//Manager Permission function logout() {
$group->id = 5; $this->redirect($this->Auth->logout());
$this->Acl->allow($group, 'controllers'); }
//User Permission function index() {
$group->id = 4; $this->User->recursive = 0;
$this->Acl->deny($group, 'controllers'); $this->set('users', $this->paginate());
$this->Acl->allow($group, 'controllers/Enquires/add'); }
$this->Acl->allow($group, 'controllers/Enquires/edit');
$this->Acl->allow($group, 'controllers/Enquires/view'); function view($id = null) {
$this->Acl->allow($group, 'controllers/Quotes/add'); if (!$id) {
$this->Acl->allow($group, 'controllers/Quotes/edit'); $this->Session->setFlash(__('Invalid User.', true));
$this->Acl->allow($group, 'controllers/Quotes/view'); $this->redirect(array('action'=>'index'));
$this->Acl->allow($group, 'controllers/QuoteProducts/add'); }
$this->set('user', $this->User->read(null, $id));
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.user_id' => $id)));
$statuses = $this->User->Enquiry->Status->find('all');
$status_list = array();
foreach ($statuses as $status) {
$status_list[] = array($status['Status']['id'], $status['Status']['name']);
}
$this->set('status_list', $status_list);
}
function add() {
$this->set('groups', $this->User->Group->find('list'));
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('The User has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid User', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('The User has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->User->read(null, $id);
$this->set('groups', $this->User->Group->find('list'));
}
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for User', true));
$this->redirect(array('action'=>'index'));
}
if ($this->User->del($id)) {
$this->Session->setFlash(__('User deleted', true));
$this->redirect(array('action'=>'index'));
}
}
function initpermissions() {
$group = $this->User->Group;
//Allow admins to everything
$group->id = 6;
$this->Acl->allow($group, 'controllers');
//Manager Permission
$group->id = 5;
$this->Acl->allow($group, 'controllers');
//User Permission
$group->id = 4;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Enquires/add');
$this->Acl->allow($group, 'controllers/Enquires/edit');
$this->Acl->allow($group, 'controllers/Enquires/view');
$this->Acl->allow($group, 'controllers/Quotes/add');
$this->Acl->allow($group, 'controllers/Quotes/edit');
$this->Acl->allow($group, 'controllers/Quotes/view');
$this->Acl->allow($group, 'controllers/QuoteProducts/add');
$this->Acl->allow($group, 'controllers/QuoteProducts/edit');
$this->Acl->allow($group, 'controllers/QuoteProducts/view');
}
$this->Acl->allow($group, 'controllers/QuoteProducts/edit');
$this->Acl->allow($group, 'controllers/QuoteProducts/view');
}
} }

13
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,8 +247,7 @@ 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);
$heightNeeded = $this->getLastH(); $heightNeeded = $this->getLastH();

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;
} }