Beispiel #1
0
 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['us_created']], 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'password', ActiveRecord::EVENT_BEFORE_UPDATE => 'password'], 'value' => function ($event) {
         /** @var \yii\base\Event $event */
         $model = $event->sender;
         if (!empty($model->password)) {
             $model->setPassword($model->password);
         }
         return $model->password;
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'us_confirmkey'], 'value' => function ($event) {
         /** @var \yii\base\Event $event */
         return Yii::$app->security->generateRandomString() . time();
     }], ['class' => ActionBehavior::className(), 'allevents' => [ActiveRecord::EVENT_AFTER_INSERT], 'action' => function ($event) {
         /** @var \yii\base\Event $event */
         $model = $event->sender;
         if ($model->scenario == 'register') {
             $oNotify = new Notificator([$model], $model, 'confirm_mail');
             $oNotify->notifyMail('Подтвердите регистрацию на портале "' . Yii::$app->name . '"');
         }
     }]];
 }
Beispiel #2
0
 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['prs_created']], 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'prs_confirmkey'], 'value' => function ($event) {
         /** @var \yii\base\Event $event */
         /** @var Person $model */
         $model = $event->sender;
         if ($model->prs_type == Person::PERSON_TYPE_GUEST) {
             return Yii::$app->security->generateRandomString() . time();
         }
         return $model->prs_confirmkey;
     }], ['class' => ActionBehavior::className(), 'allevents' => [ActiveRecord::EVENT_AFTER_INSERT], 'action' => function ($event) {
         /** @var \yii\base\Event $event */
         /** @var Person $model */
         /** @var \\app\\components\Notificator $oNotify */
         $model = $event->sender;
         if ($model->prs_type == Person::PERSON_TYPE_GUEST) {
             $oNotify = new Notificator([$model], $model, 'confirm_guest_mail');
             $oNotify->sEmailField = 'prs_email';
             $oNotify->notifyMail('Подтвердите регистрацию в качестве гостя на портале "' . Yii::$app->name . '"');
         }
     }]];
 }