Changeset 127
- Timestamp:
- 11/21/05 02:29:53 (3 years ago)
- Files:
-
- plugins/login_engine/README (modified) (3 diffs)
- plugins/login_engine/app/controllers/user_controller.rb (modified) (4 diffs)
- plugins/login_engine/db/migrate (copied) (copied from branches/login_engine/db/migrate)
- plugins/login_engine/db/migrate/001_initial_schema.rb (copied) (copied from branches/login_engine/db/migrate/001_initial_schema.rb)
- plugins/login_engine/lib/login_engine.rb (modified) (1 diff)
- plugins/login_engine/lib/login_engine/authenticated_system.rb (modified) (1 diff)
- plugins/login_engine/lib/login_engine/authenticated_user.rb (modified) (2 diffs)
- plugins/login_engine/test/fixtures/templates (deleted)
- plugins/login_engine/test/fixtures/users.yml (copied) (copied from branches/login_engine/test/fixtures/users.yml)
- plugins/login_engine/test/functional/user_controller_test.rb (modified) (9 diffs)
- plugins/login_engine/test/test_helper.rb (modified) (2 diffs)
- plugins/login_engine/test/unit/user_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/login_engine/README
r95 r127 91 91 === Create the DB schema 92 92 93 After you have done the modifications the the ApplicationController and its helper, you can import the user model into the database. An ActiveRecord schema.rb file is provided in login_engine/db/schema.rb. You should check that this file isn't going to interfere with anything in your application. You can set the table name used by adding 93 After you have done the modifications the the ApplicationController and its helper, you can import the user model into the database. An ActiveRecord schema.rb file is provided in login_engine/db/schema.rb, along with migration information in login_engine/db/migrate/. 94 95 You *MUST* check that these files aren't going to interfere with anything in your application. 96 97 You can change the table name used by adding 94 98 95 99 module LoginEngine … … 100 104 end 101 105 102 To the LoginEngine configuration in <tt>environment.rb</tt>. Then run from the root of your project:103 104 rake import_login_engine_schema106 ...to the LoginEngine configuration in <tt>environment.rb</tt>. Then run from the root of your project: 107 108 rake engine_migrate ENGINE=login 105 109 106 110 to import the schema into your database. … … 115 119 ... somewhere in the <head> section of your HTML layout file. 116 120 121 == Integrate flash messages into your layout 122 123 LoginEngine does not display any flash messages in the views it contains, and thus you must display them yourself. This allows you to integrate any flash messages into your existing layout. LoginEngine adheres to the emerging flash usage standard, namely: 124 125 * :warning - warning (failure) messages 126 * :notice - success messages 127 * :message - neutral (reminder, informational) messages 128 129 This gives you the flexibility to theme the different message classes separately. In your layout you should check for and display flash[:warning], flash[:notice] and flash[:message]. For example: 130 131 <% for name in [:notice, :warning, :message] %> 132 <% if flash[name] %> 133 <%= "<div id=\"#{name}\">#{flash[name]}</div>" %> 134 <% end %> 135 <% end %> 136 137 Alternately, you could look at using the flash helper plugin (available from https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/), which supports the same naming convention. 117 138 118 139 plugins/login_engine/app/controllers/user_controller.rb
r96 r127 39 39 User.transaction(@user) do 40 40 @user.new_password = true 41 unless LoginEngine.config(:use_email_notification) 41 unless LoginEngine.config(:use_email_notification) and LoginEngine.config(:confirm_account) 42 42 @user.verified = 1 43 43 end 44 44 if @user.save 45 45 key = @user.generate_security_token 46 url = url_for(:action => 'home', 'user[id]'=> @user.id, :key => key)46 url = url_for(:action => 'home', :user_id => @user.id, :key => key) 47 47 flash[:notice] = 'Signup successful! Please log in.' 48 if LoginEngine.config(:use_email_notification) 48 if LoginEngine.config(:use_email_notification) and LoginEngine.config(:confirm_account) 49 49 UserNotify.deliver_signup(@user, params[:user][:password], url) 50 50 flash[:notice] << ' Please check your registered email account to verify your account registration and continue with the login.' … … 56 56 flash.now[:notice] = nil 57 57 flash.now[:warning] = 'Error creating account: confirmation email not sent' 58 logger.error "Unable to send confirmation E-Mail:" 58 59 logger.error e 59 60 end … … 127 128 User.transaction(user) do 128 129 key = user.generate_security_token 129 url = url_for(:action => 'change_password', 'user[id]'=> user.id, :key => key)130 url = url_for(:action => 'change_password', :user_id => user.id, :key => key) 130 131 UserNotify.deliver_forgot_password(user, url) 131 132 flash[:notice] = "Instructions on resetting your password have been emailed to #{params[:user][:email]}" … … 181 182 key = user.set_delete_after 182 183 if LoginEngine.config(:use_email_notification) 183 url = url_for(:action => 'restore_deleted', 'user[id]'=> user.id, :key => key)184 url = url_for(:action => 'restore_deleted', :user_id => user.id, :key => key) 184 185 UserNotify.deliver_pending_delete(user, url) 185 186 end plugins/login_engine/lib/login_engine.rb
r66 r127 56 56 config :use_email_notification, true 57 57 58 # Controls whether accounts must be confirmed after signing up 59 # ONLY if this and use_email_notification are both true 60 config :confirm_account, true 61 58 62 end plugins/login_engine/lib/login_engine/authenticated_system.rb
r96 r127 96 96 97 97 # If not, is the user being authenticated by a token? 98 return false if not params[:user] 99 id = params[:user][:id] 98 id = params[:user_id] 100 99 key = params[:key] 101 100 if id and key plugins/login_engine/lib/login_engine/authenticated_user.rb
r62 r127 38 38 39 39 def authenticate(login, pass) 40 u = find _first(["login = ? AND verified = 1 AND deleted = 0", login])40 u = find(:first, :conditions => ["login = ? AND verified = 1 AND deleted = 0", login]) 41 41 return nil if u.nil? 42 find _first(["login = ? AND salted_password = ? AND verified = 1", login, AuthenticatedUser.salted_password(u.salt, AuthenticatedUser.hashed(pass))])42 find(:first, :conditions => ["login = ? AND salted_password = ? AND verified = 1", login, AuthenticatedUser.salted_password(u.salt, AuthenticatedUser.hashed(pass))]) 43 43 end 44 44 … … 46 46 # Allow logins for deleted accounts, but only via this method (and 47 47 # not the regular authenticate call) 48 u = find _first(["id = ? AND security_token = ?", id, token])48 u = find(:first, :conditions => ["id = ? AND security_token = ?", id, token]) 49 49 return nil if u.nil? or u.token_expired? 50 50 return nil if false == u.update_expiry plugins/login_engine/test/functional/user_controller_test.rb
r88 r127 1 1 require File.dirname(__FILE__) + '/../test_helper' 2 2 require_dependency 'user_controller' 3 require 'breakpoint'4 3 5 4 … … 9 8 class UserControllerTest < Test::Unit::TestCase 10 9 11 fixtures LoginEngine.config(:user_table).to_sym 10 # load the fixture into the developer-specified table using the custom 11 # 'fixture' method. 12 fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User" 12 13 13 14 def setup … … 48 49 assert_response 302 # redirect 49 50 assert_session_has :user 50 assert_equal fixture_object(LoginEngine.config(:user_table).to_sym,:bob), session[:user]51 assert_equal users(:bob), session[:user] 51 52 52 53 assert_redirect_url "http://#{@request.host}/bogus/location" … … 87 88 assert_match /login:\s+\w+\n/, mail.encoded 88 89 assert_match /password:\s+\w+\n/, mail.encoded 89 mail.encoded =~ /key=(.*?)"/ 90 key = $1 90 mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 91 user_id = $1 92 key = $2 91 93 92 94 user = User.find_by_email("newbob@test.com") … … 96 98 # First past the expiration. 97 99 Time.advance_by_days = 1 98 get :home, :user => { "id" => "#{user.id}" }, "key"=> "#{key}"100 get :home, :user_id => "#{user_id}", :key => "#{key}" 99 101 Time.advance_by_days = 0 100 102 user = User.find_by_email("newbob@test.com") … … 102 104 103 105 # Then a bogus key. 104 get :home, :user => { "id" => "#{user.id}" }, "key"=> "boguskey"106 get :home, :user_id => "#{user_id}", :key => "boguskey" 105 107 user = User.find_by_email("newbob@test.com") 106 108 assert_equal 0, user.verified 107 109 108 110 # Now the real one. 109 get :home, :user => { "id" => "#{user.id}" }, "key"=> "#{key}"111 get :home, :user_id => "#{user_id}", :key => "#{key}" 110 112 user = User.find_by_email("newbob@test.com") 111 113 assert_equal 1, user.verified … … 247 249 assert_equal 1, ActionMailer::Base.deliveries.size 248 250 mail = ActionMailer::Base.deliveries[0] 249 mail.encoded =~ /user \[id\]=(.*?)&key=(.*?)"/251 mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 250 252 id = $1 251 253 key = $2 252 254 253 post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "badkey"255 post :restore_deleted, :user_id => "#{id}", "key" => "badkey" 254 256 assert_session_has_no :user 255 257 256 258 # Advance the time past the delete date 257 259 Time.advance_by_days = LoginEngine.config :delayed_delete_days 258 post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "#{key}"260 post :restore_deleted, :user_id => "#{id}", "key" => "#{key}" 259 261 assert_session_has_no :user 260 262 Time.advance_by_days = 0 261 263 262 post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "#{key}"264 post :restore_deleted, :user_id => "#{id}", "key" => "#{key}" 263 265 assert_session_has :user 264 266 end … … 342 344 post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" } 343 345 344 assert_ success346 assert_redirected_to :action => "change_password" 345 347 346 348 post :login, :user => { :login => "bob", :password => "changed_password" } … … 453 455 mail = ActionMailer::Base.deliveries[0] 454 456 assert_equal "bob@test.com", mail.to_addrs[0].to_s 455 mail.encoded =~ /user \[id\]=(.*?)&key=(.*?)"/457 mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 456 458 id = $1 457 459 key = $2 458 post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}" , :id => "#{id}" }, :key => "#{key}"460 post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}"}, :user_id => "#{id}", :key => "#{key}" 459 461 assert_session_has :user 460 462 get :logout plugins/login_engine/test/test_helper.rb
r83 r127 1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper' # the default rails helper 2 3 # ensure that the Engines testing enhancements are loaded. 4 require File.join(Engines.config(:root), "engines", "lib", "testing_extensions") 2 5 3 6 require File.dirname(__FILE__) + '/mocks/time' 4 7 require File.dirname(__FILE__) + '/mocks/mail' 5 8 6 # TODO: Add check for database-specific sql files instead9 # Load the schema - if migrations have been performed, this will be up to date. 7 10 load(File.dirname(__FILE__) + "/../db/schema.rb") 8 11 … … 10 13 Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/" 11 14 $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path) 12 13 14 # declare mappings between your fixtures templates and the actual table names used.15 Test::Unit::TestCase.set_fixtures_table(:users, LoginEngine.config(:user_table))plugins/login_engine/test/unit/user_test.rb
r89 r127 1 1 require File.dirname(__FILE__) + '/../test_helper' 2 class UserTest < Test::Unit::TestCase 2 3 3 class UserTest < Test::Unit::TestCase 4 5 fixture s LoginEngine.config(:user_table).to_sym4 # load the fixture into the developer-specified table using the custom 5 # 'fixture' method. 6 fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User" 6 7 7 8 def setup … … 10 11 11 12 def test_auth 12 assert_equal fixture_object(LoginEngine.config(:user_table),:bob), User.authenticate("bob", "atest")13 assert_equal users(:bob), User.authenticate("bob", "atest") 13 14 assert_nil User.authenticate("nonbob", "atest") 14 15 end … … 17 18 def test_passwordchange 18 19 19 fixture_object(LoginEngine.config(:user_table),:longbob).change_password("nonbobpasswd")20 fixture_object(LoginEngine.config(:user_table),:longbob).save21 assert_equal fixture_object(LoginEngine.config(:user_table),:longbob), User.authenticate("longbob", "nonbobpasswd")20 users(:longbob).change_password("nonbobpasswd") 21 users(:longbob).save 22 assert_equal users(:longbob), User.authenticate("longbob", "nonbobpasswd") 22 23 assert_nil User.authenticate("longbob", "alongtest") 23 fixture_object(LoginEngine.config(:user_table),:longbob).change_password("alongtest")24 fixture_object(LoginEngine.config(:user_table),:longbob).save25 assert_equal fixture_object(LoginEngine.config(:user_table),:longbob), User.authenticate("longbob", "alongtest")24 users(:longbob).change_password("alongtest") 25 users(:longbob).save 26 assert_equal users(:longbob), User.authenticate("longbob", "alongtest") 26 27 assert_nil User.authenticate("longbob", "nonbobpasswd") 27 28
