Hi, look at the Bakery source code:

https://cakeforge.org/projects/bakery/

You have to create an account to browse SVN repository here:
https://svn.cakeforge.org/svn/bakery/ (you can do it with your web
browser)

In https://svn.cakeforge.org/svn/bakery/branches/plugins/users/controllers/
you have an users controller with everything you need.

In short reply to your question:
you can create three fields in db
email_token - you store the activation key
email_token_expires - how long the activation key should be valid
email_confirmed - the user successfully confirmed an email

In verify action you have to search for the activation key in db,
check if user still can validate an email and set email_confirmed to
true, email_token and email_token_expires to null on success.

the  rest you can read from bakery source code :)

On Jun 20, 12:18 pm, Tomfox Wiranata <tomfox.wiran...@gmail.com>
wrote:
> dear community,
>
> this is my first post and i am happy to finally finding a big cake
> community :)
>
> well i am a total newbie  and i started coding the registration. it
> works fine. even the sending email process works. but: i cant get the
> activation link together and the function that is necessary to
> actually activate the user: now this is my controller:
>
> [CODE]
> <?php
> class UsersController extends AppController
> {
>     var $name = 'Users';
>     var $components = array('Auth', 'Recaptcha', 'Email');
>
>     function beforeFilter()
>     {
>
>         $this->Recaptcha->publickey = "xxx";
>            $this->Recaptcha->privatekey = "xxx";
>         $this->Auth->fields = array('username' => 'nickname',
> 'password' => 'password');
>         $this->Auth->allow('register', 'recaptcha', 'thankyou');
>     }
>
>     function register()
>     {
>         if ( !empty( $this->data ) ){
>              if ($this->data['User']['password'] ==
>                  $this->Auth->password($this->data['User']
> ['password_confirm'])) {
>                     if($this->Recaptcha->valid($this->params['form']))
> {
>
>                         $this->User->create();
>                         if ( $this->User->save($this->data) ){
>
>                          #$this->__sendActivationEmail($this->User-
>
> >getLastInsertID());
>
>                         }
>                     } else {
>                         $this->Session->setFlash('Captcha
> Verifizierung fehlgeschlagen');
>                     }
>             } else {
>                 $this->Session->setFlash('Deine Passwörter stimmen
> nicht überein');
>             }
>         }
>     }
>
>       function __sendActivationEmail($id)
>       {
>
>              $this->Email->smtpOptions = array(
>               'port'=>'25',
>               'timeout'=>'30',
>               'host' => '127.0.0.1',
>               'username'=>'xxx',
>               'password'=>'xxx',
>               'client' => 'xxx'
>               );
>
>           $User = $this->User->read(null,$id);
>           $this->Email->to = $User['User']['email'];
>           $this->Email->subject = 'Herzlich willkommen bei test';
>          $this->Email->from = 'nore...@test.com';
>           $this->Email->sendAs = 'html';
>           //$this->Email->template = 'user_confirm';
>           $this->set('User', $User);
>           $this->Email->send();
>       }
>
> }
>
> ?>
> [/CODE]
>
> and this is the model:
> [CODE]
> <?php
> class User extends AppModel
> {
>     var $name = 'User';
>     var $validate = array
>     (
>     'nickname' => array(
>             'exists' => array(
>                     'rule' => array( 'checkUnique', 'nickname' ),
>                     'message' => 'Der Benutzername ist bereits
> vergeben.'
>             ),
>             'minLength' => array(
>                     'rule' => array('minLength', 3),
>                     'message' => 'Der Benutzername muss mind. 3
> Zeichen lang sein.'
>             )
>         ),
>
>         'email' => array (
>             'email' => array(
>                 'rule' => 'email',
>                 'message' => 'Die E-Mail-Adresse ist ungültig.'
>             ),
>             'exists' => array(
>                  'rule' => array( 'checkUnique', 'email' ),
>                  'message' => 'Die E-Mail-Adresse ist bereits
> registriert.'
>             )
>         ),
>
>         'password' => array(
>             'mingLength' => array(
>                 'rule' => array('minLength', '6'),
>                 'message' => 'Das Passwort muss mind. 6 Zeichen lang
> sein.'
>             )
>         ),
>     );
>
>     function checkUnique( $data, $fieldName ) {
>         $valid = false;
>         if(isset($fieldName) && $this->hasField($fieldName)) {
>             $valid = $this->isUnique(array($fieldName => $data));
>         }
>         return $valid;
>     }
>
> }
>
> ?>
> [/CODE]
>
> i know that i need a logic to create a unique activation key and put
> it into the link (preferably in the function sendActivationEmail()).
> also i need a function within the controller to activate the user
> after he clicked the link.
>
> do i need an extra field in my table? i created an attribute
> activation_key in my DB.
>
> well i tried lots of things. i got tons of errors and i need a fresh
> start before i go nuts :)
>
> you have any ideas how i would do that based on my code?
>
> i am looking forward to your help an appreciate it. thanks

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to