Example #1
0
 public function beforeSave($insert)
 {
     if (!parent::beforeSave($insert)) {
         return false;
     }
     if ($insert) {
         $this->create_time = time();
         $this->ip = XUtils::getClientIP();
         $this->user_agent = Yii::$app->request->userAgent;
     }
     $this->ip = htmlspecialchars($this->ip);
     $this->user_agent = htmlspecialchars($this->user_agent);
     $this->type = htmlspecialchars($this->type);
     $this->action = htmlspecialchars($this->action);
     $this->result = htmlspecialchars($this->result);
     $this->detail = htmlspecialchars($this->detail);
     return true;
 }
Example #2
0
 public function beforeSave($insert)
 {
     if ($this->isNewRecord) {
         $this->ip = XUtils::getClientIP();
         $this->create_time = time();
         $this->user_agent = htmlspecialchars(Yii::$app->request->getUserAgent());
     } else {
         $this->update_time = time();
         $this->ext = serialize(['ip' => XUtils::getClientIP(), 'username' => Yii::$app->user->isGuest ? 'Guest' : Yii::$app->user->identity->username]);
     }
     return parent::beforeSave($insert);
 }
Example #3
0
 /**
  * 保存前校验补充数据
  * @param bool $insert
  * @return bool
  * @throws \yii\base\Exception
  * @throws \yii\base\InvalidConfigException
  */
 public function beforeSave($insert)
 {
     if (!parent::beforeSave($insert)) {
         return false;
     }
     if ($this->isNewRecord) {
         $this->register_time = time();
         $this->register_ip = XUtils::getClientIP();
         $this->auth_key = Yii::$app->security->generateRandomKey();
     }
     //注册黑名单
     if (in_array($this->username, $this->nameBlackList) || in_array($this->nickname, $this->nameBlackList)) {
         $this->{$this}->addError('username', '该用户名不能被注册!');
     }
     if (in_array($this->scenario, array(self::SCENARIO_REGISTER, self::SCENARIO_MODIFY_PWD))) {
         $this->password = $this->hashPassword($this->password);
     }
     $this->info = HtmlPurifier::process($this->info, ['HTML.ForbiddenElements' => ['a']]);
     //管理员更改用户数据不修改活动时间
     if ($this->scenario !== self::SCENARIO_MANAGE) {
         $this->active_time = time();
     }
     $this->update_time = time();
     return true;
 }