Changeset 270
- Timestamp:
- 03/07/08 17:57:01 (6 months ago)
- Files:
-
- incubator/jumpstart/app/views/sessions/new.html.erb (modified) (1 diff)
- incubator/jumpstart/app/views/users/new.html.erb (modified) (1 diff)
- incubator/jumpstart/app/views/user_mailer/activation.text.plain.erb (deleted)
- incubator/jumpstart/app/views/user_mailer/signup_notification.text.plain.erb (deleted)
- incubator/jumpstart/db/example_data.rb (modified) (1 diff)
- incubator/jumpstart/db/migrate/001_create_users.rb (modified) (1 diff)
- incubator/jumpstart/db/schema.rb (modified) (1 diff)
- incubator/jumpstart/lib/acts_as_authentable.rb (modified) (1 diff)
- incubator/jumpstart/lib/authentable_entity.rb (modified) (2 diffs)
- incubator/jumpstart/lib/authenticated_system.rb (modified) (1 diff)
- incubator/jumpstart/test/fixtures/users.yml (modified) (2 diffs)
- incubator/jumpstart/test/test_helpers/authenticated_test_helper.rb (modified) (1 diff)
- incubator/jumpstart/test/unit/user_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
incubator/jumpstart/app/views/sessions/new.html.erb
r251 r270 6 6 <% form_tag session_path do -%> 7 7 <p> 8 <label for=" login">Email</label><br/>8 <label for="email">Email</label><br/> 9 9 <%= text_field_tag 'email' %> 10 10 </p> incubator/jumpstart/app/views/users/new.html.erb
r251 r270 8 8 <% form_for :user, :url => users_path do |f| -%> 9 9 <p> 10 <label for=" login">Login</label><br/>11 <%= f.text_field : login%>10 <label for="username">Username</label><br/> 11 <%= f.text_field :username %> 12 12 </p> 13 13 incubator/jumpstart/db/example_data.rb
r214 r270 1 1 module FixtureReplacement 2 2 attributes_for :user do |a| 3 login= String.random3 username = String.random 4 4 password = String.random 5 5 6 a. login = login7 a.email = "#{ login}@example.com"6 a.username = username 7 a.email = "#{username}@example.com" 8 8 a.password = password 9 9 a.password_confirmation = password incubator/jumpstart/db/migrate/001_create_users.rb
r214 r270 2 2 def self.up 3 3 create_table :users, :force => true do |t| 4 t.string : login4 t.string :username 5 5 t.string :email 6 6 t.string :crypted_password 7 7 t.string :remember_token 8 8 t.datetime :remember_token_expires_at 9 t.string :activation_code 10 t.datetime :activated_at 9 t.string :identity_url 11 10 t.timestamps 12 11 end incubator/jumpstart/db/schema.rb
r214 r270 13 13 14 14 create_table "users", :force => true do |t| 15 t.string " login"15 t.string "username" 16 16 t.string "email" 17 17 t.string "crypted_password" 18 18 t.string "remember_token" 19 19 t.datetime "remember_token_expires_at" 20 t.string "activation_code" 21 t.datetime "activated_at" 20 t.string "identity_url" 22 21 t.datetime "created_at" 23 22 t.datetime "updated_at" incubator/jumpstart/lib/acts_as_authentable.rb
r214 r270 12 12 end 13 13 14 COLUMNS = { : login=> :string,14 COLUMNS = { :username => :string, 15 15 :email => :string, 16 16 :crypted_password => :string, 17 17 :remember_token => :string, 18 :remember_token_expires_at => :datetime}.freeze 18 :remember_token_expires_at => :datetime, 19 :identity_url => :string}.freeze 19 20 20 21 def add_authentable_fields incubator/jumpstart/lib/authentable_entity.rb
r269 r270 11 11 attr_accessor :password 12 12 13 validates_presence_of : login14 validates_length_of : login, :within => 3..4015 validates_uniqueness_of : login, :case_sensitive => false13 validates_presence_of :username 14 validates_length_of :username, :within => 3..40 15 validates_uniqueness_of :username, :case_sensitive => false 16 16 17 17 validates_presence_of :email … … 28 28 29 29 # Prevents users from submitting crafted forms that bypasses activation. 30 attr_accessible : login, :email, :password, :password_confirmation30 attr_accessible :username, :email, :password, :password_confirmation 31 31 32 32 extend ClassMethods incubator/jumpstart/lib/authenticated_system.rb
r214 r270 29 29 # # only allow nonbobs 30 30 # def authorized? 31 # current_user. login!= "bob"31 # current_user.username != "bob" 32 32 # end 33 33 def authorized? incubator/jumpstart/test/fixtures/users.yml
r214 r270 1 1 quentin: 2 2 id: 1 3 login: quentin3 username: quentin 4 4 email: quentin@example.com 5 5 crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test … … 10 10 aaron: 11 11 id: 2 12 login: aaron12 username: aaron 13 13 email: aaron@example.com 14 14 crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test incubator/jumpstart/test/test_helpers/authenticated_test_helper.rb
r214 r270 9 9 10 10 def authorize_as(user) 11 @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user). login, 'test') : nil11 @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).email, 'test') : nil 12 12 end 13 13 end incubator/jumpstart/test/unit/user_test.rb
r269 r270 3 3 describe "User", ActiveSupport::TestCase do 4 4 describe "validations" do 5 it "should require a login" do6 user = User.new(: login=> nil)7 user.should.have_errors(: login)5 it "should require a username" do 6 user = User.new(:username => nil) 7 user.should.have_errors(:username) 8 8 end 9 9 10 it "should require a unique login" do11 User.stubs(:find).returns(stub("another user with same login"))10 it "should require a unique username" do 11 User.stubs(:find).returns(stub("another user with same username")) 12 12 13 user = User.new(: login=> 'foo')14 user.should.have_errors(: login)13 user = User.new(:username => 'foo') 14 user.should.have_errors(:username) 15 15 end 16 16
