Description:
start working on e-mail registration
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@294 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r155:f1e975d4e9fc - - 14 files changed: 144 inserted, 8 deleted
@@ -0,0 +1,23 | |||
|
1 | + class AddMoreOptionsToConfigurations < ActiveRecord::Migration | |
|
2 | + def self.up | |
|
3 | + # If the server is in contest mode and | |
|
4 | + # Configuration['contest.multisites'] is true | |
|
5 | + # the menu for site administrator is shown. | |
|
6 | + | |
|
7 | + Configuration.create(:key => 'contest.multisites', | |
|
8 | + :value_type => 'boolean', | |
|
9 | + :value => 'false') | |
|
10 | + | |
|
11 | + # If Configuration['system.online_registration'] is true, | |
|
12 | + # the registration menu would appear | |
|
13 | + | |
|
14 | + Configuration.create(:key => 'system.online_registration', | |
|
15 | + :value_type => 'boolean', | |
|
16 | + :value => 'false') | |
|
17 | + end | |
|
18 | + | |
|
19 | + def self.down | |
|
20 | + Configuration.find_by_key('contest.multisites').destroy | |
|
21 | + Configuration.find_by_key('system.online_registration').destroy | |
|
22 | + end | |
|
23 | + end |
@@ -0,0 +1,15 | |||
|
1 | + class AddActivatedToUsers < ActiveRecord::Migration | |
|
2 | + def self.up | |
|
3 | + add_column :users, :activated, :boolean, :default => 0 | |
|
4 | + | |
|
5 | + User.find(:all).each do |user| | |
|
6 | + user.activated = true | |
|
7 | + user.save | |
|
8 | + end | |
|
9 | + end | |
|
10 | + | |
|
11 | + | |
|
12 | + def self.down | |
|
13 | + remove_column :users, :activated | |
|
14 | + end | |
|
15 | + end |
@@ -0,0 +1,3 | |||
|
1 | + #!/usr/bin/env ruby | |
|
2 | + require File.dirname(__FILE__) + '/../config/boot' | |
|
3 | + require 'commands/dbconsole' |
@@ -0,0 +1,3 | |||
|
1 | + #!/usr/bin/env ruby | |
|
2 | + require File.dirname(__FILE__) + '/../../config/boot' | |
|
3 | + require 'commands/performance/request' |
@@ -0,0 +1,53 | |||
|
1 | + | |
|
2 | + require File.dirname(__FILE__) + '/../spec_helper' | |
|
3 | + | |
|
4 | + describe User do | |
|
5 | + | |
|
6 | + before(:each) do | |
|
7 | + @password = "hello" | |
|
8 | + @salt = "123" | |
|
9 | + @john = stub_model(User, :salt => @salt, | |
|
10 | + :hashed_password => User.encrypt(@password,@salt)) | |
|
11 | + end | |
|
12 | + | |
|
13 | + it "should authenticate activated user" do | |
|
14 | + @john.should_receive(:activated).and_return(true) | |
|
15 | + @john.authenticated?(@password).should == true | |
|
16 | + end | |
|
17 | + | |
|
18 | + it "should not authenticate inactivated user" do | |
|
19 | + @john.should_receive(:activated).and_return(false) | |
|
20 | + @john.authenticated?(@password).should == false | |
|
21 | + end | |
|
22 | + | |
|
23 | + it "should not authenticate user with incorrect password" do | |
|
24 | + @john.should_receive(:activated).and_return(true) | |
|
25 | + @john.should_receive(:hashed_password).and_return("byebye") | |
|
26 | + @john.authenticated?(@password).should == false | |
|
27 | + end | |
|
28 | + | |
|
29 | + end | |
|
30 | + | |
|
31 | + describe User, "during registration" do | |
|
32 | + | |
|
33 | + class User | |
|
34 | + public :encrypt_new_password | |
|
35 | + end | |
|
36 | + | |
|
37 | + before(:each) do | |
|
38 | + @john = User.new(:login => 'john', :password => 'hello') | |
|
39 | + @john.encrypt_new_password | |
|
40 | + end | |
|
41 | + | |
|
42 | + it "should produce and accept activation key" do | |
|
43 | + activation_key = @john.activation_key | |
|
44 | + | |
|
45 | + @john.verify_activation_key(activation_key).should == true | |
|
46 | + end | |
|
47 | + | |
|
48 | + it "should not accept invalid activation key" do | |
|
49 | + @john.verify_activation_key("12345").should == false | |
|
50 | + end | |
|
51 | + | |
|
52 | + | |
|
53 | + end |
@@ -25,6 +25,7 | |||
|
25 | 25 | |
|
26 | 26 | def create |
|
27 | 27 | @user = User.new(params[:user]) |
|
28 | + @user.activated = true | |
|
28 | 29 | if @user.save |
|
29 | 30 | flash[:notice] = 'User was successfully created.' |
|
30 | 31 | redirect_to :action => 'list' |
@@ -44,6 +45,7 | |||
|
44 | 45 | user.alias = items[2] |
|
45 | 46 | user.password = items[3] |
|
46 | 47 | user.password_confirmation = items[3] |
|
48 | + user.activated = true | |
|
47 | 49 | user.save |
|
48 | 50 | end |
|
49 | 51 | end |
@@ -103,7 +103,11 | |||
|
103 | 103 | |
|
104 | 104 | def self.read_one_key(key) |
|
105 | 105 | conf = Configuration.find_by_key(key) |
|
106 | - return Configuration.convert_type(conf.value,conf.value_type) | |
|
106 | + if conf | |
|
107 | + return Configuration.convert_type(conf.value,conf.value_type) | |
|
108 | + else | |
|
109 | + return nil | |
|
110 | + end | |
|
107 | 111 | end |
|
108 | 112 | |
|
109 | 113 | def self.read_grading_info |
@@ -37,7 +37,11 | |||
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def authenticated?(password) |
|
40 | - hashed_password == User.encrypt(password,self.salt) | |
|
40 | + if self.activated | |
|
41 | + hashed_password == User.encrypt(password,self.salt) | |
|
42 | + else | |
|
43 | + false | |
|
44 | + end | |
|
41 | 45 | end |
|
42 | 46 | |
|
43 | 47 | def admin? |
@@ -72,6 +76,14 | |||
|
72 | 76 | self.alias=e |
|
73 | 77 | end |
|
74 | 78 | |
|
79 | + def activation_key | |
|
80 | + Digest::SHA1.hexdigest(self.hashed_password)[0..7] | |
|
81 | + end | |
|
82 | + | |
|
83 | + def verify_activation_key(key) | |
|
84 | + key == activation_key | |
|
85 | + end | |
|
86 | + | |
|
75 | 87 | protected |
|
76 | 88 | def encrypt_new_password |
|
77 | 89 | return if password.blank? |
@@ -30,7 +30,14 | |||
|
30 | 30 | |
|
31 | 31 | %br/ |
|
32 | 32 | |
|
33 |
- - if Configuration['system. |
|
|
33 | + -# if Configuration['system.online_registration'] | |
|
34 | + Want to participate? | |
|
35 | + %b | |
|
36 | + Please | |
|
37 | + = link_to 'register.', :controller => :users, :action => :new | |
|
38 | + %br/ | |
|
39 | + | |
|
40 | + - if (Configuration['system.mode']=='contest') and (Configuration['contest.multisites']) | |
|
34 | 41 | %script{:type => 'text/javascript'} |
|
35 | 42 | var siteList = new Array(); |
|
36 | 43 | - @countries.each do |country| |
@@ -82,14 +82,14 | |||
|
82 | 82 | |
|
83 | 83 | def load_rubygems |
|
84 | 84 | require 'rubygems' |
|
85 | - | |
|
86 |
- unless rubygems_version >= |
|
|
87 |
- $stderr.puts %(Rails requires RubyGems >= |
|
|
85 | + min_version = '1.1.1' | |
|
86 | + unless rubygems_version >= min_version | |
|
87 | + $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) | |
|
88 | 88 | exit 1 |
|
89 | 89 | end |
|
90 | 90 | |
|
91 | 91 | rescue LoadError |
|
92 |
- $stderr.puts %(Rails requires RubyGems >= |
|
|
92 | + $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) | |
|
93 | 93 | exit 1 |
|
94 | 94 | end |
|
95 | 95 |
@@ -43,8 +43,15 | |||
|
43 | 43 | |
|
44 | 44 | # See Rails::Configuration for more options |
|
45 | 45 | |
|
46 | + # ------------- | |
|
47 | + # Required gems | |
|
48 | + # ------------- | |
|
49 | + | |
|
46 | 50 | # This is for rspec |
|
47 | 51 | config.gem "rspec-rails", :lib => "spec" |
|
52 | + config.gem "haml" | |
|
53 | + config.gem "pony" | |
|
54 | + #config.gem "BlueCloth", :lig => "bluecloth" | |
|
48 | 55 | end |
|
49 | 56 | |
|
50 | 57 | # Add new inflection rules using the following format |
@@ -9,7 +9,7 | |||
|
9 | 9 | # |
|
10 | 10 | # It's strongly recommended to check this file into your version control system. |
|
11 | 11 | |
|
12 |
- ActiveRecord::Schema.define(:version => 20081 |
|
|
12 | + ActiveRecord::Schema.define(:version => 20081204122651) do | |
|
13 | 13 | |
|
14 | 14 | create_table "announcements", :force => true do |t| |
|
15 | 15 | t.string "author" |
@@ -182,6 +182,7 | |||
|
182 | 182 | t.string "email" |
|
183 | 183 | t.integer "site_id" |
|
184 | 184 | t.integer "country_id" |
|
185 | + t.boolean "activated", :default => false | |
|
185 | 186 | end |
|
186 | 187 | |
|
187 | 188 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
You need to be logged in to leave comments.
Login now