Password Recovery: To Use Model Or Not?

Hi there,

I’m making a password recovery system and I’m a little stuck as to how to proceed.

I’m going to do the usual of creating a validation code that gets emailed etc etc.

My problem is how to create the password recovery form (where they enter the email)?

Should I use a model?

I want to take advantage of Yii’s validation rules so I was thinking of creating an action In UserController, something like:


public function actionForgotPassword()

	{

                $model = new User;

		$model->scenario = 'forgotPassword';

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

		{

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

			//send email, do other stuff here

		}


		$this->render('forgotPassword',array(

			'model'=>$model,

		));

	}

Is this a viable way of doing this?

It somehow seems wrong that I’m creating a new User model instance.

Thanks in advance.

Take a look at my usr module. I tried to write it as cleanly as possible, so I hope it will be easy to read for you.

In the default controller there is a separate action and a view for password recovery. I use a sperate form model to avoid populating other form models with attributes that are rarely used. The same action is used to send the email and to set a new password.

Thanks a lot, I’ll take a good look through.