How can I confirm membership registration?

How to register with CakePHP?

After registration, he will send an email to confirm.

If I click on the verification link, the account will be confirmed.

How can i do this?

Is there any function with Auth for this?

Or do I need to send mail manually to confirm the registration?

If I need to send an email manually to confirm the registration, how can I generate a registration token and how to set the time for a valid token?

Can someone show an example of this?

+7
source share
4 answers

Check out the Cake Development Corporations user plugin source, available for CakepPHP 1.3 and 2.0. https://github.com/cakedc/users It already does everything - in the correct order of MVC and CakePHP - which you request. Just use the plugin or grab the code.

+4
source

user table:

CREATE TABLE IF NOT EXISTS `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(255) COLLATE utf8_persian_ci NOT NULL, `password` varchar(255) COLLATE utf8_persian_ci NOT NULL, `email` varchar(100) COLLATE utf8_persian_ci NOT NULL, `created` datetime NOT NULL, `status` tinyint(1) NOT NULL, `activation_code` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci AUTO_INCREMENT=4 ; 

when the user is registered, u can set a unique line (sample: md5 (time ()) or any thing ...) in the activ_code field. now send an email like this url to user:

 http://test/controller/action/activation_code 

Now you need to check the action that this activation identifier is in the user table or not.

and if this is what status = disable or not ....

+3
source

You can easily generate the hash code as a token in PHP and check its duration on TimeStamp. For email, just use an email component like this. If you want to use the Auth component, make sure your form provides the correct password hash.

 function register() { $error = false; $error_captcha = null; if(isset($this->data)){ App::import('Component','Generate'); App::import('Component', 'Converter'); App::import('Component','Email'); if(empty($this->data['User']['password'])||strlen($this->data['User']['password'])<5){ $this->User->invalidate("password"); $error = TRUE; } if($this->data['User']['password']<>$this->data['Temp']['password']){ $this->User->invalidate("seotitle"); $error = TRUE; } $captcha_respuesta = recaptcha_check_answer ($this->captcha_privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($captcha_respuesta->is_valid && !$error) { $this->data['User']['coderegistration'] = $this->generate->getUserCode(); $this->data['User']['displayname'] = $this->data['User']['firstname'] . " " . $this->data['User']['lastname']; $this->data['User']['seotitle'] = $this->converter->seotitle($this->data['User']['username']); $this->data['User']['password'] = md5($this->data['User']['username'].$this->data['User']['password']); $this->User->id = NULL; if($this->User->save($this->data)){ /* ========================= send email notification ========================= */ $email = $this->data['User']['email']; $content = sprintf('<a href="%s/%s">here</div>', $this->url, $this->data['User']['coderegistration']); $this->email->to = $email; $this->email->subject = 'you have been registered, please confirm'; $this->email->replyTo = ' mail@mail.com '; $this->email->from = "name < mail@mail.com >"; $this->email->template = 'notification'; $this->email->sendAs = 'html'; $this->set('value', $content); if($this->email->send()){ // OK }else{ trigger_error("error Mail"); } } }else{ $error_captcha = $captcha_respuesta->error; $this->set('error_email',true); } } $this->setTitlePage(); $this->layout = "home"; $this->set('backurl', '/'); $this->set('posturl',''); $this->set('captcha_publickey',$this->captcha_publickey); } 
+2
source

To send email, also download the email component. The led function of registers is good, and you should go with it.

Basically the concept is to add a user, and then create a token (with timestamp ro any) and save it in the database, and then send an email with a link to this token.

Then, when the user clicks on the token link, you set user = active, and now they are registered and can log into the system.

Good advice for your Auth therefore adds a "scope" (check cakephp docs for version 1.3) to Auth. Make this area a coverage that is active = 1. So they will need to confirm the link by email and will never be able to enter it until it is done. Easy!

+2
source

All Articles