Skip to content

Commit

Permalink
Lwt => Mhs
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholstyn committed Mar 22, 2008
1 parent d49a7a9 commit 794e443
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 117 deletions.
2 changes: 1 addition & 1 deletion README
@@ -1,4 +1,4 @@
LwtAuthenticationSystem
MhsAuthenticationSystem
=======================

This authentication system allows for an easy, plug and play solution
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -5,16 +5,16 @@ require 'spec/rake/spectask'
desc 'Default: run specs.'
task :default => :spec

desc 'Run specs for the lwt_authentication_system plugin.'
desc 'Run specs for the mhs_authentication_system plugin.'
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_opts = ['--options', %Q{#{File.join(File.dirname(__FILE__), '../../../spec/spec.opts')}}]
t.spec_files = FileList['spec/**/*_spec.rb']
end

desc 'Generate documentation for the lwt_authentication_system plugin.'
desc 'Generate documentation for the mhs_authentication_system plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'LwtAuthenticationSystem'
rdoc.title = 'MhsAuthenticationSystem'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
Expand Down
6 changes: 3 additions & 3 deletions generators/lwt_authentication_system/USAGE
@@ -1,14 +1,14 @@
Description:
The generator will create the default files necessary to get the lwt_authentication_system up and running.
The generator will create the default files necessary to get the mhs_authentication_system up and running.

Example:
./script/generate lwt_authentication_system
./script/generate mhs_authentication_system

This will create:
Model: app/models/user.rb
Controller: app/controller/users_controller.rb
View: app/view/users/login.erb
Migration: db/migrate/XXX_add_lwt_authentication_system.rb
Migration: db/migrate/XXX_add_mhs_authentication_system.rb
Fixtures: test/fixtures/privileges.yml
test/fixtures/groups.yml
test/fixtures/groups_privileges.yml
Expand Down
@@ -1,4 +1,4 @@
class LwtAuthenticationSystemGenerator < Rails::Generator::Base
class MhsAuthenticationSystemGenerator < Rails::Generator::Base

#TODO: update classes of they exists?
#TODO: Add routes?
Expand All @@ -23,7 +23,7 @@ def manifest
m.template 'spec/fixtures/groups_privileges.yml', File.join( *%w{ spec fixtures groups_privileges.yml } )
m.template 'spec/fixtures/privileges.yml', File.join( *%w{ spec fixtures privileges.yml } )
m.template 'spec/fixtures/users.yml', File.join( *%w{ spec fixtures users.yml } )
m.migration_template 'db/migrate/migration.rb', File.join( *%w{ db migrate } ), :migration_file_name => "add_lwt_authentication_system"
m.migration_template 'db/migrate/migration.rb', File.join( *%w{ db migrate } ), :migration_file_name => "add_mhs_authentication_system"
end
end
end
@@ -1,4 +1,4 @@
class AddLwtAuthenticationSystem < ActiveRecord::Migration
class AddMhsAuthenticationSystem < ActiveRecord::Migration
def self.up
create_table :groups do |t|
t.string :name
Expand Down
6 changes: 3 additions & 3 deletions init.rb
Expand Up @@ -8,6 +8,6 @@
require File.join( dir, 'group_privilege_model' )
require File.join( dir, 'user_reminder_model' )
require File.join( dir, 'user_reminder_mailer_model' )
ActiveRecord::Base.send :include, LWT::AuthenticationSystem::Model
ActionController::Base.send :include, LWT::AuthenticationSystem::Controller
ActionController::Base.send :include, LWT::AuthenticationSystem::LoginController
ActiveRecord::Base.send :include, Mhs::AuthenticationSystem::Model
ActionController::Base.send :include, Mhs::AuthenticationSystem::Controller
ActionController::Base.send :include, Mhs::AuthenticationSystem::LoginController
2 changes: 1 addition & 1 deletion lib/controller.rb
@@ -1,4 +1,4 @@
module LWT
module Mhs
module AuthenticationSystem
module Controller

Expand Down
74 changes: 37 additions & 37 deletions lib/login_controller.rb
@@ -1,4 +1,4 @@
module LWT
module Mhs
module AuthenticationSystem
module LoginController

Expand All @@ -9,8 +9,8 @@ def self.included base #:nodoc:
# These methods are added to ActionController::Base
module ClassMethods
# Sets up this controller as a login controller. The following thigs are done:
# * Adds methods from LWT::AuthenticationSystem::LoginController::InstanceMethods
# * Adds methods from LWT::AuthenticationSystem::LoginController::SingletonMethods
# * Adds methods from Mhs::AuthenticationSystem::LoginController::InstanceMethods
# * Adds methods from Mhs::AuthenticationSystem::LoginController::SingletonMethods
#
# Valid options:
# - :login_flash - This is the message stored in flash[:notice] when
Expand All @@ -23,10 +23,10 @@ module ClassMethods
# the page they initially requested rather then the page defined by the
# after_login_redirect. Defatut: true
def acts_as_login_controller( options = {} )
include LWT::AuthenticationSystem::LoginController::InstanceMethods
extend LWT::AuthenticationSystem::LoginController::SingletonMethods
include Mhs::AuthenticationSystem::LoginController::InstanceMethods
extend Mhs::AuthenticationSystem::LoginController::SingletonMethods

self.lwt_authentication_system_options = {
self.mhs_authentication_system_options = {
:login_flash => "Please login",
:invalid_login_flash => "Invalid login credentials",
:inactive_login_flash => "Your account has not been activated",
Expand All @@ -44,8 +44,8 @@ def acts_as_login_controller( options = {} )
:track_pre_login_url => true
}.merge( options )

if lwt_authentication_system_options[:allow_signup]
include LWT::AuthenticationSystem::LoginController::SignupInstanceMethods
if mhs_authentication_system_options[:allow_signup]
include Mhs::AuthenticationSystem::LoginController::SignupInstanceMethods
end

after_successful_signup do ; end
Expand All @@ -62,7 +62,7 @@ def acts_as_login_controller( options = {} )
end

module SingletonMethods
attr_accessor :lwt_authentication_system_options
attr_accessor :mhs_authentication_system_options

# Update restrict_to to automatically ignore the login, logout, reminder, profile, and signup actions
def restrict_to *privileges, &blk
Expand All @@ -81,36 +81,36 @@ def restrict_to *privileges, &blk
# successfully logs in. The block will be evaluated in the scope
# of the controller.
def redirect_after_login &blk
self.lwt_authentication_system_options[:redirect_after_login] = blk
self.mhs_authentication_system_options[:redirect_after_login] = blk
end

# Sets the arguments to be passed to redirect_to after a user
# successfully logs in. The block will be evaluated in the scope
# of the controller.
def redirect_after_reminder_login &blk
self.lwt_authentication_system_options[:redirect_after_reminder_login] = blk
self.mhs_authentication_system_options[:redirect_after_reminder_login] = blk
end

# Sets the arguments to be passed to redirect_to after a user
# successfully logs out. The block will be evaluated in the scope
# of the controller.
def redirect_after_logout &blk
self.lwt_authentication_system_options[:redirect_after_logout] = blk
self.mhs_authentication_system_options[:redirect_after_logout] = blk
end

def after_successful_signup &blk
self.lwt_authentication_system_options[:after_successful_signup] = blk
self.mhs_authentication_system_options[:after_successful_signup] = blk
end

def after_failed_signup &blk
self.lwt_authentication_system_options[:after_failed_signup] = blk
self.mhs_authentication_system_options[:after_failed_signup] = blk
end

# Sets the arguments to be passed to redirect_to after a user
# successfully signs up. The block will be evaluated in the scope
# of the controller.
def redirect_after_signup &blk
self.lwt_authentication_system_options[:redirect_after_signup] = blk
self.mhs_authentication_system_options[:redirect_after_signup] = blk
end
end

Expand All @@ -136,10 +136,10 @@ def login
do_redirect_after_login
return
else
flash.now[:error] = self.class.lwt_authentication_system_options[:inactive_login_flash]
flash.now[:error] = self.class.mhs_authentication_system_options[:inactive_login_flash]
end
else
flash.now[:error] = self.class.lwt_authentication_system_options[:invalid_login_flash]
flash.now[:error] = self.class.mhs_authentication_system_options[:invalid_login_flash]
end
elsif params[:id] and params[:token] and reminder = UserReminder.find(:first, :conditions => [ "user_id = ? AND token = ? AND expires_at >= ? ", params[:id], params[:token], Time.now ])
model = self.class.login_model.find( reminder.user_id )
Expand All @@ -152,7 +152,7 @@ def login
return
else
instance_variable_set( "@#{self.class.login_model_name}", self.class.login_model.new )
flash.now[:notice] ||= self.class.lwt_authentication_system_options[:login_flash]
flash.now[:notice] ||= self.class.mhs_authentication_system_options[:login_flash]
end
end

Expand All @@ -162,26 +162,26 @@ def logout
current_user.forget_me!
cookies.delete(:remember_me_token)
set_current_user nil
redirect_to self.instance_eval( &self.class.lwt_authentication_system_options[:redirect_after_logout] )
redirect_to self.instance_eval( &self.class.mhs_authentication_system_options[:redirect_after_logout] )
end

def reminder
if request.post?
email_address = params[self.class.login_model_name.to_sym][:email_address]
if email_address.blank? || ( model = self.class.login_model.find_by_email_address( email_address ) ).nil?
flash.now[:error] = self.class.lwt_authentication_system_options[:reminder_error_flash]
flash.now[:error] = self.class.mhs_authentication_system_options[:reminder_error_flash]
else
reminder = UserReminder.create_for_user( model, Time.now + self.class.lwt_authentication_system_options[:reminder_login_duration] )
reminder = UserReminder.create_for_user( model, Time.now + self.class.mhs_authentication_system_options[:reminder_login_duration] )
url = url_for(:action => 'login', :id => model, :token => reminder.token)
UserReminderMailer.deliver_reminder(model, reminder, url,
:from => self.class.lwt_authentication_system_options[:email_from],
:subject => self.class.lwt_authentication_system_options[:reminder_email_subject] )
flash[:notice] = self.class.lwt_authentication_system_options[:reminder_success_flash]
:from => self.class.mhs_authentication_system_options[:email_from],
:subject => self.class.mhs_authentication_system_options[:reminder_email_subject] )
flash[:notice] = self.class.mhs_authentication_system_options[:reminder_success_flash]
redirect_to :action => "login"
end
else
instance_variable_set( "@#{self.class.login_model_name}", self.class.login_model.new )
flash.now[:notice] = self.class.lwt_authentication_system_options[:reminder_flash]
flash.now[:notice] = self.class.mhs_authentication_system_options[:reminder_flash]
end
end

Expand All @@ -208,19 +208,19 @@ def profile

private
def do_redirect_after_reminder_login
if blk = self.class.lwt_authentication_system_options[:redirect_after_reminder_login]
if blk = self.class.mhs_authentication_system_options[:redirect_after_reminder_login]
redirect_to self.instance_eval( &blk )
else
do_redirect_after_login
end
end

def do_redirect_after_login
if self.class.lwt_authentication_system_options[:track_pre_login_url] and session[:pre_login_url]
if self.class.mhs_authentication_system_options[:track_pre_login_url] and session[:pre_login_url]
redirect_to session[:pre_login_url]
session[:pre_login_url] = nil
else
redirect_to self.instance_eval( &self.class.lwt_authentication_system_options[:redirect_after_login] )
redirect_to self.instance_eval( &self.class.mhs_authentication_system_options[:redirect_after_login] )
end
end
end
Expand All @@ -229,21 +229,21 @@ module SignupInstanceMethods
def signup
instance_variable_set( "@#{self.class.login_model_name}", model = self.class.login_model.new( params[self.class.login_model_name.to_sym] ) )
if request.post?
model.active = self.class.lwt_authentication_system_options[:require_activation] ? false : true
model.active = self.class.mhs_authentication_system_options[:require_activation] ? false : true
if model.save
reminder = UserReminder.create_for_user( model, Time.now + self.class.lwt_authentication_system_options[:reminder_login_duration] )
reminder = UserReminder.create_for_user( model, Time.now + self.class.mhs_authentication_system_options[:reminder_login_duration] )
url = url_for(:action => 'login', :id => model, :token => reminder.token)
UserReminderMailer.deliver_signup(model, reminder, url,
:from => self.class.lwt_authentication_system_options[:email_from],
:subject => self.class.lwt_authentication_system_options[:signup_email_subject] )
flash[:notice] = self.class.lwt_authentication_system_options[:successful_signup_flash]
instance_eval &self.class.lwt_authentication_system_options[:after_successful_signup]
redirect_to self.instance_eval( &self.class.lwt_authentication_system_options[:redirect_after_signup] )
:from => self.class.mhs_authentication_system_options[:email_from],
:subject => self.class.mhs_authentication_system_options[:signup_email_subject] )
flash[:notice] = self.class.mhs_authentication_system_options[:successful_signup_flash]
instance_eval &self.class.mhs_authentication_system_options[:after_successful_signup]
redirect_to self.instance_eval( &self.class.mhs_authentication_system_options[:redirect_after_signup] )
else
instance_eval &self.class.lwt_authentication_system_options[:after_failed_signup]
instance_eval &self.class.mhs_authentication_system_options[:after_failed_signup]
end
else
flash[:notice] = self.class.lwt_authentication_system_options[:signup_flash]
flash[:notice] = self.class.mhs_authentication_system_options[:signup_flash]
end
end
end
Expand Down
26 changes: 13 additions & 13 deletions lib/model.rb
@@ -1,4 +1,4 @@
module LWT
module Mhs
module AuthenticationSystem
module Model

Expand All @@ -17,8 +17,8 @@ module ClassMethods
# * sets up after_validation callbacks to clear password and password_confirmation.
# If there were no errors on password, they password_hash will be set to the hash
# value of password
# * Adds methods from LWT::AuthenticationSystem::Model::InstanceMethods
# * Adds methods from LWT::AuthenticationSystem::Model::SingletonMethods
# * Adds methods from Mhs::AuthenticationSystem::Model::InstanceMethods
# * Adds methods from Mhs::AuthenticationSystem::Model::SingletonMethods
#
# Valid options:
# - :password_validation - Error message used when the passwords do not match.
Expand All @@ -31,10 +31,10 @@ module ClassMethods
# already in use. If this check is not desired, set to false or nil.
# Default: "has already been taken"
def acts_as_login_model options = {}
extend LWT::AuthenticationSystem::Model::SingletonMethods
include LWT::AuthenticationSystem::Model::InstanceMethods
extend Mhs::AuthenticationSystem::Model::SingletonMethods
include Mhs::AuthenticationSystem::Model::InstanceMethods

self.lwt_authentication_system_options = {
self.mhs_authentication_system_options = {
:group_validation => "can't be blank",
:password_validation => "must match",
:email_address_validation => "can't be blank",
Expand All @@ -48,19 +48,19 @@ def acts_as_login_model options = {}

belongs_to :group

if msg = lwt_authentication_system_options[:group_validation]
if msg = mhs_authentication_system_options[:group_validation]
validates_presence_of :group_id, :message => msg
end

if msg = lwt_authentication_system_options[:email_address_validation]
if msg = mhs_authentication_system_options[:email_address_validation]
validates_presence_of :email_address, :message => msg
end

if msg = lwt_authentication_system_options[:email_address_unique_validation]
if msg = mhs_authentication_system_options[:email_address_unique_validation]
validates_uniqueness_of :email_address, :message => msg
end

if msg = self.lwt_authentication_system_options[:password_validation]
if msg = self.mhs_authentication_system_options[:password_validation]
validate do |user|
if ( user.instance_variable_get( "@password" ) or user.instance_variable_get( "@password_confirmation" ) ) &&
user.instance_variable_get( "@password" ) != user.instance_variable_get( "@password_confirmation" )
Expand All @@ -83,7 +83,7 @@ def acts_as_login_model options = {}
end

module SingletonMethods
attr_accessor :current_user, :lwt_authentication_system_options
attr_accessor :current_user, :mhs_authentication_system_options

# Attempts to find a user by the passed in attributes. The param :password will
# be removed and will be checked against the password of the user found (if any).
Expand All @@ -99,9 +99,9 @@ def login params
# - Else, the stored block is called, giving passing it all arguments
def hash_password( *args, &blk )
if blk
self.lwt_authentication_system_options[:hash_password] = blk
self.mhs_authentication_system_options[:hash_password] = blk
else
self.lwt_authentication_system_options[:hash_password].call *args
self.mhs_authentication_system_options[:hash_password].call *args
end
end
end
Expand Down

0 comments on commit 794e443

Please sign in to comment.