Re: [Cppcms-users] Login mechanism
Brought to you by:
artyom-beilis
|
From: Artyom B. <art...@ya...> - 2012-05-21 12:58:19
|
________________________________
> From: Christian Gmeiner <chr...@gm...>
>
>
>Hi all,
>
>I am very new to cppcms but I am quite far in doing a conversion of a
>RoR app to cppcms.
>On thing thats missing is the user login. I have a login sub-app,
>which works nicely but I am looking
>for a way to check if users is login in on every page access -
>something like before_filter in RoR.
>
>Does there exists some linke that in cppcms?
Don't know how "before_filter" in RoR works. However there are two options:
1. If you want to check login for entire sub-application you can override main,
check if user logged in and if it is not put some redirect header
and not continue.
2. You can provide some kind guard in one of your base classes:
void check_logged_in()
{
if(!session().is_set("user_id")) {
throw not_logged_in();
}
}
And add it in every function that requires login
And override the main of tompost application with
void main(std::string url)
{
try {
cppcms::application::main(url);
}
catch(not_logged_in const &) {
response().set_redirect_header(...)
return;
}
}
3. Or even more simple without exceptions:
bool check_logged_in()
{
if(!session().is_set("user_id")) {
response().set_redirect_header(...)
return false;
}
return true;
}
And on your pages:
if(!check_logged_in())
return;
Artyom Beilis
--------------
CppCMS - C++ Web Framework: http://cppcms.com/
CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
>
>thanks
>--
>Christian Gmeiner, MSc
>
>------------------------------------------------------------------------------
>Live Security Virtual Conference
>Exclusive live event will cover all the ways today's security and
>threat landscape has changed and how IT managers can respond. Discussions
>will include endpoint security, mobile security and the latest in malware
>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>_______________________________________________
>Cppcms-users mailing list
>Cpp...@li...
>https://lists.sourceforge.net/lists/listinfo/cppcms-users
>
>
>
|