Controller (where I suspect the problem is, most changes were made
here):
<?php
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form');
var $components = array('Auth');
//authentication allowance
function beforeFilter() {
$this->Auth->allow('register', 'top');
}
//top users funciton
function top() {
$this->set('users', $this->User->findAll());
}
//login function
function login() {
}
//index function
function index() {
}
//register function
function register() {
if (!empty($this->data)) {
if ($this->data['User']['password'] ==
$this->Auth->password($this-
>data['User']['password_confirm'])) {
$this->User->create();
$this->User->save($this->data);
$this->Session->setFlash("You have been
registered! You can log
in now.");
$this->redirect(array('action' => 'index'));
}
}
}
}
?>
Model:
<?php
class User extends AppModel {
var $name = 'User';
var $useTable = 'users';
var $validate = array(
//username validation
'username' => array(
VALID_NOT_EMPTY,
'alphanumeric' => array(
'rule' => 'alphaNumeric',
'message' => 'Only alphabets and numbers allowed',
),
'maxlength' => array(
'rule' => array('maxLength', 50),
'message' => 'Username has a maximum length of
50 characters',
),
'required' => array(
'rule' => array('required' => true),
'message' => 'Username is required, how do you
expect to log in?'
),
'isUnique' => array(
'rule' => array('isUnique', 'username'),
'message' => 'Hey! Lookey there, someone got to
that username
before you. Sorry, but you\'ll have to choose another.'
)
),
//email validation
'email' => array(
VALID_NOT_EMPTY,
'maxlength' => array(
'rule' => array('maxLength', 40),
'message' => 'Email has a maximum length of 40
characters.'
),
'email' => array(
'rule' => array('email', true),
'message' => 'Please supply a valid email
address.'
),
'required' => array(
'rule' => array('required' => true),
'message' => 'Email is required.'
),
'isUnique' => array(
'rule' => array('isUnique', 'email'),
'message' => 'That email address has already
been claimed by
another... maybe even you, please try again. This time enter an email
address not in use on this site ;-)'
)
),
//first name validation
'first_name' => array(
VALID_NOT_EMPTY,
'maxlength' => array(
'rule' => array('maxLength', 15),
'message' => 'First name has a maximum length
of 15 characters',
),
'required' => array(
'rule' => array('required' => true),
'message' => 'First name is required, don\'t
you want your friends
to be able to find you?'
)
),
//last name validation
'last_name' => array(
VALID_NOT_EMPTY,
'maxlength' => array(
'rule' => array('maxLength', 30),
'message' => 'Last name has a maximum length of
30 characters'
),
'required' => array(
'rule' => array('required' => true),
'message' => 'Last name is required, don\'t you
want your friends
to be able to find you?'
)
),
//password validation
'password' => array(
'passwordConfirm' => array(
'rule' => array('confirmPassword', 'password'),
'message' => 'passwords don\'t match up, please
verify and submit
again!'
)
),
//confirm password
'confirm_password' => array(
VALID_NOT_EMPTY,
'alphanumeric' => array(
'rule' => 'alphaNumeric',
'message' => 'Only alphabets and numbers
allowed'
),
'between' => array(
'rule' => array('between', 4, 20),
'message' => 'Password must be between 4 and 20
characters long.'
),
'required' => array(
'rule' => array('required' => true),
'message' => 'Did you think you\'d get away
with a blank
password?'
)
)
); //end validation
//password confirmation function
function confirmPassword($data) {
$valid = false;
if ($data['password'] ==
Security::hash(Configure::read('Security.salt') . $this->data['User']
['password_confirm'])) {
$valid = true;
}
return $valid;
}
} //end main class
?>
View:
<h1>New User Registration</h1>
<?php echo $form->create('user', array('action' => 'register')); ?>
<table>
<tr>
<td>Username:</td>
<td><?php echo $form->input('User.username', array('label' =>
'',
'size'=>'50')) ?><br />
<small></small></td>
</tr>
<tr>
<td>Email:</td>
<td><?php echo $form->input('User.email', array('label' => '',
'size'=>'40')) ?><br />
<small>Must be a valid email address. Also must
be unique,
only allowed to register once per email address.</small></td>
</tr>
<tr>
<td>First Name:</td>
<td><?php echo $form->input('User.first_name', array('label' =>
'',
'size'=>'15')) ?></td>
</tr>
<tr>
<td>Last Name:</td>
<td><?php echo $form->input('User.last_name', array('label' =>
'',
'size'=>'30')) ?></td>
</tr>
<tr>
<td>Password:</td>
<td><?php echo $form->input('User.password', array('size'=>'20',
'label' => '', 'value' => '')) ?><br />
<small>Must be between 4 and 20 characters long. Use
only letters
and numbers.</small></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><?php echo $form->input('User.password_confirm',
array('size'=>'20', 'type' => 'password', 'label' => '', 'value' =>
'')) ?></td>
</tr>
<tr>
<td>Birth Date:</td>
<td><?php echo $form->input('User.birth_date', array('label' =>
'',
'dateFormat' => 'DMY', 'minYear' => '1940', 'maxYear' => '2000')) ?></
td>
</tr>
<tr>
<td>Submit:</td>
<td><?php echo $form->submit('Sign Up') ?></td>
</tr>
<tr>
<th colspan="2">**All Fields are required**</th>
</tr>
</table>
</form>
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---