public function register() { $user = $this->Users->newEntity(); if ($this->request->is('post')) { if ($this->Recaptcha->verify()) { $email = $this->request->data('email'); $email = trim($email); $email = strtolower($email); $this->request->data['email'] = $email; $this->request->data['password'] = $this->request->data('new_password'); $this->request->data['role'] = 'user'; $user = $this->Users->patchEntity($user, $this->request->data(), ['fieldList' => ['name', 'email', 'password', 'role']]); $errors = $user->errors(); if (empty($errors)) { $user = $this->Users->save($user); if ($this->request->data('mailing_list')) { MailingList::addToList($user); } $this->Flash->success('Your account has been registered. You may now log in.'); return $this->redirect(['action' => 'login']); } else { $this->Flash->error('There was an error registering your account. Please try again.'); } } else { $this->Flash->error('There was an error verifying your reCAPTCHA response. Please try again.'); } } else { $this->request->data['mailing_list'] = true; } /* So the password fields aren't filled out automatically when the user * is bounced back to the page by a validation error */ $this->request->data['new_password'] = null; $this->request->data['confirm_password'] = null; $this->set(['pageTitle' => 'Register an Account', 'user' => $user]); }
/** * Returns TRUE if an email address is subscribed * to the MailChimp mailing list * * @param string $email * @return boolean */ public static function isSubscribed($email) { $MailChimp = MailingList::getMailChimpObject(); $listId = Configure::read('mailChimpListId'); $subscriberHash = $MailChimp->subscriberHash($email); $response = $MailChimp->get("lists/{$listId}/members/{$subscriberHash}"); return isset($response['status']) && $response['status'] != 404; }