I manage to create the model,view and controller or the "new user" creation but I want this form to be edited only by users that are "log on".
How can I do that? the code
class RegisterForm extends CFormModel {
public $m_sUserName;
public $m_sPassword;
public $m_sPassword_repeat;
public $m_sEmailAddress;
public $m_sFirstName;
public function rules()
{
return array(
array( 'm_sUserName, m_sPassword, m_sEmailAddress, m_sFirstName,m_sPassword_repeat', 'required' ),
array( ' m_sEmailAddress', 'email' ),
array( 'm_sPassword', 'compare' ),
array( 'm_sUserName', 'register' ),
);
}
public function attributeLabels()
{
return(
array(
'm_sPassword' => 'Password',
'm_sPassword_repeat' => 'Retype Your Password',
)
);
}
public function register()
{
if ( ! $this->hasErrors() )
{
$_dbc = new CDbCriteria;
$_dbc->select = 'user_nick';
$_dbc->condition = 'user_nick = :user_name_text';
$_dbc->params = array( ':user_name_text' => $this->m_sUserName );
$_oUser = Users::model()->find( $_dbc );
if ( null == $_oUser )
{
$_oUser = new Users();
$_oUser->user_nick= $this->m_sUserName;
$_oUser->user_password = md5( $this->m_sPassword );
$_oUser->user_name = $this->m_sFirstName;
$_oUser->user_email = $this->m_sEmailAddress;
if ( $_oUser->save() ) {
}
else
{
$this->addError( 'm_sUserName', 'Unable to save new user' );
}
}
else
{
$this->addError( 'm_sUserName', 'The user name you have chosen is already in use' );
}
}
}
}
class UpdateController extends CController {
//put your code here
public function accessRules()
{
return array(
array('allow',
'actions'=>array('create'),
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function actionCreate()
{
$_oForm=new RegisterForm();
if(isset($_POST['RegisterForm']))
{$_oForm->attributes=$_POST['RegisterForm'];
// collects user input data
// $form->attributes=$_POST['LoginForm'];
// validates user input and redirect to previous page if validated
if($_oForm->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
$this->render('create',array('_oForm'=>$_oForm));
}
}