/** * Logs user in after registration. * @param boolean $insert * @param array $changedAttributes */ public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if ($this->isActive()) { $loginForm = new LoginForm(['username' => $this->username]); $loginForm->login(false); } }
protected function afterSave() { $theme = 'Добро пожаловать на "' . Yii::app()->getRequest()->getServerName() . '"!'; $link = CHtml::link('Активировать учетную запись', Yii::app()->getRequest()->getBaseUrl(true) . '/user/' . $this->id . '/activate?key=' . $this->activationKey); $msg = 'Вы зарегистрировались на сайте "' . Yii::app()->name . '". ' . $link; mail($this->email, $theme, $msg); return parent::afterSave(); }
} } } User::setOrder("name"); User::validates("name", array("presence" => true)); User::validates("name", array("format" => "^[\\p{L},]{2,} [\\p{L}\\s\\.]{2,}")); User::validates("email", array("presence" => true)); User::validates("email", array("format" => "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})\$")); User::validates("email", array("uniqueness" => true, "allow_null" => true, "allow_blank" => true)); User::validates("user_level", array("numericality" => true)); User::validates("code", array("format" => "^[0-9]{5}\$", "allow_null" => true)); User::hasMany("tickets", array("class_name" => "Ticket")); User::hasOne("account"); User::beforeSave("before_save"); User::beforeSave("strip_invalid"); User::afterSave("after_save"); User::beforeDestroy("before_destroy"); User::afterDestroy("after_destroy"); User::beforeCreate("before_create"); User::afterCreate("after_create"); User::beforeUpdate("before_update"); User::afterUpdate("after_update"); User::scope("first_level", array("user_level" => 1)); User::scope("by_level", function ($args) { return "user_level=" . $args[0]; }); User::scope("by_level_and_date", function ($args) { return "user_level=" . $args[0] . " and created_at<'" . $args[1] . " 23:59:59'"; }); User::scope("doe", "email like '%doe.com'"); User::scope("email_first", function ($args) {
public function afterSave() { parent::afterSave(); //Register to MailChimp on signup Yii::import('application.external.*'); if ($this->scenario == 'register' && isset($_POST['subscribe'])) { $MailChimp = new MailChimp(SnapUtil::config('boxomatic/mailChimpApiKey')); $result = $MailChimp->call('lists/subscribe', array('id' => SnapUtil::config('boxomatic/mailChimpListId'), 'email' => array('email' => $this->email), 'merge_vars' => array('MERGE2' => $this->full_name), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false)); if ($result === false) { // response wasn't even json } else { if (isset($result->status) && $result->status == 'error') { // Error info: $result->status, $result->code, $result->name, $result->error Yii::log('Error subscribing user ' . $this->id . ': ' . print_r($result, true), 'error', 'system.web.CActiveRecord'); } } } }