Yii Framework Forum: Where Does Yii Store The User In Sample Web Apps - Yii Framework Forum

Jump to content

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

Where Does Yii Store The User In Sample Web Apps Rate Topic: -----

#1 User is offline   jack1234 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-March 13

Posted 21 March 2013 - 10:33 PM

In the sample application created using yiic, yii has two users demo/demo and admin/admin, where does yii stored the user information? what if i wish to add more users and I would want to add it to the database myDB of table myUser, which contains two fields, user name and password?
0

#2 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 232
  • Joined: 15-August 12

Posted 22 March 2013 - 12:25 AM

../protected/components/UserIdentity.php

<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
	/**
	 * 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;
	}
}


Edit:
In this way user/pass have saved within an array, for real applications you have to deal with database or other resource.
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