*hey* please tell me how to make login page for admin in cake php i am a
newbie so dont know much...

I have made a table as "user" name with email pass and id fields.

I have made user.php page and user_controller.php page and
view/user/login.ctp file

*model/user.php page*

<?php
class User extends AppModel {
  var $name = 'User';
  var $useTable = 'users';

  var $validate = array(
    'email' => array(
      'kosher' => array(
        'rule' => 'email',
        'message' => 'Please make sure your email is entered correctly.'
      ),
      'unique' => array(
        'rule' => 'isUnique',
        'message' => 'An account with that email already exists.'
      ),
      'required' => array(
        'rule' => 'notEmpty',
        'message' => 'Please Enter your email.'
      )
    ),
    'passwd' => array(
      'min' => array(
        'rule' => array('minLength', 6),
        'message' => 'Usernames must be at least 6 characters.'
      ),
      'required' => array(
        'rule' => 'notEmpty',
        'message'=>'Please enter a password.'
      ),
    ),
    'passwd_confirm' => array(
      'required'=>'notEmpty',
      'match'=>array(
        'rule' => 'validatePasswdConfirm',
        'message' => 'Passwords do not match'
      )
    ),
    'firstname' => array(
      'required' => array(
        'rule' => 'notEmpty',
        'message'=>'Please enter your first name.'
      ),
      'max' => array(
        'rule' => array('maxLength', 30),
        'message' => 'First name must be fewer than 30 characters'
      )
    ),
    'lastname' => array(
      'required' => array(
        'rule' => 'notEmpty',
        'message' => 'Please enter your last name.'
      ),
      'max' => array(
        'rule' => array('maxLength', 30),
        'message' => 'Last name must be fewer than 30 characters'
      )
    )
  );

  function validatePasswdConfirm($data)
  {
    if ($this->data['User']['passwd'] !== $data['passwd_confirm'])
    {
      return false;
    }
    return true;
  }

  function beforeSave()
  {
    if (isset($this->data['User']['passwd']))
    {
      $this->data['User']['password'] =
Security::hash($this->data['User']['passwd'], null, true);
      unset($this->data['User']['passwd']);
    }

    if (isset($this->data['User']['passwd_confirm']))
    {
      unset($this->data['User']['passwd_confirm']);
    }

    return true;
}

}
?>

*controller/user_controller.php page
*

 <?php
 var $components = array('Auth');
 function beforeFilter() {
  $this->Auth->userModel = 'User';
  $this->Auth->fields = array('username' => 'email', 'password' =>
'password');
  $this->Auth->loginAction = array('admin' => false, 'controller' =>
'users', 'action' => 'login');
  $this->Auth->loginRedirect = array('controller' => 'users', 'action' =>
'index');
 }
 function login() {}

 function logout() {
  $this->redirect($this->Auth->logout());
 }
function beforeFilter() { //function that enables people to register
without logging in
  $this->Auth->allow('add');
  parent::beforeFilter();
 }
?>
*
view/users/login.ctp*

<?php
    if  ($session->check('Message.auth')) $session->flash('auth');  // If
authentication message it exist it will be displayed
    echo $form->create('User', array('action' => 'login')); // creating
user form with 2 fields email and password
    echo $form->input('email');
    echo $form->input('password');
    echo $form->end('Login');
?>

*please do check out the naming conventions also and do tell me how to use
them properly*

-- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.


Reply via email to