Changeset 282
- Timestamp:
- 02/23/06 08:06:03 (3 years ago)
- Files:
-
- login_engine/branches/rb_1.0/CHANGELOG (deleted)
- login_engine/branches/rb_1.0/README (modified) (2 diffs)
- login_engine/branches/rb_1.0/app/controllers/user_controller.rb (modified) (3 diffs)
- login_engine/branches/rb_1.0/app/helpers/user_helper.rb (modified) (2 diffs)
- login_engine/branches/rb_1.0/app/views/user/edit.rhtml (modified) (1 diff)
- login_engine/branches/rb_1.0/db/migrate/001_initial_schema.rb (modified) (1 diff)
- login_engine/branches/rb_1.0/init_engine.rb (modified) (1 diff)
- login_engine/branches/rb_1.0/lib/login_engine.rb (modified) (2 diffs)
- login_engine/branches/rb_1.0/lib/login_engine/authenticated_system.rb (modified) (3 diffs)
- login_engine/branches/rb_1.0/lib/login_engine/authenticated_user.rb (modified) (1 diff)
- login_engine/branches/rb_1.0/test/functional/user_controller_test.rb (modified) (1 diff)
- login_engine/branches/rb_1.0/test/unit/user_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
login_engine/branches/rb_1.0/README
r201 r282 15 15 = Installation 16 16 17 Installing the Login Engine is fairly simple. You can use either Rails' own built in plugin manager (since Engines are still plugins), or SVN itself if you are happier with that. 18 19 === <tt>script/plugin</tt> 20 21 $ ruby script/plugin discover 22 $ ruby script/plugin install engines 23 $ ruby script/plugin install login_engine 24 25 === SVN 26 27 $ cd your_app_directory 28 % svn co http://opensvn.csie.org/rails_engines/plugins/engines 29 % svn co http://opensvn.csie.org/rails_engines/plugins/login_engine 30 17 Installing the Login Engine is fairly simple. You'll probably need to accept the SSL certificate here for the OpenSVN servers. For example: 18 $ script/plugin install login_engine 19 or 20 % svn co https://opensvn.csie.org/rails_engines/plugins/login_engine <MY_RAILS_APP>/vendor/plugins/login_engine 21 22 There are a few configuration steps that you'll need to take to get everything running smoothly. Listed below are the changes to your application you will need to make. 31 23 32 24 === Setup your Rails application 33 34 There are a few configuration steps that you'll need to take to get everything running smoothly. Listed below are the changes to your application you will need to make.35 25 36 26 Edit your <tt>database.yml</tt>, most importantly! You might also want to move <tt>public/index.html</tt> out of the way, and set up some default routes in <tt>config/routes.rb</tt>. … … 228 218 verified by email. This overrides the +user_email_notification+ flag. 229 219 Defaults to true. 230 +login_redirect+:: Determines how redirection will be done on login. This configuration option must 231 have one of three values: 232 <tt>:back</tt> will redirect back, or use the default value in <tt>:default_home</tt> 233 if no information about the previous URL is available. 234 <tt>:stored</tt> will redirect to the stored location, or the default value in 235 <tt>:default_home</tt>. This is the default if no option is given. 236 <tt>:default</tt> always redirects to the value of <tt>:default_home</tt>. 237 +default_home+:: Determines the target of the login redirection when back is not possible, or there are no 238 stored values. This must be a Hash of options or String, as used in +url_for+. 220 239 221 == Overriding controllers and views 240 222 login_engine/branches/rb_1.0/app/controllers/user_controller.rb
r246 r282 17 17 # trying to access. If not, they will be sent to "/user/home". 18 18 def login 19 # get the previous page before any redirection happened here20 if request.get? and :back == LoginEngine.config(:login_redirect)21 session['back-to'] = request.env['HTTP_REFERER']22 end23 24 19 return if generate_blank 25 20 @user = User.new(params[:user]) … … 28 23 session[:user].save 29 24 flash[:notice] = 'Login successful' 30 31 case LoginEngine.config(:login_redirect) 32 when :back 33 # we have stored the 'back' link, so we should send them to whatever page they 34 # were at *before* they clicked 'login'. 35 redirect_to session['back-to'] || LoginEngine.default_home 36 session['back-to'] = nil 37 38 when :default 39 # whenever someone logs in, we always want to send them to the homepage 40 redirect_to LoginEngine.default_home 41 42 else 43 # they got sent to login because of an unauthorised action, so we should have 44 # the location stored anyway. 45 redirect_to_stored_or_default 46 end 47 25 redirect_to_stored_or_default :action => 'home' 48 26 else 49 27 @login = params[:user][:login] … … 209 187 end 210 188 else 211 destroy( user)189 destroy(@user) 212 190 end 213 191 return true login_engine/branches/rb_1.0/app/helpers/user_helper.rb
r269 r282 30 30 <<-EOL 31 31 <tr class="two_columns"> 32 <td class="prompt"><label for="#{form_name}_#{field_name}">#{prompt}:</label></td>32 <td class="prompt"><label>#{prompt}:</label></td> 33 33 <td class="value">#{field}</td> 34 34 </tr> … … 36 36 else 37 37 <<-EOL 38 <tr><td class="prompt"><label for="#{form_name}_#{field_name}">#{prompt}:</label></td></tr>38 <tr><td class="prompt"><label>#{prompt}:</label></td></tr> 39 39 <tr><td class="value">#{field}</td></tr> 40 40 EOL login_engine/branches/rb_1.0/app/views/user/edit.rhtml
r244 r282 4 4 <%= error_messages_for 'user' %> 5 5 6 <%= start_form_tag :action => 'edit' %>7 <%= render_partial 'edit', :user => @user, :submit => true %>8 <%= end_form_tag %>9 <br/>10 <%= start_form_tag :action => 'change_password' %>11 <%= hidden_field_tag "back_to", "edit" %>12 <%= render_partial 'password', :submit => true %>13 <%= end_form_tag %>6 <%= start_form_tag :action => 'edit' %> 7 <%= render_partial 'edit', :user => @user, :submit => true %> 8 <%= end_form_tag %> 9 <br/> 10 <%= start_form_tag :action => 'change_password' %> 11 <%= hidden_field_tag "back_to", "edit" %> 12 <%= render_partial 'password', :submit => true %> 13 <%= end_form_tag %> 14 14 15 <%= start_form_tag :action => 'delete' %>16 <div class="user_delete">17 <%= hidden_field 'user', 'form', :value => 'delete' %>15 <%= start_form_tag :action => 'delete' %> 16 <div class="user_delete"> 17 <%= hidden_field 'user', 'form', :value => 'delete' %> 18 18 19 <%= form_input :submit_button, 'Delete Account' %> 20 </div> 21 <%= end_form_tag %> 19 <%= form_input :submit_button, 'Delete Account' %> 20 </div> 21 <%= end_form_tag %> 22 </div> 22 23 </div> login_engine/branches/rb_1.0/db/migrate/001_initial_schema.rb
r268 r282 1 1 class InitialSchema < ActiveRecord::Migration 2 2 def self.up 3 # NOTE that we don't need to wrap the table name here, since Migrations4 # will do it whether we want it to or not.5 3 create_table LoginEngine.config(:user_table), :force => true do |t| 6 4 t.column "login", :string, :limit => 80, :default => "", :null => false login_engine/branches/rb_1.0/init_engine.rb
r268 r282 3 3 require 'login_engine' 4 4 5 module ::LoginEngine::Version 6 Major = 1 # change implies compatibility breaking with previous versions 7 Minor = 0 # change implies backwards-compatible change to API 8 Release = 1 # incremented with bug-fixes, updates, etc. 9 end 5 # TODO: why do I have to include these here, when including them in login_engine.rb should be sufficient? 6 require 'authenticated_user' 7 require 'authenticated_system' 10 8 11 Engines.current.version = LoginEngine::Version12 13 # send the helpers and modules automatically....?14 9 #ApplicationController.send(:include, LoginEngine) 15 10 #ApplicationHelper.send(:include, LoginEngine) login_engine/branches/rb_1.0/lib/login_engine.rb
r268 r282 52 52 config :user_table, "user" 53 53 end 54 54 55 55 # controls whether or not email is used 56 56 config :use_email_notification, true … … 60 60 config :confirm_account, true 61 61 62 # Sets the default URL to send users to when they have logged in63 config :login_redirect, :stored64 65 # The default 'home' location66 config :default_home, {:controller => 'user', :action => 'home'}67 68 62 end login_engine/branches/rb_1.0/lib/login_engine/authenticated_system.rb
r201 r282 74 74 75 75 # move to the last store_location call or to the passed default one 76 def redirect_to_stored_or_default(default= default_home)76 def redirect_to_stored_or_default(default=nil) 77 77 if session['return-to'].nil? 78 78 redirect_to default … … 83 83 end 84 84 85 def redirect_back_or_default(default= default_home)85 def redirect_back_or_default(default=nil) 86 86 if request.env["HTTP_REFERER"].nil? 87 87 redirect_to default … … 89 89 redirect_to(request.env["HTTP_REFERER"]) # same as redirect_to :back 90 90 end 91 end92 93 def default_home94 case LoginEngine.config(:default_home)95 when Hash96 url_for LoginEngine.config(:default_home)97 when String98 LoginEngine.config(:default_home)99 else100 # last ditch attempt - this would only happen if the user has101 # set the config value to something REALLY weird.102 url_for :controller => 'user', :action => 'home'103 end104 91 end 105 92 login_engine/branches/rb_1.0/lib/login_engine/authenticated_user.rb
r268 r282 9 9 base.class_eval do 10 10 11 # use the table name given. NOTE that this will wrap the table name 12 # using the set prefix/suffix. TODO: this behaviour isn't ideal, but it 13 # is necessary since migrations will ALWAYS wrap using the prefix/suffix. 14 # To explicitly and COMPLETELY set a unique table name, create a version 15 # of the User model in your own application and use set_table_name there. 16 set_table_name wrapped_table_name(LoginEngine.config(:user_table)) 11 # use the table name given 12 set_table_name LoginEngine.config(:user_table) 17 13 18 14 attr_accessor :new_password 19 15 16 validates_presence_of :login 20 17 validates_length_of :login, :within => 3..40 21 18 validates_uniqueness_of :login 22 19 validates_uniqueness_of :email 23 20 21 validates_presence_of :password, :if => :validate_password? 24 22 validates_confirmation_of :password, :if => :validate_password? 25 23 validates_length_of :password, { :minimum => 5, :if => :validate_password? } login_engine/branches/rb_1.0/test/functional/user_controller_test.rb
r268 r282 10 10 # load the fixture into the developer-specified table using the custom 11 11 # 'fixture' method. 12 fixture :users, :class_name => "User", 13 :table_name => ActiveRecord::Base.wrapped_table_name(LoginEngine.config(:user_table)) 12 fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User" 14 13 15 14 def setup login_engine/branches/rb_1.0/test/unit/user_test.rb
r268 r282 3 3 4 4 # load the fixture into the developer-specified table using the custom 5 # 'fixture' method. Note that it is necessary at the moment to explicitly 6 # wrap the table name. TODO: determine the table name from the Class object. 7 fixture :users, :class_name => "User", 8 :table_name => ActiveRecord::Base.wrapped_table_name(LoginEngine.config(:user_table)) 5 # 'fixture' method. 6 fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User" 9 7 10 8 def setup
