Use custom session in fatfree framework - fat-free-framework

I want to use custom session in my fatfree application.
I have already running a custom php website here: http://www.example.com and I have installed fat free app under a subdirectory like
http://www.example.com/fatfree-app, can you please let me know how I can use my parent site( http://www.example.com) session under http://www.example.com/fatfree-app.
In my parent site I'm setting session in this way:
$_SESSION['access'] = TRUE;
$_SESSION['userid'] = $objUser->userid;
$_SESSION['role_id'] = $objUser->role_id;
$_SESSION['team_id'] = $objUser->team_id;
$_SESSION['uname'] = $objUser->uname;
$_SESSION['name'] = $objUser->name;
How can I disable built-in session in fat-free framework?
Thank you in advance.

Well, you could use f3's build in sync function.
$f3->sync('SESSION'); // ensures PHP global var SESSION is the same as F3 variable SESSION
And to disable it just set Session to false in the system variables.
$f3->set('SESSION', FALSE);

Related

How to declare multiple Un-authorized URL's in apache Shiro configuration

I am trying out the Apache Shiro framework and I basically downloaded the setup from a project online. I managed to get it working but I am stuck at a really small issue. I want to make multiple JSF pages in my project to be accessed without any authorization.
The configuration currently looks something like:
authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
authc.loginUrl = /login.xhtml
roles.unauthorizedUrl = /login.xhtml
Now I would like to add one more page to roles.unnauthorizeddUrl i.e. signUp.xhtml
I tried
roles.unauthorizedUrl = /login.xhtml,/signUp.xhtml
but that doesnt work. Is there a way to declare multiple unauthorized URL's in the config.
The roles.unauthorizedUrl is the Url to which the user has to be redirected in case user tried to access the protected / unauthorized url. So you only add one such URL, otherwise ambiguity will be raised to the framework to which url to redirect.
If you want unprotect any url use the below config in [urls] section
/login.xhtml = anon
/sugnUp.xhtml = anon

How to use cron job in yii2 windows

I want to use cron job in my yii2 project. I ever search it, but I only get the tutorial in linux, in the other side I use windows. So, how can I implement cron job in yii2 in windows operating system? I have gotten the tutorial from http://www.yiiframework.com/extension/yii2-cronjob/. It use extension but I don't know to use it. I don't understand some explanation like "run the SomeModel::some_method for today". So, how to implement it?
You can try to use this extension https://github.com/yii2tech/crontab
use yii2tech\crontab\CronJob;
use yii2tech\crontab\CronTab;
$cronJob = new CronJob();
$cronJob->min = '0';
$cronJob->hour = '0';
$cronJob->command = 'php /path/to/project/yii some-cron';
$cronTab = new CronTab();
$cronTab->setJobs([
$cronJob
]);
$cronTab->apply();

how to load and edit a sql database from adobe flex builder 4.6 air program

Alright I have my sqldb hosted online and can access it using phpmyadmin what i would like to do is create tables and add items to the tables via adobe flex builder 4.6 desktop AIR application.
Anyone know if i am able to do this, the idea for the program is so person at position A can enter a name and person at position B can then use his program to read those names
According to Accessing mysql from Adobe flex/AIR, AIR is unable to access MySQL servers directly, so you'll have to use web services or some custom API do to this. But yeah, sure it's possible to do what you want.
I agree with Isaac. However, I want to add that it is good coding practices to not allow client side applications modify a database directly. In the applications that I have built, I like to use PHP to set-up an API that then interacts with the database. The AIR application then the interaction with the API using HTTP Requests.
Following code shows how to perform a URL request from the Adobe Website.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html
var url:String = url location of the API;
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables(); //create variables to pass to the API
variables.exampleSessionId = new Date().getTime(); //create variables to pass to the API
variables.exampleUserLabel = "guest"; //create variables to pass to the API
request.data = variables; //Add the variables to the request
request.method = URLRequestMethod.POST; //Set the method of the Request GET, POST, PUT
navigateToURL(request); //Executes the request
You'd probably like something like https://backendless.com/ for this.

