Description:
fixed user confirmation bug
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@305 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
r160:0138848b0c5b - - 5 files changed: 23 inserted, 12 deleted
@@ -1,42 +1,50 | |||||
|
1 | class MainController < ApplicationController |
|
1 | class MainController < ApplicationController |
|
2 |
|
2 | ||
|
3 | SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
3 | SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
4 |
|
4 | ||
|
5 | before_filter :authenticate, :except => [:index, :login] |
|
5 | before_filter :authenticate, :except => [:index, :login] |
|
6 | before_filter :check_viewability, :except => [:index, :login] |
|
6 | before_filter :check_viewability, :except => [:index, :login] |
|
7 |
|
7 | ||
|
8 | - # |
|
8 | + # COMMENTED OUT: filter in each action instead |
|
9 | - # COMMENT OUT: filter in each action instead |
|
||
|
10 | - # |
|
||
|
11 |
|
|
9 | # before_filter :verify_time_limit, :only => [:submit] |
|
12 |
|
10 | ||
|
13 | verify :method => :post, :only => [:submit], |
|
11 | verify :method => :post, :only => [:submit], |
|
14 | :redirect_to => { :action => :index } |
|
12 | :redirect_to => { :action => :index } |
|
15 |
|
13 | ||
|
16 |
- |
|
14 | + # COMMENT OUT: only need when having high load |
|
17 |
|
|
15 | # caches_action :index, :login |
|
18 |
|
16 | ||
|
|
17 | + # NOTE: This method is not actually needed, 'config/routes.rb' has | ||
|
|
18 | + # assigned action login as a default action. | ||
|
19 | def index |
|
19 | def index |
|
20 | redirect_to :action => 'login' |
|
20 | redirect_to :action => 'login' |
|
21 | end |
|
21 | end |
|
22 |
|
22 | ||
|
23 | def login |
|
23 | def login |
|
24 | saved_notice = flash[:notice] |
|
24 | saved_notice = flash[:notice] |
|
25 | reset_session |
|
25 | reset_session |
|
26 | flash[:notice] = saved_notice |
|
26 | flash[:notice] = saved_notice |
|
27 |
|
27 | ||
|
|
28 | + # EXPERIMENT: | ||
|
|
29 | + # Hide login if in single user mode and the url does not | ||
|
|
30 | + # explicitly specify /login | ||
|
28 | # |
|
31 | # |
|
29 | - # These are for site administrator login |
|
32 | + # logger.info "PATH: #{request.path}" |
|
30 | - # |
|
33 | + # if Configuration['system.single_user_mode'] and |
|
|
34 | + # request.path!='/main/login' | ||
|
|
35 | + # @hidelogin = true | ||
|
|
36 | + # end | ||
|
|
37 | + | ||
|
|
38 | + # Site administrator login | ||
|
31 | @countries = Country.find(:all, :include => :sites) |
|
39 | @countries = Country.find(:all, :include => :sites) |
|
32 | @country_select = @countries.collect { |c| [c.name, c.id] } |
|
40 | @country_select = @countries.collect { |c| [c.name, c.id] } |
|
33 |
|
41 | ||
|
34 | @country_select_with_all = [['Any',0]] |
|
42 | @country_select_with_all = [['Any',0]] |
|
35 | @countries.each do |country| |
|
43 | @countries.each do |country| |
|
36 | @country_select_with_all << [country.name, country.id] |
|
44 | @country_select_with_all << [country.name, country.id] |
|
37 | end |
|
45 | end |
|
38 |
|
46 | ||
|
39 | @site_select = [] |
|
47 | @site_select = [] |
|
40 | @countries.each do |country| |
|
48 | @countries.each do |country| |
|
41 | country.sites.each do |site| |
|
49 | country.sites.each do |site| |
|
42 | @site_select << ["#{site.name}, #{country.name}", site.id] |
|
50 | @site_select << ["#{site.name}, #{country.name}", site.id] |
@@ -46,29 +46,29 | |||||
|
46 | else |
|
46 | else |
|
47 | render :action => 'email_error', :layout => 'empty' |
|
47 | render :action => 'email_error', :layout => 'empty' |
|
48 | end |
|
48 | end |
|
49 | else |
|
49 | else |
|
50 | @user.errors.add_to_base("Email cannot be blank") if @user.email=='' |
|
50 | @user.errors.add_to_base("Email cannot be blank") if @user.email=='' |
|
51 | render :action => 'new', :layout => 'empty' |
|
51 | render :action => 'new', :layout => 'empty' |
|
52 | end |
|
52 | end |
|
53 | end |
|
53 | end |
|
54 |
|
54 | ||
|
55 | def confirm |
|
55 | def confirm |
|
56 | login = params[:login] |
|
56 | login = params[:login] |
|
57 | key = params[:activation] |
|
57 | key = params[:activation] |
|
58 | - user = User.find_by_login(login) |
|
58 | + @user = User.find_by_login(login) |
|
59 | - if (user) and (user.verify_activation_key(key)) |
|
59 | + if (@user) and (@user.verify_activation_key(key)) |
|
60 | - if user.valid? # check uniquenss of email |
|
60 | + if @user.valid? # check uniquenss of email |
|
61 | - user.activated = true |
|
61 | + @user.activated = true |
|
62 | - user.save |
|
62 | + @user.save |
|
63 | @result = :successful |
|
63 | @result = :successful |
|
64 | else |
|
64 | else |
|
65 | @result = :email_used |
|
65 | @result = :email_used |
|
66 | end |
|
66 | end |
|
67 | else |
|
67 | else |
|
68 | @result = :failed |
|
68 | @result = :failed |
|
69 | end |
|
69 | end |
|
70 | render :action => 'confirm', :layout => 'empty' |
|
70 | render :action => 'confirm', :layout => 'empty' |
|
71 | end |
|
71 | end |
|
72 |
|
72 | ||
|
73 | protected |
|
73 | protected |
|
74 |
|
74 |
@@ -119,20 +119,21 | |||||
|
119 | def self.encrypt(string,salt) |
|
119 | def self.encrypt(string,salt) |
|
120 | Digest::SHA1.hexdigest(salt + string) |
|
120 | Digest::SHA1.hexdigest(salt + string) |
|
121 | end |
|
121 | end |
|
122 |
|
122 | ||
|
123 | def uniqueness_of_email_from_activated_users |
|
123 | def uniqueness_of_email_from_activated_users |
|
124 | user = User.activated_users.find_by_email(self.email) |
|
124 | user = User.activated_users.find_by_email(self.email) |
|
125 | if user and (user.login != self.login) |
|
125 | if user and (user.login != self.login) |
|
126 | self.errors.add_to_base("Email has already been taken") |
|
126 | self.errors.add_to_base("Email has already been taken") |
|
127 | end |
|
127 | end |
|
128 | end |
|
128 | end |
|
129 |
|
129 | ||
|
130 | def enough_time_interval_between_same_email_registrations |
|
130 | def enough_time_interval_between_same_email_registrations |
|
|
131 | + return if !self.new_record? | ||
|
131 | open_user = User.find_by_email(self.email, |
|
132 | open_user = User.find_by_email(self.email, |
|
132 | :order => 'created_at DESC') |
|
133 | :order => 'created_at DESC') |
|
133 | if open_user and open_user.created_at and |
|
134 | if open_user and open_user.created_at and |
|
134 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
135 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
135 | self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
136 | self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
136 | end |
|
137 | end |
|
137 | end |
|
138 | end |
|
138 | end |
|
139 | end |
@@ -1,42 +1,43 | |||||
|
1 | %h1= Configuration['ui.front.title'] |
|
1 | %h1= Configuration['ui.front.title'] |
|
2 |
|
2 | ||
|
3 | - if @announcements.length!=0 |
|
3 | - if @announcements.length!=0 |
|
4 | .announcementbox |
|
4 | .announcementbox |
|
5 | %span{:class => 'title'} |
|
5 | %span{:class => 'title'} |
|
6 | Announcements |
|
6 | Announcements |
|
7 | = render :partial => 'announcement', :collection => @announcements |
|
7 | = render :partial => 'announcement', :collection => @announcements |
|
8 |
|
8 | ||
|
9 | %b= Configuration['ui.front.welcome_message'] |
|
9 | %b= Configuration['ui.front.welcome_message'] |
|
10 | %br/ |
|
10 | %br/ |
|
|
11 | + | ||
|
|
12 | + - if !@hidelogin | ||
|
11 | Please login to see the problem list. |
|
13 | Please login to see the problem list. |
|
12 | %br/ |
|
14 | %br/ |
|
13 | %br/ |
|
15 | %br/ |
|
14 |
|
16 | ||
|
15 | - if flash[:notice] |
|
17 | - if flash[:notice] |
|
16 | %hr/ |
|
18 | %hr/ |
|
17 | %b= flash[:notice] |
|
19 | %b= flash[:notice] |
|
18 | %hr/ |
|
20 | %hr/ |
|
19 |
|
21 | ||
|
20 | %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} |
|
22 | %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} |
|
21 | - form_tag :controller => 'login', :action => 'login' do |
|
23 | - form_tag :controller => 'login', :action => 'login' do |
|
22 | %table |
|
24 | %table |
|
23 | %tr |
|
25 | %tr |
|
24 | %td{:align => "right"} Login: |
|
26 | %td{:align => "right"} Login: |
|
25 | %td= text_field_tag 'login' |
|
27 | %td= text_field_tag 'login' |
|
26 | %tr |
|
28 | %tr |
|
27 | %td{:align => "right"} Password: |
|
29 | %td{:align => "right"} Password: |
|
28 | %td= password_field_tag |
|
30 | %td= password_field_tag |
|
29 | = submit_tag 'Login' |
|
31 | = submit_tag 'Login' |
|
30 | - |
|
||
|
31 | %br/ |
|
32 | %br/ |
|
32 |
|
33 | ||
|
33 | - if Configuration['system.online_registration'] |
|
34 | - if Configuration['system.online_registration'] |
|
34 | Want to participate? |
|
35 | Want to participate? |
|
35 | %b |
|
36 | %b |
|
36 | Please |
|
37 | Please |
|
37 | = link_to 'register.', :controller => :users, :action => :new |
|
38 | = link_to 'register.', :controller => :users, :action => :new |
|
38 | %br/ |
|
39 | %br/ |
|
39 |
|
40 | ||
|
40 | - if (Configuration['system.mode']=='contest') and (Configuration['contest.multisites']) |
|
41 | - if (Configuration['system.mode']=='contest') and (Configuration['contest.multisites']) |
|
41 | %script{:type => 'text/javascript'} |
|
42 | %script{:type => 'text/javascript'} |
|
42 | var siteList = new Array(); |
|
43 | var siteList = new Array(); |
@@ -74,22 +74,23 | |||||
|
74 | post :register, :login => @john_info[:login], |
|
74 | post :register, :login => @john_info[:login], |
|
75 | :full_name => @john_info[:full_name], |
|
75 | :full_name => @john_info[:full_name], |
|
76 | :email => @john_info[:email] |
|
76 | :email => @john_info[:email] |
|
77 |
|
77 | ||
|
78 | response.should render_template('users/email_error') |
|
78 | response.should render_template('users/email_error') |
|
79 | end |
|
79 | end |
|
80 |
|
80 | ||
|
81 | it "should activate user with valid activation key" do |
|
81 | it "should activate user with valid activation key" do |
|
82 | login = @john_info[:login] |
|
82 | login = @john_info[:login] |
|
83 | User.should_receive(:find_by_login). |
|
83 | User.should_receive(:find_by_login). |
|
84 | with(login). |
|
84 | with(login). |
|
85 | and_return(@john) |
|
85 | and_return(@john) |
|
|
86 | + User.should_not_receive(:find_by_email) | ||
|
86 | @john.should_receive(:valid?).and_return(true) |
|
87 | @john.should_receive(:valid?).and_return(true) |
|
87 | @john.should_receive(:activated=).with(true) |
|
88 | @john.should_receive(:activated=).with(true) |
|
88 | @john.should_receive(:save).and_return(true) |
|
89 | @john.should_receive(:save).and_return(true) |
|
89 |
|
90 | ||
|
90 | get :confirm, :login => login, :activation => @john_activation_key |
|
91 | get :confirm, :login => login, :activation => @john_activation_key |
|
91 |
|
92 | ||
|
92 | response.should render_template('users/confirm') |
|
93 | response.should render_template('users/confirm') |
|
93 | end |
|
94 | end |
|
94 |
|
95 | ||
|
95 | end |
|
96 | end |
You need to be logged in to leave comments.
Login now