Whenever i got an error in yii2 application it shows session and cookie information.
$_COOKIE = [
'advanced-backend' => 'd9ao5cmemmnte4epb69mkuore1',
'_identity-backend' => '9f1de7abef3bcb3b520d1a6caa06defc181307c5f227cb3bf06477428d021366a:2:{i:0;s:17:"_identity-backend";i:1;s:16:"[51,144,2592000]";}',
];
$_SESSION = [
'__flash' => [],
'__returnUrl' => '/oms/',
'UserID' => '51',
'UserName' => 'alesh#example.com.np',
'FullName' => 'Alesh',
'EmployeeID' => '53',
'RoleID' => '423',
'SupervisorID' => '342',
'SupervisorName' => 'USER',
'Menus' => 'leave,attendance,dailyreport,myinfo',
'Role' => 'employee',
'__id' => 51,
'__expire' => 1520506157,
];
as this cant be secure to show these things to user how to hide or remove these things when user get an error??
In home directory of your project, you have a index.php file, just need to change first and second line of this file to :
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
this change, can change your project to production mode and hide any error of your site, but error stored in project_root\runtime\logs
Related
Where is session files stored in Yii2? I need to know the the exact location. There is options to create a session database.
The default session save path is '/tmp'. link
This path is accessible via the getSavePath() method in the session class file(yii2)
#property string $savePath The current session save path, defaults to '/tmp'.
For example, in xampp software (localhost) go to the following folder(default)
myDrive:\xampp\tmp // The drive where the software is installed
It is taken by default through the session_save_path method. Which depends on the settings of the php.ini file. In session.save_path="...\tmp"
But you can also configure it through the .htaccess file
To adjust Yii2, you can do the following. In the config web file
'components' => [
'session' => [
'name' => '_Session',
'savePath' => dirname(__DIR__) .'/sessions'
],
To save in the database(yii\web\DbSession) refer to this link.
Example:
'session' => [
'class' => 'yii\web\DbSession',
'name' => 'mySession',
// 'db' => 'mydb', // the application component ID of the DB connection. Defaults to 'db'.
// 'sessionTable' => 'my_session', // session table name. Defaults to 'session'.
'timeout' => 30 * 24 * 3600,
'cookieParams' => ['httponly' => true, 'lifetime' => 3600 * 24],
'writeCallback' => function ($session) {
return [
// 'user_id' => Yii::$app->user->id,
// 'last_write' => time(),
];
},
],
writeCallback: To create more data and columns in the database table
Good luck
Yii2 by default stores session files in #app/runtime/data folder.
And if you want to use database instead then yii2 guide is great resource. check this link: https://www.yiiframework.com/doc/guide/2.0/en/runtime-sessions-cookies#custom-session-storage.
Moodle 3.5.1
plugin auth_saml2sso_moodle35_2018051500.zip
Question:
I guess I have the same error as Naaman Fallouh at https://moodle.org/plugins/auth_saml2sso (comments page 2)
I am able to login with phpBB/SAML and have
http://moodle.localhost/
and
http://moodle.localhost/simplesaml
I am able to login using http://moodle.localhost/simplesaml
I am able to login using http://moodle.localhost/ but after the login I get stuck in a loop:
http://saml_idp.localhost/simplesaml/saml2/idp/SSOService.php?SAMLRequest=chars&RelayState=http%3A%2F%2Fmoodle.localhost%2Flogin%2Findex.php
(saml_idp.localhost is indeed my idp)
Over and over again, with every time other value for chars.
I did set in http://moodle.localhost/simplesaml/config/config.php
'session.phpsession.cookiename' => 'MoodleSession',
That is the only difference from the
phpbb3.localhost/simplesaml/config/config.php.
What else could be wrong? What's your first thought I should look at?
I use the example userpass authentication and defined a user like so:
'admin:admin' => array(
'urn:oid:0.9.2342.19200300.100.1.1' => array('admin'),
'idnumber'=> array('123'),
'email' => array('email#admin.nl'),
'firstname' => array('firstadmin'),
'lastname' => array('lastadmin'),
"phone1" => array('admin'),
"phone2" => array('admin'),
"department" => array('admin'),
"address" => array('admin'),
"city" => array('admin'),
"country" => array('admin'),
"description" => array('admin'),
"idnumber" => array('admin'),
"lang" => array('admin'),
"guid" => array('admin'),
'urn:oid:1.3.6.1.4.1.5923.1.1.1.1' => array('globaladministrators'),
),
In Moodle the plugin configuration I set
Username attribute to: urn:oid:0.9.2342.19200300.100.1.1
Would that not be enough?
Fixed by using sql for session.
For the currency conversion i am using "florianv/laravel-swap": "^1.1" library. Florianv/Laravel-swap.
As Fixer.io has changed its implementation, it is necessary to pass the access_key with the request, and because of that i am getting this error: "InvalidArgumentException: The "access_key" option must be provided to use fixer.io in /var/www/project/project-files/vendor/florianv/exchanger/src/Service/Fixer.php:51".
I registered and got the access_key.
I updated the library using composer and now i can see three constants in the vendor/florianv/exchanger/src/Service/Fixer.php.
const ACCESS_KEY_OPTION = 'access_key';
const LATEST_URL = 'http://data.fixer.io/api/latest?base=%s&access_key=%s';
const HISTORICAL_URL = 'http://data.fixer.io/api/%s?base=%s&access_key=%s';
To pass the access key i tried this:
I have a swap.php in config folder which looks something like this:
return [
'options' => [
'cache_ttl' => 86400, // 24 hours.
'cache_key_prefix' => 'currency_rate'
],
'services' => [
'fixer' => true,
],
'currency_layer' => [
'access_key' => 'asdfas7832mw3nsdfa776as8dfa', // Your app id
'enterprise' => true, // True if your AppId is an enterprise one
],
'cache' => env('CACHE_DRIVER', 'file'),
'http_client' => null,
'request_factory' => null,
'cache_item_pool' => null,
];
This had one more option which was commented, i enabled and passed the access_key in it but it doesn't work.
I also added it in services block below 'fixer => true'.
'currency_layer' => [
'access_key' => 'asdfas7832mw3nsdfa776as8dfa'
]
Also in options block:
'options' => [
'cache_ttl' => 86400, // 24 hours.
'cache_key_prefix' => 'currency_rate',
'access_key'=>'7ca208e9136c5e140d6a14427bf9ed21'
],
I tried with adding access_key in config/services.php file but it also didn't work.
'fixer' => [
'access_key' => 'asdfas7832mw3nsdfa776as8dfa'
],
Even i tried, adding to env file and calling from there, but no success. How do i pass the access_key, can anyone help me on this, what should be the approach.
vendor/florianv/exchanger/src/Service/Fixer.php -> don't touch the constant (that was my own error).
Pass the options-array by creating the Builder:
$options = ['access_key' => 'YourGeneratedAPIKeyAtCurrencyLayer'];
$this->exchangeSwap = (new Builder($options))
->add('fixer', $options )
->build();
I hope I could help ;-)
I m using a basic template for a small project on Yii2. I have already set the module Language Picker of Lajax (Doc) and I am trying now to manage the translation with the module Translate Manager of Lajax (Github). The plugin is scanning perfectly the project and getting the translatable texts. I even set some translations through this module and everything is saved in the database, but these translations are not set when changing the language.
here are my web.php Configurations:
'language' => 'en-GB',
'components' => [
...
'languagepicker' => [
'class' => 'lajax\languagepicker\Component',
'languages' => ['en-GB', 'fr-FR']
],
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\DbMessageSource',
'db' => 'db',
'sourceLanguage' => 'en-GB',
'sourceMessageTable' => '{{%language_source}}',
'messageTable' => '{{%language_translate}}',
'forceTranslation' => true,
'cachingDuration' => 86400,
'enableCaching' => true,
],
],
],
...
]
'modules' => [
...
'translatemanager' => [
'class' => 'lajax\translatemanager\Module',
'root' => '#app', // The root directory of the project scan.
'scanRootParentDirectory' => false, // Whether scan the defined `root` parent directory, or the folder itself.
// IMPORTANT: for detailed instructions read the chapter about root configuration.
'layout' => 'language', // Name of the used layout. If using own layout use 'null'.
'allowedIPs' => ['127.0.0.1'], // IP addresses from which the translation interface is accessible.
'roles' => ['#'], // For setting access levels to the translating interface.
'tmpDir' => '#runtime', // Writable directory for the client-side temporary language files.
// IMPORTANT: must be identical for all applications (the AssetsManager serves the JavaScript files containing language elements from this directory).
'phpTranslators' => ['::t'], // list of the php function for translating messages.
'jsTranslators' => ['lajax.t'], // list of the js function for translating messages.
'patterns' => ['*.js', '*.php'],// list of file extensions that contain language elements.
'ignoredCategories' => ['yii'], // these categories won't be included in the language database.
'ignoredItems' => ['config'], // these files will not be processed.
'scanTimeLimit' => null, // increase to prevent "Maximum execution time" errors, if null the default max_execution_time will be used
'searchEmptyCommand' => '!', // the search string to enter in the 'Translation' search field to find not yet translated items, set to null to disable this feature
'defaultExportStatus' => 1, // the default selection of languages to export, set to 0 to select all languages by default
'defaultExportFormat' => 'json',// the default format for export, can be 'json' or 'xml'
'tables' => [ // Properties of individual tables
[
'connection' => 'db', // connection identifier
'table' => '{{%language}}', // table name
'columns' => ['name', 'name_ascii'],// names of multilingual fields
'category' => 'database-table-name',// the category is the database table name
]
],
'scanners' => [ // define this if you need to override default scanners (below)
'\lajax\translatemanager\services\scanners\ScannerPhpFunction',
'\lajax\translatemanager\services\scanners\ScannerPhpArray',
'\lajax\translatemanager\services\scanners\ScannerJavaScriptFunction',
'\lajax\translatemanager\services\scanners\ScannerDatabase',
],
],
...
]
I always use something like this im code for translatable strings:
<?= Yii::t('app','Test') ?>
Am I doing something wrong?
I have got the following in my sentry seeder:
<?php
use App\Models\User;
class SentrySeeder extends Seeder {
public function run()
{
DB::table('users')->delete();
DB::table('groups')->delete();
DB::table('users_groups')->delete();
Sentry::getUserProvider()->create(array(
'email' => 'admin#admin.com',
'password' => "admin#admin.com",
'first_name' => 'Kamran',
'last_name' => 'Ahmed',
'activated' => 1,
));
Sentry::getUserProvider()->create(array(
'email' => 'user#user.com',
'password' => "user#user.com",
'first_name' => 'New',
'last_name' => 'User',
'activated' => 1,
));
Sentry::getGroupProvider()->create(array(
'name' => 'Admin',
'permissions' => array(
'blog' => 1
),
));
Sentry::getGroupProvider()->create(array(
'name' => 'Blogger',
'permissions' => array(
'blog.add' => 1,
'blog.update' => 1,
'blog.trash' => 1,
'blog.remove' => 1
),
));
// Assign user permissions
$adminUser = Sentry::getUserProvider()->findByLogin('admin#admin.com');
$adminGroup = Sentry::getGroupProvider()->findByName('Admin');
$normalUser = Sentry::getUserProvider()->findByLogin('user#user.com');
$normalGroup = Sentry::getGroupProvider()->findByName('Blogger');
$adminUser->addGroup($adminGroup);
}
}
As you can see, I have defined two groups Admin and Blogger. Admin has all the permissions defined by blog, while blogger can only blog.add, blog.update, blog.trash and blog.remove. In my post view, I have got a button called Delete Permanently for which I have used the permission blog.remove. I want to show this button only if Sentry::getUser()->hasAnyAccess(array('blog', 'blog.remove')):
#if (Sentry::getUser()->hasAnyAccess(array('blog', 'blog.remove')))
<a class="btn btn-danger" href="{{URL::to('post/delete/' . $post->id)}}">Delete Permanently</a>
#endif
Now when I login using the admin#admin.com, it works fine that is remove button is shown as expected, because the admin has the access to blog permission. But, when I login using user#user.com, the button is not being shown. What is the reason that the button is not being shown although I have assigned the permission of blog.remove to user#user.com. Also I did a var_dump(..) and it's return false. Can any one please tell me what's wrong with my implementation? Why is the removal button not being shown for the user#user.com user?
In your seeder your not assigning the user to the blogger group.
$normalUser->addGroup($normalGroup);