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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:17:47+00:00 2026-05-28T07:17:47+00:00

I’m having trouble hashing out how to test whether a user is active using

  • 0

I’m having trouble hashing out how to test whether a user is active using the new Auth component. I have 3 states a user can be in: 0 unactivated (default), 1 activated, 2 deactivated. I’m trying to implement this in the login function so I can return whether they haven’t registered or have been banned.

Login:

        public function login() {
        if ($this->request->is('post')) {
            if($this->Auth->login()) {                   
                $results = $this->User->find('all', array(
                    'conditions' => array('User.email' => $this->Auth->user('email')),
                    'fields' => array('User.is_active')
                ));
                if ($results['User']['is_active'] == 0) {
                    // User has not confirmed account
                    $this->Session->setFlash('Your account has not been activated. Please check your email.');
                    $this->Auth->logout();
                    $this->redirect(array('action'=>'login'));
                }
               // not working atm
                else if ($results['User']['is_active'] == 2) {
                    // User has been deactivated
                    $this->Session->setFlash('Your account has been deactivated. Contact site admin if you believe this is in error.');
                    $this->Auth->logout();
                    $this->redirect(array('action'=>'login'));
                }
                else if ($results['User']['is_active'] == 1) {
                    // User is active
                      $this->redirect($this->Auth->redirect());
                    }
            } else {
                $this->Session->setFlash(__('Your email/password combination was incorrect'));
            }
        }
    }

Can’t see where I’ve gone wrong. Users with admin privileges and activated users are still getting the unactivated account error.

Update

Decided to drop the User.is_active field and handle it all in roles. I’m handling it in the AppController and it is almost working now. In the isAuthorized function, it now throws errors if the user is banned or unactivated, but I need it to log them out as well.

    public function isAuthorized($user) {
    // This isAuthorized determines what logged in users are able to see on ALL controllers. Use controller
    // by controller isAuthorized to limit what they can view on each one. Basically, you do not want to allow
    // actions on all controllers for users. Only admins can access every controller.
    if (isset($user['role']) && $user['role'] === 'admin') {
        return true; //Admin can access every action
    }
    elseif (isset($user['role']) && $user['role'] === 'unactivated') { // Account has not been activated
        $this->Session->setFlash("You haven't activated your account yet. Please check your email.");
        return false; 
    }
    elseif (isset($user['role']) && $user['role'] === 'banned') { // Your account has been banned
        $this->Session->setFlash("You're account has been banned. If you feel this was an error, please contact the site administrator.");
        return false;
    }
    return false; // The rest don't
}
  • 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-28T07:17:48+00:00Added an answer on May 28, 2026 at 7:17 am

    If they log in, the User model info can be accessed with $this->Auth->user(). So you should be able to do something like this:

    if ($this->Auth->login()) {
        if ($this->Auth->user('is_active') == 0) {
            // User has not confirmed account
        } else if ($this->Auth->user('is_active') == 1) {
            // User is active
    
        // and so on
    

    You can use debug($this->Auth->user()); after the login() to see why the users keep showing as unactivated.

    • 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 have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.