Yii Framework Forum: Update form managing - Yii Framework Forum

Jump to content

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

Update form managing Rate Topic: -----

#1 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 28 April 2010 - 03:10 AM

Hello!

i'm quite new to Yii... so this can be quite a stupid question.

I have a user moel that saves on my db sha1 versions of passwords. i'd like my users to be able to set a new password when updating their user profile... how could i prevent the password field to be already completed on the update form?

thanks a lot

joey
joey santiago

an Italian with Suomi inside.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 April 2010 - 03:29 AM

in actionUpdate after $model= new User;
add $model->password='';
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 28 April 2010 - 03:41 AM

thanks for the suggestion!! :)

i thought not to display the password field in the update form and i'd like to create a new action for the model: newpassword.

So, in UsersController i added an action:

	public function actionNewpassword()
	{
		$model=$this->loadModel();

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['BoUsers']))
		{
                        if($model->password == sha1($_POST['BoUsers']['password']));
			$model->attributes=$_POST['BoUsers'];
                        $model->password = sha1($model->password);
			if($model->save())
				$this->redirect(array('view','id'=>$model->idBOUsers));
		}

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


i thought that $this->render would have called the file newpassword.php in views folder... but i got an error 404... what's the matter?

thanks!
joey santiago

an Italian with Suomi inside.
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 April 2010 - 04:04 AM

It should... if the model is BoUsers than the view files should be in /protected/views/boUsers

but I tryed to request a nonexistent view and

I'm getting error 500 UserController cannot find the requested view "updatexy", and you got the 404 - don't know why
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 28 April 2010 - 04:53 AM

View Postmdomba, on 28 April 2010 - 04:04 AM, said:

It should... if the model is BoUsers than the view files should be in /protected/views/boUsers

but I tryed to request a nonexistent view and

I'm getting error 500 UserController cannot find the requested view "updatexy", and you got the 404 - don't know why


thanks!!

i got it! :)

i was calling the link without passing an id to it... now it goes!
joey santiago

an Italian with Suomi inside.
0

#6 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 28 April 2010 - 08:14 AM

mhm... i'm still having problems...

i added a field newpassword to the BoUsers class, then my _formpass.php looks like this:
<div class="row">
		<?php echo $form->labelEx($model,'password'); ?>
		<?php echo $form->passwordField(BoUsers::model(),'password',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'password'); ?>
	</div>

        <div class="row">
		<?php echo $form->labelEx($model,'newpassword'); ?>
		<?php echo $form->passwordField(BoUsers::model(),'newpassword',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'newpassword'); ?>
	</div>

and my actionNewpassword is:
public function actionNewpassword()
	{
		$model=$this->loadModel();

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['BoUsers']))
		{
                        if($model->validatePassword(sha1($_POST['BoUsers']['password']))){
                            $model->attributes=$_POST['BoUsers'];
                            echo $_POST['BoUsers']['newpassword'];
                            $model->password = sha1($model->newpassword);
                            if($model->save())
                                    $this->redirect(array('view','id'=>$model->idBOUsers));
                        }
                        else $model->addError('password','The password provided is incorrect!');
		}

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

. i also added a rule in the model:
array('newpassword','required','on'=>'newpassword', 'message'=>'hey, guy... set a password!'),

expecting my newpassword field to be required in the form, but it's not. Does anyone know why?

... nothing works at the moment :(
joey santiago

an Italian with Suomi inside.
0

#7 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 April 2010 - 08:23 AM

try to remove 'on'=>'newpassword', this is for scenario not for action...
Find more about me.... btw. Do you know your WAN IP?
0

#8 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 28 April 2010 - 08:33 AM

but this way the newpassword field is required also on creation form...

Should i build a new scenario, then? i'll try that :)
joey santiago

an Italian with Suomi inside.
0

#9 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 April 2010 - 08:37 AM

Didn't use that yet.... try to set scenario... 'on'=>'update'
Find more about me.... btw. Do you know your WAN IP?
0

#10 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 28 April 2010 - 08:52 AM

wow, it works!!

thanks a lot! :)
joey santiago

an Italian with Suomi inside.
0

#11 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 28 April 2010 - 11:09 AM

d'oh!!
this way it asks me for a value for newpassword in the update action too... i think i should try setting up a newpassword scenario. i'll try that out. thanks a lot!
joey santiago

an Italian with Suomi inside.
0

#12 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 29 April 2010 - 03:26 AM

it works with scenario...

here's the code!
the function actionNewpassword sets the scenario:
public function actionNewpassword()
	{
		$model=$this->loadModel();
                $model->setScenario("newpwd");
		// Uncomment the following line if AJAX validation is needed
		//$this->performAjaxValidation($model);

		if(isset($_POST['BoUsers']))
		{
                        if($model->validatePassword(sha1($_POST['BoUsers']['password']))){
                            $model->attributes=$_POST['BoUsers'];
                            $model->newpassword=$_POST['BoUsers']['newpassword'];
                            if($model->validate()){
                                $model->password = sha1($model->newpassword);
                            }
                            if($model->save()){
                                $this->redirect(array('view','id'=>$model->idBOUsers));
                            }
                        }
                        else $model->addError('password','The password provided is incorrect!');
		}

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

and this is the rule:
array('newpassword','required','on'=>'newpwd', 'message'=>'you must set a new password!'),

joey santiago

an Italian with Suomi inside.
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