Skip to content

Instantly share code, notes, and snippets.

@DAddYE
Created April 27, 2010 15:26
Show Gist options
  • Save DAddYE/380870 to your computer and use it in GitHub Desktop.
Save DAddYE/380870 to your computer and use it in GitHub Desktop.
class MyAwesomeMoneyMakingService < Padrino::Application
register Authorization
get :edit, :with => :permalink, :authorize_with => :admin do
# Edit interface, I guess.
end
post :destroy, :with => :permalink, :authorize_with => :matainers do
@post = # ...
@post.destroy
end
end
module Authorization
def self.registered(app)
app.helpers Authorization::Helpers
end
def authorize_with(strategy)
case strategy
when :admin
current_account.role == "admin" || current_account.role == "editor" || params[:development] == "1"
when :mantainers
current_account.role == "mantainers"
end
end
module Helpers
def authorize(username, password)
# some authentication code
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment