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 function saveConfig() { $config = new Config(); $conf = $config->findOne(['path' => 'newsletter.newsletterEnabled']); $conf->value = $this->isActive; $conf->save(); $conf = $config->findOne(['path' => 'newsletter.newsletterNotifyType']); $conf->value = $this->notifyType; $conf->save(); }
public function login($username = '', $password = '', $remember = '') { $user = $this->find($username); if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { $this->find($username); if ($user) { if ($this->data()->password === Hash::make($password)) { Session::put($this->_sessionName, $this->data()->id); if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('users_session', ['user_id', '=', $this->data()->id]); if (!$hashCheck->count()) { $this->_db->insert('users_session', ['user_id' => $this->data()->id, 'hash' => $hash]); } else { $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } return true; } } } return false; }
public static function generate_jwt($user) { $issuedAt = time(); $tokenId = base64_encode(Random::key(32)); $serverName = Config::get('serverName'); /* * Create the token as an array */ $data = ['iat' => $issuedAt, 'jti' => $tokenId, 'iss' => $serverName, 'exp' => $issuedAt + 1800, 'data' => ['userId' => $user->id, 'userName' => $user->username]]; /* * Extract the key, which is coming from the config file. * * Generated with base64_encode(openssl_random_pseudo_bytes(64)); */ $secretKey = base64_decode(Config::get('jwt')['key']); /* * Extract the algorithm from the config file too */ $algorithm = Config::get('jwt')['algorithm']; /* * Encode the array to a JWT string. * Second parameter is the key to encode the token. * * The output string can be validated at http://jwt.io/ */ $jwt = JWT::encode($data, $secretKey, $algorithm); return $jwt; }
public function getItem() { if (!$this->item) { $steam = new APIBridge(\Config::get('steam-api.api_key')); $this->item = $steam->queryPlayerInventory($this->app_id, $this->bot_steam_id)->findByClassID($this->class_id); } return $this->item; }
public function down() { if ($this->isSqlite()) { echo '!!! SQLite does not support drop columns.' . PHP_EOL; return; } $this->dropColumn(Config::tableName(), 'perms'); }
/** * Get the Neo4j client * * @return Client */ protected static function getClient() { $neo4jConfig = \Config::get('database.connections.neo4j'); // Create an admin $client = new Client($neo4jConfig['host'], $neo4jConfig['port']); $client->getTransport()->setAuth($neo4jConfig['username'], $neo4jConfig['password']); return $client; }
private function __construct() { try { $this->_pdo = new \PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password')); } catch (\PDOException $e) { die($e->getMessage()); } }
public function getFacebookInformation() { if ($this->fb_post_id) { $facebookRequest = sprintf('/%s?oauth_token=%s&fields=comments.summary(true).filter(toplevel).fields(parent.fields(id),comments.summary(true),message,from,created_time),likes.summary(true)', $this->fb_post_id, \Config::get('laravel-facebook-sdk.facebook_config.page_access_token')); $facebookResponse = \Facebook::get($facebookRequest)->getDecodedBody(); $this->facebook_information = $facebookResponse; } }
public static function theme() { $themeName = Config::setting('application.theme'); if (!$themeName) { return null; } return static::loadTheme($themeName); }
public function postIndex() { $configItem = Input::get('config'); $configValues = (array) Input::get($configItem); $config = \App\Models\Config::where('name', '=', $configItem)->first(); if (is_null($config)) { $config = new \App\Models\Config(); } $config->name = $configItem; $config->config = json_encode($configValues); if ($config->save()) { Session::flash('success', 'Config saved'); } else { Session::flash('error', 'Config could not be saved.'); } return Redirect::to("admin/config/" . $configItem); }
public static function connectToEs() { if (is_null(static::$_esInstance)) { $params = array('hosts' => Config::get('elasticsearch.hosts')); static::$_esInstance = new ElasticSearch\Client($params); } static::setEsIndex(Config::get('elasticsearch.annotationIndex')); return static::$_esInstance; }
public function actionIndex() { $model = Config::find()->one(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('index', ['model' => $model]); } }
public function getComments() { $comments = $this->comments()->with('user')->where('type', '=', 'post'); if (\Auth::check()) { $blockedUsers = app('App\\Repositories\\blockedUserRepository')->listIds(\Auth::user()->id); $comments = $comments->whereNotIn('user_id', $blockedUsers); } return $comments = $comments->orderBy('id', 'desc')->paginate(\Config::get('post-per-page')); }
private static function createUser(Hybrid_User_Profile $profile) { $user = new User(); $data = ['email' => $profile->email ? $profile->email : null, 'name' => $profile->displayName, 'avatar' => $profile->photoURL, 'country' => $profile->country, 'gender' => $profile->gender, 'region' => $profile->region, 'phone' => $profile->phone, 'city' => $profile->city, 'address' => $profile->address, 'birthday' => $profile->birthYear . '-' . $profile->birthMonth . '-' . $profile->birthDay, 'language' => $profile->language]; $user->fill($data); $user->token = md5(sha1(\Config::get('app.key') . microtime() . rand())); $user->save(); return $user; }
private static function createStartingCountries(Field $field) { $countries = new Collection(); for ($x = 0; $x < \Config::get('settings.fieldWidth'); $x++) { for ($y = 0; $y < \Config::get('settings.fieldHeight'); $y++) { $countries->push(Country::create(['x' => $x, 'y' => $y, 'field_id' => $field->id])); } } return $countries; }
public function updateValues() { $items = $this->all(); foreach ($items as $item) { $name = $item->name; $values = json_decode($item->config); foreach ($values as $key => $value) { \Config::set($name . '::' . $key, $value); } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Config::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['config_id' => $this->config_id]); $query->andFilterWhere(['like', 'config_name', $this->config_name])->andFilterWhere(['like', 'config_value', $this->config_value]); return $dataProvider; }
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 actionSubscribe() { if (Yii::$app->request->isAjax) { $email = Yii::$app->request->post('email'); $validator = new EmailValidator(); if ($validator->validate($email)) { $mc = new Mailchimp(Config::find()->where('name = :name', [':name' => 'mailChimpKey'])->one()->value); $Mailchimp_Lists = new Mailchimp_Lists($mc); $subscriber = $Mailchimp_Lists->subscribe(Config::find()->where('name = :name', [':name' => 'mailChimpListId'])->one()->value, array('email' => htmlentities($email))); if (!empty($subscriber['leid'])) { echo "'Ваш электронный адрес добавлен в подписчики'"; } else { echo "error"; } } else { echo "Неправильный электронный адрес"; } } }
/** * @param string $targetRole * @param bool $checkSubRoles * @return bool */ public function hasRole($targetRole, $checkSubRoles = true) { $roles = []; foreach ($this->roles as $role) { $roles[] = $role->role; } if (in_array($targetRole, $roles)) { return true; } if (!$checkSubRoles) { return false; } $roleConfigs = \Config::get('admin_user.roles', []); foreach ($roles as $role) { $subRoles = array_get($roleConfigs, "{$role}.sub_roles", []); if (in_array($targetRole, $subRoles)) { return true; } } return false; }
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 function getUIConfig() { $cache = Yii::$app->get($this->cacheComponent); $cache->delete('UI_CONFIG'); $config = $cache->get('UI_CONFIG'); if ($config === false) { $config = []; $configModels = Config::find()->where(['option' => 'cdnServer'])->all(); foreach ($configModels as $model) { $config[$model->option] = $model->value; } $cache->set('UI_CONFIG', $config); } if (YII_ENV_DEV || Yii::$app->session->get("debugMode", false)) { $sessionConfig = Yii::$app->session->get("uiConfig", false); if ($sessionConfig !== false) { foreach ($sessionConfig as $key => $value) { $config[$key] = $value; } } } return $config; }
/** * Determines whether or not the provided subdomain * meets subdomain length and character requirements. * * @param string $subdomain * @return bool */ public function isValidSubdomain($subdomain) { $subdomain = lowertrim($subdomain); $min_length = Config::get('stryve.tenant.subdomain-min-length'); $max_length = Config::get('stryve.tenant.subdomain-max-length'); $subdomain_length = strlen($subdomain); // check subdomain is of valid characters if (!isValidSubdomain($subdomain)) { return false; } // check subdomain meets length requirements if ($subdomain_length < $min_length || $subdomain_length > $max_length) { return false; } return true; }
public function scopeSearch($query, $searchData = array(), $status = '') { if (!empty($searchData)) { $idCountry = $searchData[0]['value']; $idCate = $searchData[1]['value']; $typeName = $searchData[2]['value']; $keyword = $searchData[3]['value']; $status = $searchData[4]['value']; if (!empty($idCountry)) { $query->where('country', $idCountry); } if (!empty($idCate)) { $query->where('category', $idCate); } if (isset($status) && $status != -1) { $query->where('status', $status); } if (!empty($keyword)) { if ($typeName == "company") { $query->where("company", "LIKE", DB::raw("'%{$keyword}%'")); } else { $query->where('email', 'LIKE', DB::raw("'%{$keyword}%'")); } } } else { if ($status == Config::get('backend.publisher_approved')) { $query = $query->where('status', Config::get('backend.publisher_approved')); } else { $query->where('status', '0'); } } return $query; }
public function down() { $this->dropTable(Config::tableName()); $this->dropTable(Storage::tableName()); }
<?php //namespace app\core; use app\models\Cookie; use app\models\Config; use app\models\Session; use app\models\User; use app\classes\DB; session_start(); $GLOBALS['config'] = ['mysql' => ['host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'db' => 'test'], 'remember' => ['cookie_name' => 'hash', 'cookie_expiry' => 604800], 'session' => ['session_name' => 'root', 'token_name' => 'token']]; spl_autoload_register(function ($class) { require_once 'classes/' . $class . '.php'; }); require_once "functions/sanitize.php"; if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) { $hash = Cookie::get(Config::get('remember/cookie_name')); $hashCheck = DB::connect()->get('users_session', ['hash', '=', $hash]); if ($hashCheck->count()) { $user = new User($hashCheck->first()->user_id); $user->login(); } }
public function run() { $config = Config::find()->select('watermark')->one(); return $this->render('watermark', ['watermark' => $config->watermark]); }
/** * Find installation config * * @return Config|null */ public function getInstallation() { /** @var Config|null $config */ $config = Config::all()->first(); return $config; }
/** * @param int $width * @param int $height * @return string */ public function getThumbnailUrl($width, $height) { if (\Config::get('app.offline_mode', false)) { return \URL::to('static/img/local/local.png'); } if (empty($this->url)) { if ($height == 0) { $height = intval($width / 4 * 3); } return 'https://placehold.jp/' . $width . 'x' . $height . '.jpg'; } $categoryType = $this->file_category; $confList = \Config::get('file.categories'); $conf = array_get($confList, $categoryType); if (empty($conf)) { return $this->getUrl(); } $size = array_get($conf, 'size'); if ($width === $size[0] && $height === $size[1]) { return $this->getUrl(); } if (preg_match(' /^(.+?)\\.([^\\.]+)$/', $this->url, $match)) { $base = $match[1]; $ext = $match[2]; foreach (array_get($conf, 'thumbnails', []) as $thumbnail) { if ($width === $thumbnail[0] && $height === $thumbnail[1]) { return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext; } if ($thumbnail[1] == 0 && $height == 0 && $width <= $thumbnail[0]) { return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext; } if ($thumbnail[1] == 0 && $height != 0 && $size[1] != 0) { if (floor($width / $height * 1000) === floor($size[0] / $size[1] * 1000) && $width <= $thumbnail[0]) { return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext; } } if ($thumbnail[1] > 0 && $height > 0) { if (floor($width / $height * 1000) === floor($thumbnail[0] / $thumbnail[1] * 1000) && $width <= $thumbnail[0]) { return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext; } } } } return $this->getUrl(); }