public function execute() { // Задаём лайаут для фронтенда $this->setLayout(new guestbook2FrontendLayout()); // Получаем hash из GET параметров $hash = waRequest::get('hash'); // Проверяем хэш if (!$hash || strlen($hash) < 33) { $this->redirect(wa()->getRouteUrl('/frontend')); } // Получаем contact_id из хэша $contact_id = substr($hash, 16, -16); $hash = substr($hash, 0, 16) . substr($hash, -16); $contact = new waContact($contact_id); // Проверяем валидность хэша if ($contact->getSettings($this->getAppId(), 'confirm_hash') === $hash) { // Удаляем хэш $contact->delSettings($this->getAppId(), 'confirm_hash'); // Выставляем статус confirmed для email-адреса контакта $contact['email'] = array('value' => $contact->get('email', 'default'), 'status' => 'confirmed'); // Сохраняем контакт $contact->save(); } else { // Если хэш неправильный, то просто редирект на главную страницу $this->redirect(wa()->getRouteUrl('/frontend')); } }
public function execute() { // Setting the frontend layout // Задаём лайаут для фронтенда $this->setLayout(new guestbook2FrontendLayout()); // Retrieving hash from the GET request // Получаем hash из GET параметров $hash = waRequest::get('hash'); // Verifying hash // Проверяем хэш if (!$hash || strlen($hash) < 33) { $this->redirect(wa()->getRouteUrl('/frontend')); } // Retrieving contact_id from the hash // Получаем contact_id из хэша $contact_id = substr($hash, 16, -16); $hash = substr($hash, 0, 16) . substr($hash, -16); $contact = new waContact($contact_id); // Validating hash // Проверяем валидность хэша if ($contact->getSettings($this->getAppId(), 'confirm_hash') === $hash) { // Deleting hash // Удаляем хэш $contact->delSettings($this->getAppId(), 'confirm_hash'); // Setting "confirmed" status to the contact's email address // Выставляем статус confirmed для email-адреса контакта $contact['email'] = array('value' => $contact->get('email', 'default'), 'status' => 'confirmed'); // Saving contact // Сохраняем контакт $contact->save(); } else { // If the hash is incorrect then simply redirect to the home page // Если хэш неправильный, то просто редирект на главную страницу $this->redirect(wa()->getRouteUrl('/frontend')); } }
/** * @param $confirmation_hash * @param array $errors * @return bool|waContact */ protected function confirmEmail($confirmation_hash, &$errors = array()) { $email_id = substr(substr($confirmation_hash, 16), 0, -16); $confirmation_hash = substr($confirmation_hash, 0, 16) . substr($confirmation_hash, -16); $ce = new waContactEmailsModel(); $contact_email = $ce->getById($email_id); $contact = new waContact($contact_email['contact_id']); $user_confirm_hash = $contact->getSettings(wa()->getApp(), "email_confirmation_hash", false); if ($user_confirm_hash && $confirmation_hash === $user_confirm_hash) { // try auth new contact try { if (wa()->getAuth()->auth($contact)) { $ce->updateById($email_id, array('status' => 'confirmed')); $contact->delSettings(wa()->getApp(), "email_confirmation_hash"); } } catch (waException $e) { $errors = array('auth' => $e->getMessage()); } return $contact; } return false; }