07.01 php saved
kaotisch
Tags add more
 
Note
login view, users controller, app controller
  1. <?= $session->flash('auth');
  2. pr($this->params);
  3. echo "stat:".$stat; echo "user:".$user;    pr($this->data);?>
  4. <div class="login">
  5. <h2>Login</h2>   
  6. <?php echo $form->create('User', array('action' => 'login'));?>
  7.         <?php echo $form->input('username');?>
  8.         <?php echo $form->input('password');?>
  9.         <?php echo $form->submit('Login');?>
  10.     <?php echo $form->end(); ?>
  11. </div>
  12.  
  13.  
  14. <?PHP
  15. class UsersController extends AppController {
  16.  
  17.     var $name = 'Users';   
  18.     var $components = array('Auth');
  19.     function beforeFilter() {
  20.     //pr($this->data);
  21.     }
  22. function login() {
  23.     $this->set('stat',"Try login");
  24.     $this->set('error', false);
  25.    
  26.     echo "pre log in".$this->data;
  27.    
  28.     if (!empty($this->data['User']['username']))     {
  29.    
  30.         $results = $this->User->findByUsername($this->data['User']['username']);
  31.         //pr($results);
  32.         if ($results && $results['User']['password'] == $this->Auth->password($this->data['User']['password'])) {
  33.  
  34.             $this->set('stat',"Logged in!");
  35.  
  36.             $this->Session->write('user', $this->data['User']['username']);
  37.  
  38.             $this->redirect('/verwaltung/patienten/view/');
  39.         } else {
  40.             // login data is wrong, redirect to login page
  41.              
  42.                $this->set('stat',"Not logged in!");
  43.             $this->Session->setFlash('Wrong username / password. Please try again.');
  44.             $this->redirect('/verwaltung/users/login/');
  45.         }
  46.     } else {
  47.         $this->set('stat',"daten leer? ".$this->data['User']['username']);
  48.         echo "data: ".pr($this->data);
  49.         $this->render();
  50.     }
  51. }
  52.  
  53.     function logout() {
  54.         $this->redirect($this->Auth->logout());
  55.     }
  56. }
  57. ?>
  58.  
  59.  
  60.  
  61.  
  62. <?php
  63. /* SVN FILE: $Id: app_controller.php 6311 2008-01-02 06:33:52Z phpnut $ */
  64. /**
  65. * Short description for file.
  66. *
  67. * This file is application-wide controller file. You can put all
  68. * application-wide controller-related methods here.
  69. *
  70. * PHP versions 4 and 5
  71. *
  72. * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
  73. * Copyright 2005-2008, Cake Software Foundation, Inc.
  74. *                1785 E. Sahara Avenue, Suite 490-204
  75. *                Las Vegas, Nevada 89104
  76. *
  77. * Licensed under The MIT License
  78. * Redistributions of files must retain the above copyright notice.
  79. *
  80. * @filesource
  81. * @copyright      Copyright 2005-2008, Cake Software Foundation, Inc.
  82. * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  83. * @package   cake
  84. * @subpackage    cake.cake
  85. * @since         CakePHP(tm) v 0.2.9
  86. * @version   $Revision: 6311 $
  87. * @modifiedby    $LastChangedBy: phpnut $
  88. * @lastmodified    $Date: 2008-01-01 22:33:52 -0800 (Tue, 01 Jan 2008) $
  89. * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
  90. */
  91. /**
  92. * This is a placeholder class.
  93. * Create the same file in app/app_controller.php
  94. *
  95. * Add your application-wide methods in the class below, your controllers
  96. * will inherit them.
  97. *
  98. * @package  cake
  99. * @subpackage  cake.cake
  100. */
  101. class AppController extends Controller {
  102. var $components = array('Auth');
  103. function beforeFilter(){
  104.    
  105. }
  106.  
  107. function checkSession(){
  108.  
  109.     //fill $username with session data
  110.     $username = $this->Session->read('user');
  111.  
  112.     // if the $username is empty,
  113.     // send user to login page
  114.     if (!$username){
  115.         $this->Session->setFlash('Kein Benutzername angegeben');
  116.         $this->redirect('/verwaltung/users/login/');
  117.        
  118.         exit();
  119.     } else {
  120.         // if $username is not empty,
  121.         // check to make sure it's correct
  122.         $results = $this->User->findByUsername($username);
  123.  
  124.         // if not correct, send to login page
  125.         if(!$results){
  126.             $this->Session->delete('user');
  127.             $this->Session->setFlash('Incorrect session data.');
  128.             $this->redirect('/verwaltung/users/login/');
  129.             exit();
  130.         }
  131.  
  132.         // otherwise set $user variable as users email address
  133.         $this->set('user', $results['User']['username']);
  134.     }
  135. }
  136. }
  137. ?>
Parsed in 0.186 seconds, using GeSHi 1.0.7.14

Modify this Paste