Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6213339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:40:43+00:00 2026-05-24T06:40:43+00:00

I have tried to get this function working in the desired way but not

  • 0

I have tried to get this function working in the desired way but not having much luck.
The good news is, is that it works. Only thing I wanted to get working correctly is the field validation error messages which I managed to, but could not login in even if the username and password were correct. I have rolled back the function in the hope that someone could shed some light on this for me please.

    function login() {
            $this->layout = 'login';
            $this->set('title_for_layout', 'Login');
            if (!empty($this->data) && $id = $this->Auth->user('id')) { 
                    $this->User->id = $id; 
                    $this->User->saveField('last_login', date('Y-m-d H:i:s')); 
                    $this->Session->setFlash(__('You have successfully logged in', true));
                    $this->redirect(array('action'=>'index')); 
            }    
    }

The validation which I have setup in the users model:

var $validate = array(
                'username' => array(
               ),
                'login' => array(
                            'rule' => 'isUnique',
                            'message' => 'This username has already been taken',
                     ),
                    'pattern' => array(
                            'rule' => array('custom','/[a-zA-Z0-9\_\-]{6,}$/i'),
                            'message' => 'Must be 6 characters or longer with no spaces',
                    ),
                    'length' => array(
                            'rule' => array('maxLength', 15),
                            'message' => 'Please keep username under 15 characters',
                    ),
                    'notempty' => array(
                            'rule' => array('notempty'),
                            'message' => 'Username cannot be empty',
                    ),
            ),
        'password' => array(
                        'notempty' => array(
                                'rule' => array('notempty'),
                                'message' => 'Password cannot be empty',
                        ),
                        'length' => array(
                                'rule' => array('between', 5, 15),
                                'message' => 'Passwords must be between 5 and 15 characters long with no spaces',
                                'on' => 'create',
                        )
        )
);

I shall unset certain validation rules for the login, I for now would just like to get the validation actually working in the correct manner.

Really, I have three questions…

  1. Why is my validation not working correctly?

  2. How can I display messages from the AuthComponent in my views?

  3. How can I temporarily disable the modified field in my table from updating?

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:40:45+00:00Added an answer on May 24, 2026 at 6:40 am

    Beside the error I found in my comment I’m fairly certain your login validation isn’t setup correctly.

    Here’s what you have:

    'login' => array(
                    'rule' => 'isUnique',
                    'message' => 'This username has already been taken',
                ),
                            'pattern' => array(
                                    'rule' => array('custom','/[a-zA-Z0-9\_\-]{6,}$/i'),
                                    'message' => 'Must be 6 characters or longer with no spaces',
                            ),
                            'length' => array(
                                    'rule' => array('maxLength', 15),
                                    'message' => 'Please keep username under 15 characters',
                            ),
                            'notempty' => array(
                                    'rule' => array('notempty'),
                                    'message' => 'Username cannot be empty',
                            ),
            ),
    

    Here’s what I think you want to have

    'username' => array(
        'isUnique' => array(
            'rule' => 'isUnique',
            'message' => 'This username has already been taken'
        ),
        'pattern' => array(
            'rule' => array('custom','/[a-zA-Z0-9\_\-]{6,}$/i'),
            'message' => 'Must be 6 characters or longer with no spaces',
        ),
        'length' => array(
            'rule' => array('maxLength', 15),
            'message' => 'Please keep username under 15 characters',
        ),
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => 'Username cannot be empty',
        ),
    ),
    

    Mandatory links to the CakePHP Book and the CakePHP API.


    Answer to error from OP in comment:

    I see now what you were trying to do. Try this:

    $id = $this->Auth->user('id');
    if (!empty($this->data) && $id) { 
                    $this->User->id = $id;
    

    Answer to “How to display my login error message from the AuthComponent?”

    For the login error message to appear you will need to add the following line in your layout or view for your login form.

    echo $this->Session->flash('auth');
    

    Answer to “How to temporarily disable CakePHP’s modified behavior?”:

    Well, a brief look at the source code and the answer to this question on Cake’s internal QA you can add something like this before you save the data.

    $this->data['User']['modified'] = false;
    

    This tells Cake to not update the modified field.

    Interestingly enough from the source code it appears that you could just as easily replace false with true and it wouldn’t update the field. I don’t know if this is actually the case though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried many things to get this working correctly but I can't Here
I am trying to get this jGrowl working but I am not having any
I have tried and failed to get this working. Basically I am trying to
Hello you naughty code animals.. I have tried to get this code to work,
I'm coding some c# against Active Directory and have tried endlessly to get this
I cannot get smooth lines for this graph. I have tried anti aliasing, increasing
Does file_get_contents maintain line breaks? I thought it did but I have tried this:
Have you managed to get Aptana Studio debugging to work? I tried following this,
i have tried to get the sine wave example running on an AsioOut, but
I have tried using date(m/d/Y, strtotime(04-05-2012)) but I will get 05/04/2012 or on some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.