-
Notifications
You must be signed in to change notification settings - Fork 66
Authentication
If you have devise installed already you can use it for authentication. For example, if you have a user model that is setup with devise, and it has a booelan flag of admin that determines if a user is an admin, you would simply add the following to your routes file:
authenticate :user, lambda { |u| u.admin? } do
mount Upmin::Engine => '/admin'
endIf you aren't using devise and you want to add authentication, you can do this by overriding the application_controller used by Upmin Admin. To do this, create the controller app/controllers/upmin/application_controller.rb with contents similar to this:
module Upmin
class ApplicationController < ActionController::Base
before_filter :is_admin?
def is_admin?
# This should be your custom logic
if user.is_not_admin
raise ActionController::RoutingError.new('Not Found')
end
end
end
endThe filter should either give a 404, or redirect the user if they are not a valid admin user. Please note that this file runs in the context of the upmin-admin gem, so root_path will NOT point to your application root, but to the root of the engine (which is the path you mounted the engine at in Installation). If you want to redirect to a login page the easiest way is to just manually type in the path. eg redirect_to "/signin". Alternative, you can see the Accessing your Application Routes inside Upmin Admin for more info on accessing your application's paths.