0
votes

isUnique validation doesn't work if there there is validation error only of uniqueness in user creating form and gives error of 'The page isn't redirecting properly'. Model code is:

class User extends AppModel {
    public $validate = array(
        'username' => array(
            'notEmpty' => array(
                'rule' => array('email'),
                'message' => 'Please supply a valid email address.'
            ),
            'isUnique' => array(
                'rule' => 'isUnique',
                'message' => 'This email has already been taken.'
            )
        ),
        'password' => array(
            'min' => array(
                'rule' => array('minLength', 3),
                'message' => 'Password must be at least 3 characters.'
            ),
            'required' => array(
                'rule' => 'notEmpty',
                'message' => 'Please enter a password.'
            ),
        ),
        'cpassword' => array(
            'required' => 'notEmpty',
            'match' => array(
                'rule' => 'validatePasswdConfirm',
                'message' => 'Passwords do not match'
            )
        )
    );
}

When I enter mismatch passwords then it gives error of 'Passwords do not match' and also gives error 'This email has already been taken.' if a username is already there in users table but the problem is when I Only enter the username which already exists and enter a match password then it goes to a page with error "The page isn't redirecting properly". How can I fix this issue? Thanks in advance.

1
If I remove the isUnique validation from model even then I get to the "The page isn't redirecting properly" page.NTkhan
I asked this issue also here: stackoverflow.com/questions/27012195/…NTkhan
Actually it logout the current logged-in user.....NTkhan
Can you please post the matching controller code? Normally if the validation does not work you should be redirected to the edit form and shown the error message, but maybe the redirect in your controller is faulty somewhere.Calamity Jane
I would also suggest that you test the validation without the additional complication with the Auth Component. Then you can see more clearly where the problem lies.Calamity Jane

1 Answers

1
votes

if you have used $this->Auth->login() in beforeFilter for any condition, remove it and use !empty($this->Auth->user('id')) instead of $this->Auth->login() for you conditions in beforeFilter.