public function __construct($config) { parent::__construct($config); // Set name from database if not set by config file. if (!isset($config['name'])) { if ($name = Config::setting('application.name')) { $this->name = $name; } } // Set email from database if not set by config file. if (!isset(Yii::$app->params['adminEmail'])) { Yii::$app->params['adminEmail'] = null; if ($email = Config::setting('application.admin.email')) { Yii::$app->params['adminEmail'] = $email; } } // Setup options for the user module. $user = Yii::$app->getModule('user'); $user->enableRegistration = Config::setting('user.registration.enabled'); $user->enableConfirmation = Config::setting('user.registration.confirmation'); $user->enableUnconfirmedLogin = Config::setting('user.registration.unconfirmed.login'); $user->enablePasswordRecovery = Config::setting('user.registration.password.recovery'); $user->rememberFor = Config::setting('user.login.remember.time'); $user->confirmWithin = Config::setting('user.registration.confirm.time'); $user->recoverWithin = Config::setting('user.registration.recover.time'); // Add some event listeners to the app user. $appUser = Yii::$app->user; $appUser->on($appUser::EVENT_AFTER_LOGIN, function ($e) use($appUser) { $class = $appUser->identityClass; $class::globalCookieSet($e->duration); }); $appUser->on($appUser::EVENT_AFTER_LOGOUT, function ($e) use($appUser) { $class = $appUser->identityClass; $class::globalCookieClear(); }); $appUserClass = $appUser->identityClass; if ($appUser->isGuest) { $appUserClass::globalCookieClear(); } else { $appUserClass::globalCookieSet(); } }
public static function theme() { $themeName = Config::setting('application.theme'); if (!$themeName) { return null; } return static::loadTheme($themeName); }
public function actionContact() { $content = Config::setting('page.contact.content'); if (!trim($content)) { throw new NotFoundHttpException('Page not found.'); } $page = (object) ['content' => $content]; $model = new ContactForm(); if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { Yii::$app->session->setFlash('success', Config::setting('page.contact.submitted')); return $this->refresh(); } return $this->render('contact', ['model' => $model, 'page' => $page]); }
public function __construct($config) { parent::__construct($config); // If database if unavailable skip settings (initital install). try { // Set name from database if not set by config file. if (!isset($config['name'])) { if ($name = Config::setting('application.name')) { $this->name = $name; } } // Set email from database if not set by config file. if (!isset(Yii::$app->params['adminEmail'])) { Yii::$app->params['adminEmail'] = null; if ($email = Config::setting('application.admin.email')) { Yii::$app->params['adminEmail'] = $email; } } } catch (DBException $e) { // Do nothing. } }
public static function maybeGarbageCollect() { // A cron-free way to garbage collect. if (!static::$maybeGC) { return false; } static::$maybeGC = false; $setting = 'oauth2.code.lastgc'; $now = time(); $lastGC = Config::setting($setting); // Check if time for another GC. if ($lastGC + static::$gcInterval >= $now) { return false; } // Update the current garbage collection time. Config::setting($setting, $now); $expire = static::getExpiration(); static::deleteAll(['<', 'updated_at', $now - $expire]); return true; }
public static function usernameBlacklisted($username) { $error = 'Blacklisted content in username.'; $list = Config::setting('user.name.blacklist'); $usernameLower = strtolower($username); foreach ($list as $entry) { if ($entry[0] === '/') { // Let regex use case insensitive flag if desired. if ((bool) preg_match($entry, $username)) { return $error; } } else { // Chack plain string case-insensitivly. if (strpos($usernameLower, strtolower($entry)) !== false) { return $error; } } } return null; }
public function saveSettings() { if (!$this->validate()) { return false; } foreach (Config::settingsKeys() as $key) { $prop = static::keyToProp($key); if ($this->hasProperty($prop)) { Config::setting($key, $this->{$prop}); } } return true; }
$items[] = ['label' => 'Logout', 'url' => ['/user/security/logout']]; } echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $items]); NavBar::end(); ?> </header> <main class="container"> <?php echo $content; ?> </main> </div> <footer class="footer"> <div class="container"> <p class="text-center"><?php if ($copyright = Config::setting('application.copyright')) { echo Html::encode(str_replace('{{year}}', date('Y'), $copyright)); } ?> </p> </div> </footer> <?php $this->endBody(); ?> </body> </html> <?php $this->endPage();