Welcome Guest, Not a member yet? Register   Sign In
Showing not authorised message by default to non-admin users (for maintenance/offline mode)
#1

[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
#2

[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') ) {
  show_503();
}

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.
#3

[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?
#4

[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
#5

[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?
#6

[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
#7

[eluser]RichLove[/eluser]
Thanks very much




Theme © iAndrew 2016 - Forum software by © MyBB