Logically Organize Registration

So I’m relatively new to Yii, but enjoy it thus far. I have read several articles/posts on how to implement registration, but none of them seem to answer my question - what’s the best way to do it?

For example, I have two tables - m_password and m_person:

[indent]

m_person:

personID

firstName

lastName

email

m_password:

id

person_id

hashedPassword

salt

[/indent]

I also have a model for Password and Person. My planned implementation was to create a form (class RegisterForm extends CFormModel) as well as an actionRegister method in the SiteController.

Within the SiteController, I was going to pass both models to the view:




public function actionRegister() {

$person = new Person;

$password = new Password;

...

$this->render('register', array('person'=>$person, 'password'=>$password));

}



Here are some question I had about this approach:

1.) Since the Person model is related to the Password via a HAS_ONE relationship, do I even need to create a PasswordController? Is it bad practice to access the password hash exclusively through the PersonController?

2.) Is the SiteController the best place to put generic forms such as Registration and Login?

3.) Is there anything flawed about my intended implementation?

Thanks in advance!

Hi,

IMHO:

  1. You do not need a PasswordController. All the hard stuff should be done in the model.

  2. You can use site controller if you want … But if you plan to have more functionnalities (profile editing for your user, a user search facility …) a specific controller can be more coherent. Or even better, a reusuable module …

  3. well not really … Do you "have to" separate "person" and "password" ?

Thanks for the reply. The reason I have a seperate table for passwords is that the m_person table will have records for people who are not necessarily users of the site.

I figured for all of the person profiles, editing, searching I would simply use the PersonController and Person model.

Understand now.

Did you know that Yii have some built in classes that might help you especially CWebUser ?