public function beforeSave($created = false) {
}
Inside the method, $created will be true if the record was created and false if it's being updated... but this wouldn't work if you want to change the user password (since it's an update).
Regards,
--
Thiago Belem
Desenvolvedor
Rio de Janeiro - RJ - Brasil
-- Thiago Belem
Desenvolvedor
Rio de Janeiro - RJ - Brasil
Assando Sites - Curso online de CakePHP
assando-sites.com.br
thiagobelem.net
contato@thiagobelem.net
Skype / gTalk » thiago.belem.web
LinkedIn » br.linkedin.com/in/thiagobelem/pt
thiagobelem.net
contato@thiagobelem.net
Skype / gTalk » thiago.belem.web
LinkedIn » br.linkedin.com/in/thiagobelem/pt
On Sun, Apr 29, 2012 at 16:39, Charles Blackwell <charlesblackwell412@gmail.com> wrote:
I was trying to use $created because I saw it in book. I didn't know if it was a model property or not. That didn't work and I had a brain freeze, lol.
On Sunday, April 29, 2012 3:30:30 PM UTC-4, MaJerle.Eu wrote:--only PHP basics :)public function beforeSave(){if (isset($this->data['User']['password'])) {$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);}return true;}--Lep pozdrav, Tilen Majerle
2012/4/29 Charles Blackwell <charlesblackwell412@gmail.com>This works but, is there a way to NOT has the password when the confirm method is called? Also, in your opinion is beforeSave a good way to hash the password?
Thanks!
<?php class User extends AppModel { public $name = 'User'; public function beforeSave() { $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); return true; } <?php App::uses('CakeEmail', 'Network/Email'); class UsersController extends AppController { public $name = 'Users'; function beforeFilter(){ $this->Auth->allow('signup', 'confirm'); } function signup(){ $this->request->data['User']['confirm_code'] = String::uuid(); $this->User->create(); if($this->User->save($this->request->data)){ $email = new CakeEmail(); $email->template('welcome', 'default') ->emailFormat('html') 'id' => $this->User->getLastInsertID(), 'username' => $this->request->data['User']['username'], 'email' => $this->request->data['User']['email'], 'server' => $_SERVER['SERVER_NAME'], 'code' => $this->request->data['User']['confirm_code'] )) ->to($this->request->data['User']['email']) ->subject('Welcome!'); if($email->send()){ $this->Session->setFlash('Congratulations! You have signed up!'); } } else { $this->Session->setFlash('There was an error signing up. Please, try again.'); $this->request->data = null; } } } function confirm($user_id=null, $code=null){ $this->set('confirmed', 0); $this-render(); } $user = $this->User->read(null, $user_id); $this->set('confirmed', 0); $this->render(); } if($user['User']['confirm_code'] == $code){ $this->User->id = $user_id; $this->User->saveField('confirmed', '1'); $this->set('confirmed', 1); } else { $this->set('confirmed', 0); } }
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment