my session timeout config don't work correctly in yii 2 - session-cookies

I use this config for manage login duration time of users
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
'enableSession' => true,
'authTimeout' => 3600*24*120,
'loginUrl' => ['user/login']
//'class' => 'app\components\User',
],
'session' => [
'class' => 'yii\web\Session',
'timeout' => 3600*24*120,
'useCookies' => true,
],
and in login time set duration of login by :
Yii::$app->user->login($this->getUser(), 3600*24*120);
this is getUser() :
private $_user = false;
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::find()
->where(['mobile' => trim($this->mobile)])
->andWhere(['not',['status' => User::STATUS['SUSPEND']]])
->one();
}
return $this->_user;
}
These code work correctly in local , but in server don't work.
I was forced change manually session.gc_maxlifetime value in php.ini for my target. it's work
Question: Why don't work these config in server without change php.ini ? where is the problem ?

Related

Custom .env variable on Codeigniter 4

Normally if i want to change the database hostname in CI4 project i will change it in .env file and change the
database.default.hostname = localhost
but now i need to use MYSQL_HOST in env to change the hostname like so
MYSQL_HOST = localhost
can i do that in CI4? it will give error if i change the Database.php file to
public $default = [
'DSN' => '',
'hostname' => getenv('MYSQL_HOST'),
'username' => '',
'password' => '',
'database' => '',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
];
I found the answer, lets say you have this in you .env file
MYSQL_HOST = localhost
MYSQL_USERNAME = root
MYSQL_PASSWORD = root
so if you want to change hostname of CI4 database you can add
$this->default['hostname'] = getenv('MYSQL_HOST');
inside __construct() in app/config/Database.php
so it will be look like this
public function __construct()
{
parent::__construct();
// Ensure that we always set the database group to 'tests' if
// we are currently running an automated test suite, so that
// we don't overwrite live data on accident.
if (ENVIRONMENT === 'testing') {
$this->defaultGroup = 'tests';
}
$this->default['hostname'] = getenv('MYSQL_HOST');
$this->default['username'] = getenv('MYSQL_USERNAME');
$this->default['password'] = getenv('MYSQL_PASSWORD');
}
well this is only if you want to custom your .env and dont want to use the default CI4 database.default.hostname

How to upload some media files under “http://domain_name/folder_name” for a specific page?

I want to upload a file in a specific folder like http://domain_name/folder_name.
Please remember that, not in http://domain_name/wp-content/uploads/folder_name/file.
Try this code.
add_filter('upload_dir', 'upload_image_specific_calback');
function upload_image_specific_calback( $param ){
//$_GET['post'] which is your target post like 10 is post id.
//After click update button.
if(isset($_GET['post'])){
if($_GET['post'] == 10){
$param = array(
'path' => get_home_path().'logos',
'url' => home_url().'/logos',
'subdir' => '',
'basedir' => get_home_path(),
'baseurl' => home_url(),
'error' => false
);
}
}
//$_POST['post_id'] which is your target post like 10 is post id.
//instant upload time before save
if(isset($_POST['post_id'])){
if($_POST['post_id'] == 10) {
$param = array(
'path' => get_home_path().'logos',
'url' => home_url().'/logos',
'subdir' => '',
'basedir' => get_home_path(),
'baseurl' => home_url(),
'error' => false
);
}
}
error_log("path={$param['path']}");
error_log("url={$param['url']}");
error_log("subdir={$param['subdir']}");
error_log("basedir={$param['basedir']}");
error_log("baseurl={$param['baseurl']}");
error_log("error={$param['error']}");
return $param;
}

How to define a global variable that can be accessed in Delayed Job in rails?

