Before specific pages

29 views
Skip to first unread message

pistacchio

unread,
Apr 4, 2011, 1:47:02 AM4/4/11
to Limonade
hi,
i've recently used limonade for a project and i loved to.
when developing the "admin" area i needed to protect the
administration pages. example:

dispatch('/', 'home');
dispatch('/blog/', 'blog);
...
dispatch('/admin/', 'admin');
dispatch('/admin/new/*/', 'admin_new');
...

i have lots of admin pages and i had to include a protect() function
within each (to check if the user is logged in etc). how can i use
before() to check if the request is for a given array of routes and
then execute a script before the call?

thanks

Alejandro Villanueva

unread,
Apr 4, 2011, 12:17:19 PM4/4/11
to limo...@googlegroups.com
I just check a post from the limonade blog xangello.ca developed a bug tracker and you can see there how he implemented access to certain pages by user, you can check the code here:

https://github.com/AngeloR/Lemontrac/blob/master/index.php

it looks something like this:

dispatch('/project', 'project_list');
if(user('access_level') == 0) {
    dispatch('/project/new', 'create_project');
    dispatch_post('/project', 'create_project_handler');
    dispatch('/project/edit/:pjid', 'edit_project');
    dispatch('/project/close/:pjid', 'close_project_handler');
    dispatch_post('/project/:pjid', 'edit_project_handler');
}


2011/4/4 pistacchio <pista...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Limonade" group.
To post to this group, send email to limo...@googlegroups.com.
To unsubscribe from this group, send email to limonade+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/limonade?hl=en.




--
Alejandro Villanueva Escalante
www.iAlex.org
Admin [At] iAlex [Dot] org
ialex [At] LinuxMerida [Dot] org

P Antes de imprimir este mensaje, asegúrese de que es necesario. El medio ambiente está en nuestras manos.  ü  Ahorra papel

xangelo

unread,
Apr 4, 2011, 1:08:56 PM4/4/11
to Limonade
Hi pistacchio,

As Alejandro said, the easiest method I found was to simply wrap all
the routes in a simple if statement. Protected pages are not set as
routes if the user doesn't have the appropriate access level. That
way, even if the user knows the route to a page, they can't access it
because Limonade will report that page as non-existent.

The code you're looking for (that Alejandro posted below) occurs
around like 510, and the user function that I use is on line 51.
Reply all
Reply to author
Forward
0 new messages