Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » sessions in Skylark
sessions in Skylark [message #38375] Wed, 12 December 2012 23:26 Go to previous message
Peter is currently offline  Peter
Messages: 16
Registered: October 2012
Promising Member
Hello.

I wrote a very simple authorization system using sessions. The general idea is as follows. I have two pages: main page and the other one with a login form. If the user tries to enter the main page without logging in, he/she will be redirected to login page. When the correct login ("john") and password ("doe") are given, a new session is established, the user gets redirected to the main page and a success message is displayed. This part works fine, here's the code:

main cpp:

#include <Skylark/Skylark.h>

using namespace Upp;

SKYLARK(Login, "login")
{
	http.RenderResult("Sessions/login");
}

SKYLARK(HomePage, "")
{
	if(IsNull(http[".SESSID"]))
		http.Redirect(Login);
	else
		http << "<html><body>You are logged in.</body></html>";
}

SKYLARK(HomePagePost, "post:POST") 
{
	if((String)http["login"] == "john" && (String)http["password"] == "doe")
	{
		http.SessionSet(".SESSID", (int)Random());
		http.Redirect(HomePage);
	}
	else
		http.Redirect(Login);
}

SKYLARK(CatchAll, "**")
{
	http.Redirect(Login);
}

struct MyApp : SkylarkApp {

    MyApp() {
    #ifdef _DEBUG
	prefork = 0;
	use_caching = false;
	#endif
    }
};

CONSOLE_APP_MAIN
{
	#ifdef _DEBUG
	StdLogSetup(LOG_FILE|LOG_COUT);
	Ini::skylark_log = true;
	#endif
    MyApp().Run();    
}


login.witz:

<html>
<body>
<form action=$HomePagePost method="post" accept-charset="utf-8" enctype="multipart/form-data">
   <P>
   	$post_identity()
    Login:<INPUT type="text" name="login" id=""><br>
    Password:<INPUT type="password" name="password" id=""><br>
    <INPUT type="submit" value="Log in">
   </P>
</form>
</body>
</html>


Now I'd like to be able to decide how long a session should last before it expires. Unfortunately I don't know how to do it. The way it works now is as follows: in IE and Chrome the session doesn't expire until I close the browser window. In Firefox I remain logged in even after closing the browser window and opening a new one.

Let's say I want session to expire one minute after logging in. I thought setting SkylarkSessionConfig::expire to 60 would do the trick, but it didn't. I also tried to use Http::ClearSession, but it didn't work the way I expected. Can you please give me some tips?
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: docEdit /lineEdit to array
Next Topic: Compile for Unix on Windows?!?!?!?
Goto Forum:
  


Current Time: Sun Aug 24 12:37:12 CEST 2025

Total time taken to generate the page: 0.04277 seconds