This is my config/initializers/bunny.rb file:
if Setting.RABBITMQ_ENABLED[Rails.env]
conn = Bunny.new Setting.MERCURY_URL[Rails.env]
conn.start
bunny_settings = Setting.BUNNY_SETTINGS
## Channel && Topic for sending SMS-es.
sms_ch = conn.create_channel
::SmsHandle = sms_ch.topic(bunny_settings["sms_topic_name"], :durable => true, :auto_delete => true)
## Channel && Topic for sending seller requests
seller_ch = conn.create_channel
exchange = seller_ch.topic(bunny_settings["seller_topic_name"], :durable => true, :auto_delete => true)
seller_ch.queue(bunny_settings["seller_queue_name"], :durable => true, :auto_delete => true, :arguments => {}, :exclusive => false).bind(exchange, :routing_key => bunny_settings["seller_routing_key"]).subscribe do |delivery_info, properties, payload|
payload_json = JSON.parse payload
BunnyConsumer.consume_seller_request(delivery_info, properties, payload_json)
end
end
As you can see, I declared SmsHandle as a global variable to use it anywhere.
Worker code:
def send_sms(message_handle, caller_params)
if Setting.RABBITMQ_ENABLED[Rails.env]
pay_load = {:usertype => "custom", :triggers => [message_handle], :type => "notification", :caller_params => caller_params}.to_json
SmsHandle.publish(pay_load, :routing_key => "route_key" + rand(0..9).to_s, :content_type => "application/json", :type => "transport")
self.notification_events.create!(handle_name: message_handle, notification_type: SellerLead::NotificationType::SMS, payload: caller_params.to_json)
end
end
But, the problem for me here is that I unable to use it in any method that'll be called in a delayed_job.
So, how can I enable the delayed_job to use this particular variable.
Should I declare variable like this in the config/initializer/delayed_job.rb? Even this doesn't seem to working. Can someone point to the right way of doing this?

firewall pattern with parameters on anonymous asking for login

I have a route that has a parameter and its tripping my firewall thinking it needs to be logged in first. I tried to setup the pattern to use the name form at as used in the route but it still saying it requires authentication.
is there a special way to get the patter to work with parameters? I'm failing to see how to so that.
Thanks
$app->register(new Silex\Provider\SecurityServiceProvider(), [
'security.firewalls' => [
'login' => [
'pattern' => '^/login$',
'anonymous' => true
],
'pwdRecovery' => [
'pattern' => '^/recover',
'anonymous' => true
],
'newPassword' => [
'pattern' => '^/newpassword$',
'anonymous' => true
],
// Any other URL requires auth.
'authenticated' => [
'pattern' => '^.*$',
'form' => [
'login_path' => '/login',
'check_path' => '/authenticate'
],
'anonymous' => false,
'logout' => ['logout_path' => '/logout'],
'users' => $app->share(function() use ($app) {
return new App\Providers\UserServiceProvider();
}),
]
],
'security.access_rules' => [
['^/admin', 'ROLE_ADMIN']
],
'security.encoder.digest' => $app->share(function() {
return new BCryptPasswordEncoder(15);
})
]);
This may be a regex problem. I can pass parameters to the ^/recover route just fine.
$app->get('/recover/{id}', function (Request $request, $id) use ($app) {
error_log(print_r((int) $id,1).' '.__FILE__.' '.__LINE__,0);
});
But if I add $ to that route like ^/recover$ then it redirects to login because the dollar sign dictates end of string.

Where is SugarFullTest_Version2.php? (Sugar CRM and SOAP)

In regards to using SOAP to connect to Sugar CRM, the documentation for Sugar 6.1 Community Edition states:
"See /examples/SugarFullTest_Version2.php for more examples on usage."
source:
http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000244
This file is not in the examples folder. Where is it?
If this file does not exist, where can I find a working example of connecting to Sugar CRM with SOAP? None of the test scripts in the /examples/ folder work.
Couldn't find the file either, so made an example (PHP script connecting to sugarCRM v6 SOAP) for you.
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://mysite.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'xxxx',
'password' => MD5('xxxx'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
// Create lead
// (Can be made without login, i.e. sessionid)
$leadParams = array('user_name' => 'xxxx',
'password' => MD5('xxxx'),
'first_name' => 'Test',
'last_name' => '2',
'email_address' => '2#'
);
$leadResult = $soapClient->call('create_lead', $leadParams);
$leadId = $leadResult;
print_r($leadResult);
// Login
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'WebForm');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
// Modules
// (Need login, so sessionID is used)
$modulesResult = $soapClient->call('get_available_modules', array('session' => $sessionId));
print_r($modulesResult);
// Get account list
$accountParams = array('session' => $sessionId,
'module_name' => 'Accounts',
'query' => "accounts.name = 'Amarelo'",
'order_by' => '',
'deleted' => 0
);
$accountResult = $soapClient->call('get_entry_list', $accountParams);
print_r($accountResult);
// Get entry
$leadParams = array('session' => $sessionId,
'module_name' => 'Leads',
'id' => "$leadId"
);
$leadResult = $soapClient->call('get_entry', $leadParams);
print_r($leadResult);
// Logout
$logoutResult = $soapClient->call('logout', array('session' => $sessionId));
?>
For debugging and testing SoapUI is very helpful.

Resources