LoxAuth is a dropin solution for basic authentication for Nitro apps. Can be used to login your users as well as registering them. It's customizable by settings if you need registering for example, since this is deactivated by default.
Copyright (c) 2006 Fabian Buch under MIT license. See LICENSE file for details.
May work with other versions with small adjustments
in your run.rb:
require 'part/auth' Nitro::Server.map['/auth'] = AuthController
before your controllers and models!
in your Controller
class MainController < Nitro::Controller helper :auth pre :force_login, :on => [:edit, :add] # This action is now protected. When someone tries to # go to /edit while not being logged in, he will be # redirected to a login screen and after having logged # in he will be redirected to `edit` again. # The same happens with `add` and any other protected # action. def edit(id) # do something end end
Part Auth has its own User model, if it's not sufficient for you, just extend
it by monkey patching. Currently the User has the properties :name, :email and
:password, so if you need it to have an additional age do the
following in your own User model:
class User property :age, Integer end
Same goes for relations:
class User has_many :articles, Article end
If your application defines a Page skin class (Element) it'll integrate nicely into your Page design.
To enable Registering:
LoxAuthPart.register_enabled = true LoxAuthPart.register_welcome_msg = "Successfully registered. You're logged in now!"
To disable Roles:
LoxAuthPart.roles_enabled = false
Apart from adding additional properties to User or Role you can also modify how it looks.
Copy the xhtml templates from the LoxAuth template folder to auth/ (subfolder of your template folder, standard is template, modifyable by the setting Nitro::Template.root = 'template').
Having the .xhtml now in yout template/auth folder, you can modify them just like all your other templates.