Example #1
0
 /**
  * Check if user is binded to IP and compare it with his actual IP
  */
 public function validateIP()
 {
     $user = $this->getUser();
     if ($user and $user->bind_to_ip) {
         $ips = explode(',', $user->bind_to_ip);
         $ips = array_map('trim', $ips);
         if (!in_array(LittleBigHelper::getRealIp(), $ips)) {
             $this->addError('password', UserManagementModule::t('front', "You could not login from this IP"));
         }
     }
 }
Example #2
0
 /**
  * Save new record in DB and write unique token in session
  *
  * @param int $userId
  */
 public static function newVisitor($userId)
 {
     $browser = new Browser();
     $model = new self();
     $model->user_id = $userId;
     $model->token = uniqid();
     $model->ip = LittleBigHelper::getRealIp();
     $model->language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : null;
     $model->browser = $browser->getBrowser();
     $model->os = $browser->getPlatform();
     $model->user_agent = $browser->getUserAgent();
     $model->visit_time = time();
     $model->save(false);
     Yii::$app->session->set(self::SESSION_TOKEN, $model->token);
 }
Example #3
0
 /**
  * Make sure user will not deactivate himself and superadmin could not demote himself
  * Also don't let non-superadmin edit superadmin
  *
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($insert) {
         if (php_sapi_name() != 'cli') {
             $this->registration_ip = LittleBigHelper::getRealIp();
         }
         $this->generateAuthKey();
     } else {
         // Console doesn't have Yii::$app->user, so we skip it for console
         if (php_sapi_name() != 'cli') {
             if (Yii::$app->user->id == $this->id) {
                 // Make sure user will not deactivate himself
                 $this->status = static::STATUS_ACTIVE;
                 // Superadmin could not demote himself
                 if (Yii::$app->user->isSuperadmin and $this->superadmin != 1) {
                     $this->superadmin = 1;
                 }
             }
             // Don't let non-superadmin edit superadmin
             if (!Yii::$app->user->isSuperadmin and $this->oldAttributes['superadmin'] == 1) {
                 return false;
             }
         }
     }
     // If password has been set, than create password hash
     if ($this->password) {
         $this->setPassword($this->password);
     }
     return parent::beforeSave($insert);
 }
 /**
  * @param UploadedFile $file
  *
  * @return string
  */
 public function generateFileName($file)
 {
     return uniqid() . '_' . LittleBigHelper::slug($file->baseName, '_') . '.' . $file->extension;
 }
 /**
  * Generate url from the name
  *
  * @return bool
  */
 public function beforeValidate()
 {
     $this->url = $this->url ? $this->url : LittleBigHelper::slug($this->name);
     return parent::beforeValidate();
 }
Example #6
0
 /**
  * Make sure that only 1 main page exists
  *
  * @param bool $insert
  *
  * @return bool
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->type == static::TYPE_TEXT) {
             $this->slug = LittleBigHelper::slug($this->slug ? $this->slug : $this->name);
         }
         if ($this->is_main == 1 && ($insert || $this->oldAttributes['is_main'] == 0)) {
             ContentPage::updateAll(['is_main' => 0]);
             $this->active = 1;
         }
         return true;
     }
     return false;
 }