Posted: Fri Jun 19, 2009 10:09 pm Post subject: RE:Ruby as CGI Script
Okay, I've run into another problem. (I decided to go with DataMapper btw, thanks for talking me into not using MySQL )
I have some Sinatra... things (Callbacks, hooks, or something?) and I want some to be protected, so that the user logged in needs to be at least a certain rank to view the page. If they aren't, redirect to he home page with a message.
I could do something like this for each, but I was wondering if there was some way to simplify it, make it DRYer.
get '/protected/path'do #session[:uid] is the user's id, nil means not logged in if(session[:uid] == nil)or(User[session[:uid]].level < 3)#User needs to be at least level three to get here
session[:flash] = 'You do not have permission to view this'
redirect '/' end #If we get here, the user is allowed. Continue on with page rendering, whatever. end
Posted: Sat Jun 20, 2009 1:32 pm Post subject: RE:Ruby as CGI Script