![]() |
Showing not authorised message by default to non-admin users (for maintenance/offline mode) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Showing not authorised message by default to non-admin users (for maintenance/offline mode) (/showthread.php?tid=30750) |
Showing not authorised message by default to non-admin users (for maintenance/offline mode) - El Forum - 05-25-2010 [eluser]RichLove[/eluser] Hi This is my first post here.. I have done a bit of Googling about this and have come across a few ideas but I want to make some things live on a site today and was hoping for some quick help if possible. I would like to put my site in to offline/maintenance mode to put some changes live (code, database and content (stored in database). I would like for users with the admin role (using dx auth) to be able to get access the site and for any other users who log in to be shown a custom error message (e.g. site undergoing maintenance) Could somebody please suggest a sensible way of doing this please (and if this sounds sensible)? My thoughts are to try and interrupt the application flow quite early on to check if the page is not the login page (still want to allow access to this so admin can login) and check if the user is admin - if not, redirect to an error html page or view. Richard Showing not authorised message by default to non-admin users (for maintenance/offline mode) - El Forum - 05-25-2010 [eluser]Buso[/eluser] What I did is to define a constant inside index.php SITE_CLOSED, which can be TRUE or FALSE Then inside the main controller I check for permissions, something like this: Code: if( SITE_CLOSED AND ! is_allowed('site_closed') ) { is_allowed() checks if the user is allowed to access the site when its closed show_503() sends him to a custom 503 error page. Codeigniter doesn't have these functions, but its not difficult to write them on your own. Showing not authorised message by default to non-admin users (for maintenance/offline mode) - El Forum - 05-25-2010 [eluser]RichLove[/eluser] Thanks for the reply Buso. What do you mean by main controller exactly...editing one of the core CI files so that the check is performed on every page request on the site? Showing not authorised message by default to non-admin users (for maintenance/offline mode) - El Forum - 05-25-2010 [eluser]Buso[/eluser] http://userguide/general/creating_libraries.html check out 'Extending Native Libraries' you can use MY_Controller as your main controller. Make all your controllers extend from it. Then use its constructor for site-wide checks Showing not authorised message by default to non-admin users (for maintenance/offline mode) - El Forum - 05-25-2010 [eluser]RichLove[/eluser] That's great thank you, I was reading about this after I put the post up here. I wasn't sure whether to do that or use a hook - perhaps pre_controller. Would using a hook work but using MY_controller might be a better solution? Showing not authorised message by default to non-admin users (for maintenance/offline mode) - El Forum - 05-25-2010 [eluser]Buso[/eluser] I use hooks only when I have to modify an already finished application and there is no other way to do it (eg: no main controller implemented). MY_Controller is the way to go But you can do it the way you want Showing not authorised message by default to non-admin users (for maintenance/offline mode) - El Forum - 05-25-2010 [eluser]RichLove[/eluser] Thanks very much |