My two cents:

Action in the controller:

function changePassword() {
                if (!empty($this->data)) {
                        $this->User->recursive = -1;
                        $user = $this->User->findById($this->Auth->User('id'));
                        
if($this->Auth->password($this->data['User']['old_password']) ==
$user['User']['password']) {
                                $this->data['User']['password']= 
$this->Auth->password($this-
>data['User']['password']);
                                if ($this->User->save($this->data)) {
                                        $this->Session->setFlash(__('Password 
reseted.', true));
                                        
$this->redirect(array('action'=>'view'));
                                } else {
                                        $this->Session->setFlash(__('Password 
not reseted', true));
                                }
                        }
                        else
                                $this->Session->setFlash(__('The old password 
is not right. Please
write it again.', true));
                }

                if (isset($this->data['User']['password']))
                        unset($this->data['User']['password']);
                if (isset($this->data['User']['password_confirm']))
                        unset($this->data['User']['password_confirm']);
                if (isset($this->data['User']['old_password']))
                        unset($this->data['User']['old_password']);
        }

And in my view I have three fields, old_password, password, and
repeat_password. The validation of equality between password and
repeat_password is done in the model.

Cheers,
mbavio

On May 3, 1:59 am, damo <[EMAIL PROTECTED]> wrote:
> Trying to write a controller to change the password.  The only guide I
> have found to do this is at the 
> following:http://groups.google.com/group/cake-php/browse_thread/thread/83359000...
>
> However this appears to be using cake 1.x (because of the html helper
> being used for a form).
>
> When using this controller I get this
> Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /var/www/
> cake/app/controllers/users_controller.php on line 68
>
> This is at the 'if($this->data['change']['newpassword'] !=.....' line.
>
> Here is the code I am trying.  Let me know if there is a better way to
> do this in Cake 2.
>
> Cheers,
> Damo
>
>     function changepassword()
>     {
>       if (!empty($this->data)) {
>         $user = $this->Session->read('User');
>          $this->User->id = $user['id'];
>          $someone = $this->User->findById($this->User->id);
>                 if(md5($this->data['change']['oldpassword']) !=
> $someone['User']['password']) {
>                 $this->User->invalidate('oldpassword', 'Your old password
> is invalid');
>                 }
>             if($this->data['change']['newpassword'] != 
> this->data['change']['confirmpassword']){
>
>                         $this->User->invalidate('newpassword', 'Your
> passwords do not match');
>                         $this->User->invalidate('confirmpassword',
> 'Your passwords do not match');}
>                         else {
>                                 $encryptedPassword = md5($this->data['change']
> ['newpassword']);
>                              $this->data['User']['password'] =
> $encryptedPassword;
>                           $this->data['User']['id'] = $this->User->id;
>                        }
>                    if ($this->User->save($this->data)){
>                    $this->flash('Password updated, please login again.','/
> users/logoutnf');
>                } else {
>                   $this->render();
>                }
>         }
>     }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to