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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:57:51+00:00 2026-06-15T08:57:51+00:00

In yii I can use: self::ERROR_USERNAME_INVALID; I want another one: self::ERROR_USER_BANNED; That must give

  • 0

In yii I can use:

self::ERROR_USERNAME_INVALID;

I want another one:

self::ERROR_USER_BANNED;

That must give the error:

Sorry, but you cannot login because you account has been blocked.

How do I set this up?

  • 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-06-15T08:57:53+00:00Added an answer on June 15, 2026 at 8:57 am

    Add it directly to your protected/components/UserIdentity.php :

    class UserIdentity extends CUserIdentity {
        const ERROR_USER_BANNED = -1; // say -1 you have to give some int value
    
        public function authenticate() {
            // ... code ...
            if (/* condition to check for banning */) { // you might want to put this check right after any other username checks, and before password checks
                $this->errorCode=self::ERROR_USER_BANNED;
                $this->errorMessage='Sorry, but you cannot login because your account has been blocked.'
                return $this->errorCode;
            }
        }
    }
    

    The default way with LoginForm.php model :

    Add a new validator rule, say to your username field:

    public function rules() {
        return array(
            // ... other rules ...
            array('username','isBanned')
        );
    }
    
    // the isbanned validator
    public function isBanned($attribute,$params) {
        if($this->_identity===null)
            $this->_identity=new UserIdentity($this->username,$this->password);
    
        if($this->_identity->authenticate() === UserIdentity::ERROR_USER_BANNED){
            $this->addError($attribute,$this->_identity->errorMessage);
    }
    

    Ofcourse you could have declared another function in UserIdentity to check just for banning, and call that function from the isBanned validator, instead of having things in the authenticate function.

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

Sidebar

Related Questions

I was using Yii's CPhpMessageSource for message translations. BUt i don't want to use
I'm trying to create small application on Yii framework but can't understand one moment.
Can anyone give example of how to use CHtml::ajaxbutton with Yii for posting the
Ok I have a controller class in Yii that I want to use a
I use shared hosting and didn't want to install core library of Yii in
I've created Yii quiz module which I also want to use in Facebook app
Iam a yii newbie (started a week ago) and i want to use the
how I can use array in cell related with another table in database like
in Yii framework, can I use unique validation rule to check uniqueness of an
If I only use DAO to save data in Yii , can I use

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.