چگونه یک فرم لاگین ایجاد کنیم؟؟؟؟

[right]با سلام خدمت دوستان عزیز

من تازه یی رُ شروع کردم

میخوام فرم لاگین ایجاد کنم ولی و احراز هویت انجام بدم ولی نمیدونم از کجا شروع کنم؟

راهنمایی لطفا[/right]

https://www.google.fr/search?client=ubuntu&channel=fs&q=user+authentication+yii&ie=utf-8&oe=utf-8&gws_rd=cr&ei=pbYRU-7rNeeV7AbexYDYBA

سلام

فروم معمولا آخرین راهه

من تمام این سرچ ها رُ انجام.

اگه میشه کنترلر و مدل رُ بهم نشون بدبد…نمونه کد

خیلی ممنون دوست عزیز

[right]آقا این ارور رُ دارم

اینم کدام[/right]

Fatal error: Call to undefined method User::model() in C:\xampp\htdocs\pro_c\protected\components\UserIdentity.php on line 47

UserIdentity.php




<?php

class UserIdentity extends CUserIdentity 

{


	public function authenticate()

	{

		//$users=array(

			// username => password

			//'demo'=>'demo',

			//'admin'=>'admin',

			//'j'=>'j',

	//	);

                                       

 $users = User::model()->findByAttributes(array('username'=>$this->username));

 //print_r($users);


		if(!isset($users[$this->username]))

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		elseif($users[$this->username]!==$this->password)

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		else

			$this->errorCode=self::ERROR_NONE;

		return !$this->errorCode;

	}

}


?>



UserController.php




<?php


class UserController extends Controller

{


	public function actionIndex()

	{

		// renders the view file 'protected/views/site/index.php'

		// using the default layout 'protected/views/layouts/main.php'

		$this->render('index');

	}




	public function actionLogin()

	{

		$model=new User;




		if(isset($_POST['User']))

		{

			$model->attributes=$_POST['User'];

			// validate user input and redirect to the previous page if valid

			if($model->validate() && $model->login())

				$this->redirect(Yii::app()->user->returnUrl);

		}

		// display the login form

		$this->render('login',array('model'=>$model));

	}




	public function actionLogout()

	{

		Yii::app()->user->logout();

		$this->redirect(Yii::app()->homeUrl);

	}

}

?>



User.php




<?php


/**

 * LoginForm class.

 * LoginForm is the data structure for keeping

 * user login form data. It is used by the 'login' action of 'SiteController'.

 */

class User extends CFormModel

{

	public $username;

	public $password;

	public $rememberMe;


	private $_identity;


	/**

	 * Declares the validation rules.

	 * The rules state that username and password are required,

	 * and password needs to be authenticated.

	 */

	public function rules()

	{

		return array(

			// username and password are required

			array('username, password', 'required'),

			// rememberMe needs to be a boolean

			array('rememberMe', 'boolean'),

			// password needs to be authenticated

			array('password', 'authenticate'),

		);

	}


	/**

	 * Declares attribute labels.

	 */

	public function attributeLabels()

	{

		return array(

			'rememberMe'=>'Remember me next time',

		);

	}


	/**

	 * Authenticates the password.

	 * This is the 'authenticate' validator as declared in rules().

	 */

	public function authenticate($attribute,$params)

	{

		if(!$this->hasErrors())

		{

			$this->_identity=new UserIdentity($this->username,$this->password);

			if(!$this->_identity->authenticate())

				$this->addError('password','Incorrect username or password.');

		}

	}


	/**

	 * Logs in the user using the given username and password in the model.

	 * @return boolean whether login is successful

	 */

	public function login()

	{

		if($this->_identity===null)

		{

			$this->_identity=new UserIdentity($this->username,$this->password);

			$this->_identity->authenticate();

		}

		if($this->_identity->errorCode===UserIdentity::ERROR_NONE)

		{

			$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days

			Yii::app()->user->login($this->_identity,$duration);

			return true;

		}

		else

			return false;

	}

}




[right][rtl][font="Tahoma"]

سلام

کلاس user شما باید از ActiveRecord ارث بری کنه نه FormModel

یعنی باید یک جدول برای کاربران توی دیتابیس داشته باشید و براش مدل بسازید

برای ساختن مدل هم که gii هست و میتونید استفاده کنید

ضمنا کلاس user فعلی رو هم اسمش رو عوض کنید که با کلاس user که جدید میسازید قاطی نشه، همون اسم پیش فرضش که فکر کنم LoginForm هست خوبه

[/font][/rtl][/right]