TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
De-activate an username and regenerate the same in kohana
  • In my application,i want to de-activate the existing user and able to create new user with same username and email address.I know,kohana have set username and email address as unique i created a column called is_deactivated in User table and setting a flag to that.If the user is deactivated,the flag set to zero,else the flag is "1".I written an separate function for validation of unique username and email address with reference to is_deactivated flag.If the flag is "0",validation will ignore the existing username and email address and user able to create new user with same existing username and password.New username is created with same username.After signup,it is taking me to existing de-activated user account, instead of fresh new account.But if i login with same username and password,it is taking me to existing de-activated account.In login,i had validated with this is_deactivated flag with 1.

    for creating new user with same username i had commented the below lines from User.php,

    /var/www/html/zergid/modules/orm/classes/Model/Auth/User.php
    
    public function rules()
        {
            return array(
    //          'username' => array(
    //              array('not_empty'),
    //              array('max_length', array(':value', 32)),
    //              array(array($this, 'unique'), array('username', ':value')),
    //          ),
                'password' => array(
                    array('not_empty'),
                ),
    //          'email' => array(
    //              array('not_empty'),
    //              array('email'),
    //              array(array($this, 'unique'), array('email', ':value')),
    //          ),
            );
        }
    

    Need help to how to login to newly created account and not existing de-activated account.

  • You can keep all those rules, and just change the 'unique' rule for 'username' to something like array(array($this, 'username_available'), array(':value')), (And don't change the module's User.php file, but create your own APPPATH/classes/Model/User.php that extends Model_Auth_User).

    The username_available callback in the rule could look like:

    public function username_available($username)
    {
        $find = array(
            'is_deactivated' => 0,
            'username' => $username,
        );
        $user = ORM::factory($this->object_name(), $find);
        return (! $user->loaded() OR $user->id == $this->id);
    }
    

    Similarly for email.

    And there are the unique keys in the DB schema to change.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion