Skip to content
Permalink
Browse files

Revert "Add and remove subscribe"

This reverts commit 82a0a95.
  • Loading branch information...
duythien committed Dec 20, 2017
1 parent 511c9d6 commit 3c16ab61771d83e12a0e74db41e2c42b28fb62ea
@@ -12,9 +12,8 @@
*/
namespace Phanbook\Models;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Email as EmailValidator;
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator;
use Phalcon\Mvc\Model\Validator\Email as Email;
use Phalcon\Mvc\Model\Validator\Uniqueness as Uniqueness;
/**
* To use for subscribe weekly post
@@ -118,21 +117,25 @@ public function getStatus()
public function validation()
{
$validator = new Validation();
$validator->add(
'email',
new EmailValidator([
'model' => $this,
'message' => 'Please enter a correct email address'
])
$this->validate(
new Email(
array(
'field' => 'email',
'required' => true,
)
)
);
$validator->add(
'email',
new UniquenessValidator([
'model' => $this,
'message' => 'Another user with same email already exists'
])
$this->validate(
new Uniqueness(
array(
'field' => 'email'
)
)
);
if ($this->validationHasFailed() == true) {
return false;
}
}
/**

This file was deleted.

Oops, something went wrong.
@@ -111,53 +111,17 @@ public function weeklyAction()
$this->flashSession->error(t('Please input your Email'));
return $this->indexRedirect();
}
$subscribe = Subscribe::findFirstByEmail($email);
if (!$subscribe) {
$subscribe = new Subscribe();
$subscribe->setEmail($email);
}
$subscribe = new Subscribe();
$subscribe->setStatus('Y');
$subscribe->setEmail($email);
if (!$subscribe->save()) {
foreach ($subscribe->getMessages() as $message) {
$this->flashSession->error($message);
return $this->indexRedirect();
}
}
$name = $this->config->application->name;
$link = ($this->request->isSecure()
? 'https://' : 'http://') . $this->request->getHttpHost();
$params = [
'link' => $link,
'unLink' => $link . '/subscribe/remove?email=' . urlencode($this->crypt->encryptBase64(trim($email))),
'name' => $name,
'subject' => 'Please confirm your subscription for ' . $name
];
$this->mail->send($email, 'subscribe', $params);
$this->flashSession->success(t('Thank you for subscribing to our newsletter'));
return $this->currentRedirect();
}
public function removeAction()
{
$email = $this->request->get('email');
$email = $this->crypt->decryptBase64(urldecode($email));
$subscribe = Subscribe::findFirstByEmail($email);
if (!$subscribe) {
$this->flashSession->error(t('The email have not exits!'));
return $this->indexRedirect();
}
$subscribe->setStatus('N');
if (!$subscribe->save()) {
foreach ($subscribe->getMessages() as $message) {
$this->flashSession->error($message);
return $this->indexRedirect();
}
}
$this->flashSession->success(t('Unsubscribe Successful'));
return $this->indexRedirect();
}
}

0 comments on commit 3c16ab6

Please sign in to comment.
You can’t perform that action at this time.