public static function onUniqueEMailValidator($event) { $model = new AccountRegisterForm(); $allowed = EmailWhitelist::toArray(); if (isset($_POST['AccountRegisterForm'])) { $model->attributes = $_POST['AccountRegisterForm']; if ($model->validate()) { // Make sure the address is valid if (filter_var($model->email, FILTER_VALIDATE_EMAIL)) { $domain = strtolower(array_pop(@explode('@', $model->email))); if (!in_array($domain, $allowed)) { // email not whitelisted // empty $_POST['AccountRegisterForm'] so it doesn't submit anything $_POST['AccountRegisterForm'] = null; Yii::app()->request->redirect(Yii::app()->createUrl('//email_whitelist/denied', array())); // TODO // Redirect them to an error page // render the invalid email domain notification // Yii::app()->getController()->widget('application.modules.email_whitelist.widgets.InvalidEmailDomain', array()); // Yii::app()->getController()->widget('application.modules.email_whitelist.widgets.InvalidEmailDomain', array(), true); --> } } } } }
/** * Returns a list of whitelisted domains */ public static function toArray() { $whitelist = array(); foreach (EmailWhitelist::model()->findAll() as $row) { $whitelist[] = strtolower($row['domain']); } return $whitelist; }
/** * Deletes a whitelist record */ public function actionDelete() { $id = (int) Yii::app()->request->getQuery('id'); $doit = (int) Yii::app()->request->getQuery('doit'); $emailWhitelist = EmailWhitelist::model()->resetScope()->findByPk($id); if ($emailWhitelist == null) { throw new CHttpException(404, "Karma record not found"); } if ($doit == 2) { $this->forcePostRequest(); $emailWhitelist->delete(); $this->redirect($this->createUrl('index')); } $this->render('delete', array('model' => $emailWhitelist)); }