06.28
php
saved
ddd
Note
ddd
ddd
- <h1>User Login</h1>
- <table class="whatever">
- <tr>
- <th>Username</th>
- </tr>
- <tr>
- <th>Password</th>
- </tr>
- <tr>
- <th>Remember Me</th>
- 'Remember Me', 'type' => 'checkbox')); ?></td>
- </tr>
- <tr>
- <th> </th>
- => $this->base . '/images/login-down.png', 'border' => '0'));?></th>
- </tr>
- </table>
- <input type="hidden" name="XDEBUG_SESSION_START" value="tim" />
- *** /views/users/register.ctp
- <h1>User Registration</h1>
- <table class="whatever">
- <tr>
- <th>Username</th>
- > <span class="required_field">*</span></td>
- </tr>
- <tr>
- <th>Email Address</th>
- class="required_field">*</span><br />
- Please note your confirmation email will be sent to this address</
- td>
- </tr>
- <tr>
- <th>Password</th>
- 'size'=>'15', 'div' => null)); ?> <span
- class="required_field">*</span></td>
- </tr>
- <tr>
- <th>Confirm Password</th>
- 'size'=>'15', 'div' => null)); ?> <span
- class="required_field">*</span></td>
- </tr>
- <tr>
- <th> </th>
- 'srcdown' => $this->base . '/images/register-down.png', 'border' =>
- '0'));?></th>
- </tr>
- </table>
- <input type="hidden" name="XDEBUG_SESSION_START" value="tim" />
- *** /controllers/login.php
- <?php
- /**
- * User Controller class
- */
- class UsersController extends AppController {
- var $name = 'Users';
- function index() {
- $this->redirect('/home');
- }
- /**
- * Login the user
- */
- function login() {
- //-- code inside this function will execute only when autoRedirect
- was set to false (i.e. in a beforeFilter).
- if ($this->RequestHandler->isPost()) {
- if ($this->Auth->user()) { // Does user/password checking
- == '1') {
- // Save cookie only if checkbox ticked
- $cookie['username'] = $this->data['User']['username'];
- $cookie['password'] = $this->data['User']['password'];
- $this->Cookie->write('Auth.User', $cookie, true, '+2
- weeks');
- }
- $this->redirect($this->Auth->redirect());
- } else {
- $this->Session->setFlash('Invalid user or password');
- }
- }
- }
- /**
- * Log out user
- *
- */
- function logout(){
- $cookie = $this->Cookie->read('Auth.User');
- $this->Cookie->del('Auth.User');
- $this->redirect($this->Auth->logout());
- }
- function register() {
- // Check if user already logged in
- $i = $this->getUserID();
- if ($i != null && $i > 0) {
- $this->Session->setFlash('You\'re already logged in!');
- $this->redirect('/home/index');
- }
- // Setup data for page
- $this->set('title', $this->appName .'User Registration');
- be between 3 and 10 characters long',
- 'password' => 'Your password must be
- between 4 and 10 characters long',
- 'email' => 'Please enter a valid email
- address',
- 'first_name' => 'name size is too
- short'
- )));
- // Just show the form
- } else {
- // Need to encode password2 so it can be matched with password
- by validation, but need to keep the length
- // around to check as encoded password is always the same length
- >data['User']['password2']);
- $this->data['User']['password2'] = $this->Auth->password($this-
- >data['User']['password2']);
- // Attempt to register the user
- if ($this->User->save($this->data)) {
- $this->set('title', $this->appName .'User Registration
- Succesful');
- $this->set('user', $this->data);
- $this->render('register_email_sent');
- return;
- } else {
- $this->Session->setFlash('Please correct the errors
- highlighted below');
- $this->data['User']['password'] = $this->data['User']
- ['password2'] = '';
- }
- }
- }
- function beforeFilter() {
- $this->set('title', $this->appName .'User Login');
- parent::beforeFilter();
- }
- }
- ?>
- /controllers/app_controller.php
- <?php
- /**
- * Main App Controller File
- */
- class AppController extends Controller {
- var $home = '/home/view/';
- /**
- * Load the Authentication
- *
- * @access public
- */
- function beforeFilter(){
- => 'login');
- $this->Auth->allow('index');
- $this->Auth->authorize = 'controller';
- $this->Auth->autoRedirect = false;
- if ($this->getUserID() == -1) {
- $this->loginFromCookie();
- }
- }
- function loginFromCookie() {
- $cookie = $this->Cookie->read('Auth.User');
- if ($this->Auth->login($cookie)) {
- // Clear auth message, just in case we use it.
- $this->Session->del('Message.auth');
- //$this->redirect($this->Auth->redirect());
- } else { // Delete invalid Cookie
- $this->Cookie->del('Auth.User');
- }
- }
- }
- function getUserID() {
- $usr = $this->Auth->user();
- return $usr['User']['id'];
- } else {
- return -1;
- }
- }
- }
Parsed in 0.473 seconds, using GeSHi 1.0.7.14