abramsen
abramsen

Reputation: 65

how to get password using Yii::app()->User

I want to know why when I use var_dump(Yii::app()->User->id);

I get the id number,

and when i use var_dump(Yii::app()->User->password);

I get the following error:

CException CAssetManager.basePath "/opt/local/www/projects/theuniversalgroup/app/webim/operator/assets" is invalid. Please make sure the directory exists and is writable by the Web server process.

Also how can I get the password of the user so i can use it to log in into the web app.

Upvotes: 0

Views: 1752

Answers (3)

Neeraj Prajapati
Neeraj Prajapati

Reputation: 541

If you want to get user password using interface

var_dump(Yii::app()->user->password);

use this method, then you need add in your base component file UserIdentity.php

common/components/base/UserIdentity.php 


   public function getId() {
        return $this->id;
    }


    public function getName() {
        return $this->username;
    }




   public function getPassword() {
        return $this->password;
    }

after this change you will be able to use password using the method:

var_dump(Yii::app()->user->password);

Upvotes: 1

StreetCoder
StreetCoder

Reputation: 10061

When submit the login form, model LoginForm.php [protected/models/LoginForm.php] instantiate the UseIdentity.php [protected/components/SiteController.php] class to check user and password. If login info is correct, UseIdentity class saves the user id.

Please check the following files:

  • login.php [protected/views/login.php]
  • LoginForm.php [protected/models/LoginForm.php]
  • SiteController.php [protected/controllers/SiteController.php]
  • UseIdentity.php [protected/components/SiteController.php]

So you find the logged in user id when you try as var_dump(Yii::app()->User->id);. I answered earlier in you another post that how to get the password. If you would like to save the password as user id you should use $this->setState(); method in UserIdentity class. there are many ways to get or hold the password.

Upvotes: 0

Gunnit
Gunnit

Reputation: 1074

if my understanding is correct you are trying to create a login for your app in that case you can use something like this to log into you app , this is how i set up my userIdentity.php ;

    class UserIdentity extends CUserIdentity
{
        private $_id;


    public function authenticate()
    {
            $username = strtolower($this->username);
            $user = User::model()->find('LOWER(user_name)=?',array($username));
            if($user===null)
                    $this->errorCode=self::ERROR_USERNAME_INVALID;
            else if(!$user->validatePassword($this->password))
                    $this->errorCode=self::ERROR_PASSWORD_INVALID;
            else{
                $this->_id = $user->id_user;
                $this->username=$user->user_name;
                $this->errorCode=self::ERROR_NONE;
                $user->updateLoginDate();
            }
            return $this->errorCode==self::ERROR_NONE;
    }

        public function getId()
        {
            return $this->_id;
        }
}

Upvotes: 0

Related Questions