Yii Framework Forum: Login Button Instead Logout In Menu - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Login Button Instead Logout In Menu A problem with login in chapter 7

#1 User is offline   leonias 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 15-February 13

Posted 15 February 2013 - 04:47 PM

I have a problem in chapter 7 code, when changing UserIdentity class code, particularly when i define private $_id and public function getId as is shown in page 165. I don't know if the application is still doing the login properly, but the button for login is shown in menu instead logout(demo) or logout(admin). Thanks in advance to the person which helps me to understand this behavior. I leave the code for UserIdentity.php (i don't know if is going to be enough).

class UserIdentity extends CUserIdentity
{

        private $_id;

        /**
         * Authenticates a user.
         * The example implementation makes sure if the username and password
         * are both 'demo'.
         * In practical applications, this should be changed to authenticate
         * against some persistent user identity storage (e.g. database).
         * @return boolean whether authentication succeeds.
         */
        public function authenticate()
        {
                $users=array(
                        // username => password
                        'demo'=>'demo',
                        'admin'=>'admin',
                );
                if(!isset($users[$this->username]))
                        $this->errorCode=self::ERROR_USERNAME_INVALID;
                else if($users[$this->username]!==$this->password)
                        $this->errorCode=self::ERROR_PASSWORD_INVALID;
                else
                        $this->errorCode=self::ERROR_NONE;
                return !$this->errorCode;
        }
  

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



I know that i'm not using the function getID or _id, but to me it seems that Logout button have to work the same way, but it doesn't.
0

#2 User is offline   Reza m 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 07-March 12

Posted 15 February 2013 - 05:11 PM

you have to modify authenticate function based on this part of the book, take a look at that page again
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users