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

  • SEARCH
  • Home
  • 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 6880449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:58:32+00:00 2026-05-27T04:58:32+00:00

I have the below in my users_controller because there is further logic needed to

  • 0

I have the below in my users_controller because there is further logic needed to perform the login, however when done in CakePHP the default validation stops and therefore i am trying to force it to validate the username and password fields before doing the account check. Everything works fine but this. I have tried adding two if statements (below) to check if username/password is empty, however as soon as the page loads they are empty and the validation box shows.

I am stumped as to how to achieve this. Any help would be greatly appreciated.

    function login() {
    if($this->Auth->user()) {
        $this->redirect(array('controller'=>'shows'));
    }
    if(empty($this->data['User']['username'])) {
        $this->User->validationErrors['username'] = "Please enter a username";
    }
    if(empty($this->data['User']['password'])) {
        $this->User->validationErrors['password'] = "Please enter a password";
    }
    if(!empty($this->data['User']['username'])) {
        // unset unrequired validation rules
        unset($this->User->validate['username']['unique']);

        // validate form
        $this->User->set($this->data);
        if($this->User->validates()) {
            // update Last Login date
            $this->User->id = $this->User->_user['User']['id'];
            $this->User->saveField('last_login',date("Y-m-d H:i:s"));

            // save User to Session and redirect
            $this->Session->write('User', $this->User->_user);
            $this->Session->setFlash('You have successfully logged in.','default',array('class'=>'flash_green'));
            //$this->redirect(array('controller'=>'shows', 'admin'=>FALSE));
        } else {
            $this->Session->setFlash('Incorrect username/password combination.','default',array('class'=>'flash_red'));
            $this->redirect(array('controller'=>'users', 'action'=>'login', 'admin'=>FALSE));
        }
    }
}

users_controller beforeFilter()

    function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('register');
}

app_controller beforeFilter and components

    var $components = array('Session', 'Auth' => array(
    'loginAction' => array('controller'=>'users','action'=>'login', 'admin'=>false),
    //'logoutRedirect' => array('controller'=>'users','action'=>'logout'),
    'loginRedirect' => array('controller'=>'shows', 'action'=>'index'),
    'autoRedirect' => false,
    'authorize' => 'controller')
);

function beforeFilter() {
    $this->Auth->allow('home');
    $this->set('admin', $this->_isAdmin());
    $this->set('logged_in', $this->_loggedIn());
    $this->set('users_username', $this->_usersUsername());
}
  • 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-27T04:58:32+00:00Added an answer on May 27, 2026 at 4:58 am

    Remove the below code from the user_controller.php file.

     else {
            $this->Session->setFlash('Incorrect username/password combination.','default',array('class'=>'flash_red'));
            $this->redirect(array('controller'=>'users', 'action'=>'login', 'admin'=>FALSE));
        }
    

    This is looping the page back to the login action with no data and therefore no validation.

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

Sidebar

Related Questions

i have a usercenter/users_controller,in this controller have code like belows def login end def
I have below trigger ALTER TRIGGER [dbo].[DeleteUserData] ON [dbo].[site_users] AFTER DELETE AS BEGIN SET
I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator
Below is an old PHP function I have for a dropdown list for users
I have this javascript code below that uses jquery, it is suppoed to be
I have a problem for querying records into mysql explanation below The user could
I have a user who randomly gets a Script Error box (shown below) which
I have data stored as below in an MS Access database: Date User 20090101
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
Below is my table, a User could have multiple profiles in certain languages, non-English

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.