diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-05-10 20:48:41 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-05-20 17:03:03 +0200 |
commit | 2c4affa23f43e8ccff5508fc6582c84724d80fac (patch) | |
tree | 5e2470956e7a90a72f369d1c64325478d600b4b4 | |
parent | Add irc_nick field to User model (diff) | |
download | council-webapp-2c4affa23f43e8ccff5508fc6582c84724d80fac.tar.gz council-webapp-2c4affa23f43e8ccff5508fc6582c84724d80fac.tar.bz2 council-webapp-2c4affa23f43e8ccff5508fc6582c84724d80fac.zip |
Use hobo_devise to manage users login
-rw-r--r-- | site/Gemfile | 2 | ||||
-rw-r--r-- | site/Gemfile.lock | 48 | ||||
-rw-r--r-- | site/app/mailers/user_mailer.rb | 2 | ||||
-rw-r--r-- | site/app/models/user.rb | 8 | ||||
-rw-r--r-- | site/config/initializers/devise.rb | 1 | ||||
-rw-r--r-- | site/db/schema.rb | 4 | ||||
-rw-r--r-- | site/features/login.feature | 20 | ||||
-rw-r--r-- | site/features/step_definitions/login_steps.rb | 12 |
8 files changed, 87 insertions, 10 deletions
diff --git a/site/Gemfile b/site/Gemfile index 7a4edfc..3898aca 100644 --- a/site/Gemfile +++ b/site/Gemfile @@ -1,6 +1,8 @@ source 'http://rubygems.org' gem 'rails', '3.0.3' gem 'sqlite3-ruby', :require => 'sqlite3' +gem 'devise' +gem 'hobo_devise', '>=0.0.2' group :development, :test do gem 'ruby-debug' diff --git a/site/Gemfile.lock b/site/Gemfile.lock index b3ff31a..cc828d7 100644 --- a/site/Gemfile.lock +++ b/site/Gemfile.lock @@ -28,7 +28,9 @@ GEM activemodel (= 3.0.3) activesupport (= 3.0.3) activesupport (3.0.3) + addressable (2.2.5) arel (2.0.9) + bcrypt-ruby (2.1.4) builder (3.0.0) capybara (0.4.1.2) celerity (>= 0.7.9) @@ -56,22 +58,53 @@ GEM rack-test (>= 0.5.7) culerity (0.2.15) database_cleaner (0.6.6) + devise (1.3.4) + bcrypt-ruby (~> 2.1.2) + orm_adapter (~> 0.0.3) + warden (~> 1.0.3) + devise_oauth2_facebook (0.1.50) + devise (>= 1.1.1) + fbgraph diff-lcs (1.1.2) dryml (1.3.0.pre28) actionpack (>= 3.0.0) hobo_support (= 1.3.0.pre28) erubis (2.6.6) abstract (>= 1.0.0) + faraday (0.6.1) + addressable (~> 2.2.4) + multipart-post (~> 1.1.0) + rack (>= 1.1.0, < 2) + fbgraph (1.8.0) + activesupport + activesupport + hashie + hashie + i18n + i18n + json + json + oauth2 + oauth2 + rest-client + rest-client + typhoeus + typhoeus ffi (1.0.7) rake (>= 0.8.7) gherkin (2.3.5) json (>= 1.4.6) + hashie (1.0.0) hobo (1.3.0.pre28) dryml (= 1.3.0.pre28) hobo_fields (= 1.3.0.pre28) hobo_support (= 1.3.0.pre28) rails (>= 3.0.0) will_paginate (>= 3.0.pre) + hobo_devise (0.0.2) + devise (>= 1.1.7) + devise_oauth2_facebook + hobo (>= 1.3.0.pre28) hobo_fields (1.3.0.pre28) hobo_support (= 1.3.0.pre28) rails (>= 3.0.0) @@ -90,7 +123,13 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.16) + multi_json (1.0.1) + multipart-post (1.1.0) nokogiri (1.4.4) + oauth2 (0.4.1) + faraday (~> 0.6.1) + multi_json (>= 0.0.5) + orm_adapter (0.0.5) polyglot (0.3.1) rack (1.2.2) rack-mount (0.6.14) @@ -111,6 +150,8 @@ GEM rake (>= 0.8.7) thor (~> 0.14.4) rake (0.8.7) + rest-client (1.6.1) + mime-types (>= 1.16) rspec (2.5.0) rspec-core (~> 2.5.0) rspec-expectations (~> 2.5.0) @@ -144,7 +185,12 @@ GEM thor (0.14.6) treetop (1.4.9) polyglot (>= 0.3.1) + typhoeus (0.2.4) + mime-types + mime-types tzinfo (0.3.25) + warden (1.0.4) + rack (>= 1.0) will_paginate (3.0.pre2) xpath (0.1.3) nokogiri (~> 1.3) @@ -156,7 +202,9 @@ DEPENDENCIES capybara cucumber-rails database_cleaner + devise hobo (>= 1.3.0.pre28) + hobo_devise (>= 0.0.2) launchy rails (= 3.0.3) rspec-rails diff --git a/site/app/mailers/user_mailer.rb b/site/app/mailers/user_mailer.rb index dd96057..c5c18f8 100644 --- a/site/app/mailers/user_mailer.rb +++ b/site/app/mailers/user_mailer.rb @@ -4,7 +4,7 @@ class UserMailer < ActionMailer::Base def forgot_password(user, key) @user, @key = user, key mail( :subject => "#{app_name} -- forgotten password", - :to => user.email_address ) + :to => user.email ) end end diff --git a/site/app/models/user.rb b/site/app/models/user.rb index 20b2c4c..bf9769b 100644 --- a/site/app/models/user.rb +++ b/site/app/models/user.rb @@ -1,11 +1,11 @@ class User < ActiveRecord::Base - hobo_user_model # Don't put anything above this + hobo_devise_user_model :auth_methods => [:database_authenticable] fields do name :string, :required, :unique irc_nick :string, :required, :unique - email_address :email_address, :login => true + email :email_address, :login => true administrator :boolean, :default => false timestamps end @@ -17,7 +17,7 @@ class User < ActiveRecord::Base state :active, :default => true create :signup, :available_to => "Guest", - :params => [:name, :email_address, :irc_nick, :password, :password_confirmation], + :params => [:name, :email, :irc_nick, :password, :password_confirmation], :become => :active transition :request_password_reset, { :active => :active }, :new_key => true do @@ -37,7 +37,7 @@ class User < ActiveRecord::Base def update_permitted? acting_user.administrator? || - (acting_user == self && only_changed?(:email_address, :crypted_password, + (acting_user == self && only_changed?(:email, :crypted_password, :current_password, :password, :password_confirmation)) # Note: crypted_password has attr_protected so although it is permitted to change, it cannot be changed # directly from a form submission. diff --git a/site/config/initializers/devise.rb b/site/config/initializers/devise.rb new file mode 100644 index 0000000..d4aaf27 --- /dev/null +++ b/site/config/initializers/devise.rb @@ -0,0 +1 @@ +require 'devise/orm/active_record.rb' diff --git a/site/db/schema.rb b/site/db/schema.rb index d01de42..bd46dfd 100644 --- a/site/db/schema.rb +++ b/site/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110510092019) do +ActiveRecord::Schema.define(:version => 20110510180303) do create_table "users", :force => true do |t| t.string "crypted_password", :limit => 40 @@ -18,7 +18,7 @@ ActiveRecord::Schema.define(:version => 20110510092019) do t.string "remember_token" t.datetime "remember_token_expires_at" t.string "name" - t.string "email_address" + t.string "email" t.boolean "administrator", :default => false t.datetime "created_at" t.datetime "updated_at" diff --git a/site/features/login.feature b/site/features/login.feature index 8ba5be3..cea0492 100644 --- a/site/features/login.feature +++ b/site/features/login.feature @@ -7,7 +7,6 @@ Feature: Login When I am on the homepage When I follow "Login" Then I should be on the login page - When I login as example user Then I should see "You have logged in." @@ -15,6 +14,23 @@ Feature: Login Given example user When I am on the login page And I login as example user - When I follow "Logged in as Example" Then I should see "Log out" + + Scenario: Do not remember log in if "Remeber me" field was not checked + Given example user + When I am on the login page + And I uncheck "remember_me" + And I login as example user + When I close browser + And I am on the home page + Then I should see "Login" + + Scenario: Remember log in if "Remeber me" field was checked + Given example user + When I am on the login page + And I check "remember_me" + And I login as example user + When I close browser + And I am on the home page + Then I should see "Log out" diff --git a/site/features/step_definitions/login_steps.rb b/site/features/step_definitions/login_steps.rb index 5eaa5cc..d0f6642 100644 --- a/site/features/step_definitions/login_steps.rb +++ b/site/features/step_definitions/login_steps.rb @@ -1,5 +1,5 @@ Given /^example user$/ do - user = User.new :name => "Example", :email_address => "example@example.com", + user = User.new :name => "Example", :email => "example@example.com", :password => "Example", :irc_nick => "example" user.save! end @@ -13,3 +13,13 @@ end When /^I login as example user$/ do When 'I login as "example@example.com" with password "Example"' end + +When /^I close browser$/ do + Capybara.current_session.driver.is_a?(Capybara::Driver::Selenium).should be_true + browser = Capybara.current_session.driver.browser + browser.manage.all_cookies.each do |cookie| + if cookie[:expires].nil? || cookie[:expires] < Time.now + browser.manage.delete_cookie(cookie[:name]) + end + end +end |