07.01
php
saved
kaotisch
Note
login view, users controller, app controller
login view, users controller, app controller
- <?= $session->flash('auth');
- pr($this->params);
- <div class="login">
- <h2>Login</h2>
- </div>
- <?PHP
- class UsersController extends AppController {
- var $name = 'Users';
- function beforeFilter() {
- //pr($this->data);
- }
- function login() {
- $this->set('stat',"Try login");
- $this->set('error', false);
- $results = $this->User->findByUsername($this->data['User']['username']);
- //pr($results);
- if ($results && $results['User']['password'] == $this->Auth->password($this->data['User']['password'])) {
- $this->set('stat',"Logged in!");
- $this->Session->write('user', $this->data['User']['username']);
- $this->redirect('/verwaltung/patienten/view/');
- } else {
- // login data is wrong, redirect to login page
- $this->set('stat',"Not logged in!");
- $this->Session->setFlash('Wrong username / password. Please try again.');
- $this->redirect('/verwaltung/users/login/');
- }
- } else {
- $this->set('stat',"daten leer? ".$this->data['User']['username']);
- $this->render();
- }
- }
- function logout() {
- $this->redirect($this->Auth->logout());
- }
- }
- ?>
- <?php
- /* SVN FILE: $Id: app_controller.php 6311 2008-01-02 06:33:52Z phpnut $ */
- /**
- * Short description for file.
- *
- * This file is application-wide controller file. You can put all
- * application-wide controller-related methods here.
- *
- * PHP versions 4 and 5
- *
- * CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
- * Copyright 2005-2008, Cake Software Foundation, Inc.
- * 1785 E. Sahara Avenue, Suite 490-204
- * Las Vegas, Nevada 89104
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
- * @package cake
- * @subpackage cake.cake
- * @since CakePHP(tm) v 0.2.9
- * @version $Revision: 6311 $
- * @modifiedby $LastChangedBy: phpnut $
- * @lastmodified $Date: 2008-01-01 22:33:52 -0800 (Tue, 01 Jan 2008) $
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- */
- /**
- * This is a placeholder class.
- * Create the same file in app/app_controller.php
- *
- * Add your application-wide methods in the class below, your controllers
- * will inherit them.
- *
- * @package cake
- * @subpackage cake.cake
- */
- class AppController extends Controller {
- function beforeFilter(){
- }
- function checkSession(){
- //fill $username with session data
- $username = $this->Session->read('user');
- // if the $username is empty,
- // send user to login page
- if (!$username){
- $this->Session->setFlash('Kein Benutzername angegeben');
- $this->redirect('/verwaltung/users/login/');
- } else {
- // if $username is not empty,
- // check to make sure it's correct
- $results = $this->User->findByUsername($username);
- // if not correct, send to login page
- if(!$results){
- $this->Session->delete('user');
- $this->Session->setFlash('Incorrect session data.');
- $this->redirect('/verwaltung/users/login/');
- }
- // otherwise set $user variable as users email address
- $this->set('user', $results['User']['username']);
- }
- }
- }
- ?>
Parsed in 0.186 seconds, using GeSHi 1.0.7.14