Keeping a user logged in with nodeJS

I have a login system with my NodeJS using mysql-node.
The problem i have how ever is how to keep the user logged in, if they refresh the page they have to login again, because i do not know how to store the session.
My login system is like this:
socket.on('login', function(data,callBack){
var username = sanitize(data['login']).escape(),
pass = sanitize(data['password']).escape();
var query = connection.query('SELECT uid FROM users WHERE name = ? AND pass = ?', [username,pass],
function(err,results){
if(err){
console.log('Oh No! '+err);
} else if(results.length == 1){
//some how set a session here
} else if(!results.length) {
console.log('No rows found!');
}
});
});
I'm having difficulty understanding how i set up a session for each client that connects. Is this possible with NodeJS ?
Reading that they assign express to var app but if i already have this : var app = http.createServer( ... how can i also assign express to it :S bit confusing
You need to understand the difference between a express' server and a native NodeJS' server, here my link comparaison nodejs server vs express server
So you can do:
var app = express();
var server = http.createServer(app);
This enable you to have still the low level functionnaly with NodeJS.
So, if you don't want to use existing modules or framework, you can build your own session manager:
using cookie
using IP/UA
using socket
The best way would be first to implement it with socket, for example:
server.on('connection', function (socket) {
socket.id = id;
});
or
server.on('request', function (req, res) {
req.connection.id = id; // The socket can also be accessed at request.connection.
});
So, you just need to implement a middleware who check the id.
If you want to prevent from session prediction, session sidejacking, etc. you need to combine cookies, ip, socket, and your ideas to make it more secure for your app.
Once you've done your session manager, you can choose where to store the sessions, in a simple object, in redis, in mongodb, in mysql ... (express use MemoryStore by default, but maybe not now)
I don't have an idea if nodejs has core feature of saving sessions. you need to use a database along with it. using Express will help you to utilized a database to persist user sessions. You better study and use it
http://expressjs.com/
http://blog.modulus.io/nodejs-and-express-sessions
I don't think there is any session mechanism within Nodejs' core. However, they are plenty of libraries that would allow you to do it. The first that comes to mind is Connect's session, which is a middleware for Nodejs. Have a look at this question for more details on how to use it.
Have a look at this tutorial from dailyjs which tries to include Express's session into a notepad webapp. The source code is available here. (Note that Express' session is based on Connect's, and is practically the same).
EDIT: Here is a more complete example for Node authentication, using mongoose. They do however show their schemas, so I assume you can easily do the transition to MySQL.

Using profile in Watir and Webdriver

My question is regarding modify default profile settings to allow/deny access of mic and cam by my web app. Here is the code - which seems to be ignored.
#!/usr/bin/ruby
require 'watir-webdriver'
profile = Selenium::WebDriver::Chrome::Profile.new
profile['content_settings.pattern_pairs.*,*.media-stream-mic'] = 1
# if I put mysever.com into here (first asterix), the parsing must fail
# as the '.' is used as delimiter by profile.rb - so *,* should work
browser = Watir::Browser.new :chrome, :profile => profile
browser.goto "http://webaudiodemos.appspot.com/input/index.html"
# here a get media event is fired and the browser should proceed without(!)
# asking the user for permission - but the browser is always asking and
# this element is not accessible for Watir (is it?).
I had a look into profile.rb where just the parsing takes place - which is also somehow problematic (see comment inline).
I also searched the web but could not find anything.
Holger
1. create a profile manually using the cmd :
firefox -profilemanager
set what you want on the browser of the new profile
2.code example
protected void initializeWebDriver() {
LoggerInfo.logger.info("Starting webdriver...");
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("MyProfile");
// FirefoxProfile profile = new FirefoxProfile();
driver = new DriverBuilder().using(Browser.FIREFOX).withFirefoxProfile(profile).build();
LoggerInfo.logger.info("webdriver is up");
}