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
No comments:
Post a Comment