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 6760719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:05:51+00:00 2026-05-26T14:05:51+00:00

I’m implementing a logic where you can use either your username or email address

  • 0

I’m implementing a logic where you can use either your username or email address to log in in CakePHP. I’m following an example in a book called CakePHP 1.3: Application Development Cookbook (Chapter 1: Allowing logins with username or email). The book explains that when the Auth component cannot log the user in with the provided info, it goes back to the login() action and can look for additional info that might log the user in with the logic within the login() action.

The code/logic is working. However, when I login with my email address, it still displays the loginError message, which says “Invalid account specified.” Below that it says “Welcome,” which is a message I display when a login is successfull.

These are what I’d like to know:

  1. The book doesn’t indicate whether or not this is normal, but I’d like to learn how to omit this error message, since it doesn’t make sense. Where is THIS LINE (in comment) taking the user? The error message displays after that line.

  2. .. and possibly display with “you logged logged in with email.” This is of secondary importance.

Below are what I think relevant code. Please let me know if you need more.

class AppController extends Controller {
public $components = array(
    'Auth' => array(
        'authorize' => 'controller',
        'loginRedirect' => array(
            'admin' => false,
            'controller' => 'users',
            'action' => 'dashboard'
        ),
        'loginError' => 'Invalid account specified',
        'authError' => 'You don\'t have the right permission'
    ),
    'Session'
);
}


class UsersController extends AppController {
public function login() {
    if (
        !empty($this->data) &&
        !empty($this->Auth->data['User']['username']) &&
        !empty($this->Auth->data['User']['password'])
    ) {
        $user = $this->User->find('first', array(
            'conditions' => array(
                'User.email' => $this->Auth->data['User']['username'],
                'User.password' => $this->Auth->data['User']['password']
            ),
            'recursive' => -1
        ));

        if (!empty($user) && $this->Auth->login($user)) {   // $this->Auth->login() true if logs in
            if ($this->Auth->autoRedirect) {    // I think autoRedirect is TRUE by default

                $this->redirect($this->Auth->redirect()); // <<THIS LINE>>
            }
        } else {
            $this->Session->setFlash($this->Auth->loginError, $this->Auth->flashElement, array(), 'auth');
        }           
    }
}
  • 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-26T14:05:52+00:00Added an answer on May 26, 2026 at 2:05 pm
        if (!empty($user) && $this->Auth->login($user)) {
            $this->Session->delete('Message.auth');
        }
    

    You don’t need to setFlash for authError if you flash(‘auth’) in login view (as in the cookbook) and you don’t need to call redirect.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.