Description:
login test
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r626:f38d39d4f555 - - 7 files changed: 35 inserted, 11 deleted

@@ -1,78 +1,78
1 1 source 'https://rubygems.org'
2 2
3 3 gem 'rails', '~>4.2.0'
4 4 gem 'activerecord-session_store'
5 5
6 6 gem 'select2-rails'
7 7
8 8 # Bundle edge Rails instead:
9 9 # gem 'rails', :git => 'git://github.com/rails/rails.git'
10 10
11 11 gem 'mysql2'
12 12 gem 'sqlite3'
13 13
14 14 # Gems used only for assets and not required
15 15 # in production environments by default.
16 16 gem 'sass-rails'
17 17 gem 'coffee-rails'
18 18
19 19 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
20 20 # gem 'therubyracer', :platforms => :ruby
21 21
22 22 gem 'uglifier'
23 23
24 24
25 25 # gem 'prototype-rails'
26 26
27 27 # To use ActiveModel has_secure_password
28 28 # gem 'bcrypt-ruby', '~> 3.0.0'
29 29
30 30 # To use Jbuilder templates for JSON
31 31 # gem 'jbuilder'
32 32
33 33 # Use unicorn as the app server
34 34 # gem 'unicorn'
35 35
36 36 # Deploy with Capistrano
37 37 # gem 'capistrano'
38 38
39 39 # To use debugger
40 40 # gem 'debugger'
41 41 #
42 42
43 43 #in-place editor
44 44 gem 'best_in_place', '~> 3.0.1'
45 45
46 46 # jquery addition
47 47 gem 'jquery-rails'
48 48 gem 'jquery-ui-rails'
49 49 gem 'jquery-timepicker-addon-rails'
50 50 gem 'jquery-tablesorter'
51 51 gem 'jquery-countdown-rails'
52 52
53 53 #syntax highlighter
54 54 gem 'rouge'
55 55
56 56 #add bootstrap
57 57 gem 'bootstrap-sass', '~> 3.2.0'
58 58 gem 'bootstrap-switch-rails'
59 59 gem 'bootstrap-toggle-rails'
60 60 gem 'autoprefixer-rails'
61 61
62 62 #bootstrap sortable
63 63 gem 'momentjs-rails'
64 64 gem 'rails_bootstrap_sortable'
65 65
66 66 #ace editor
67 67 gem 'ace-rails-ap'
68 68
69 69 gem 'haml'
70 70 gem 'haml-rails'
71 71 gem 'mail'
72 72 gem 'rdiscount'
73 - gem 'test-unit'
73 + #gem 'test-unit'
74 74 gem 'will_paginate', '~> 3.0.7'
75 75 gem 'dynamic_form'
76 76 gem 'in_place_editing'
77 77 gem 'verification', :git => 'https://github.com/sikachu/verification.git'
78 78
@@ -24,198 +24,194
24 24 rails-dom-testing (~> 1.0, >= 1.0.5)
25 25 rails-html-sanitizer (~> 1.0, >= 1.0.2)
26 26 actionview (4.2.7.1)
27 27 activesupport (= 4.2.7.1)
28 28 builder (~> 3.1)
29 29 erubis (~> 2.7.0)
30 30 rails-dom-testing (~> 1.0, >= 1.0.5)
31 31 rails-html-sanitizer (~> 1.0, >= 1.0.2)
32 32 activejob (4.2.7.1)
33 33 activesupport (= 4.2.7.1)
34 34 globalid (>= 0.3.0)
35 35 activemodel (4.2.7.1)
36 36 activesupport (= 4.2.7.1)
37 37 builder (~> 3.1)
38 38 activerecord (4.2.7.1)
39 39 activemodel (= 4.2.7.1)
40 40 activesupport (= 4.2.7.1)
41 41 arel (~> 6.0)
42 42 activerecord-session_store (1.0.0)
43 43 actionpack (>= 4.0, < 5.1)
44 44 activerecord (>= 4.0, < 5.1)
45 45 multi_json (~> 1.11, >= 1.11.2)
46 46 rack (>= 1.5.2, < 3)
47 47 railties (>= 4.0, < 5.1)
48 48 activesupport (4.2.7.1)
49 49 i18n (~> 0.7)
50 50 json (~> 1.7, >= 1.7.7)
51 51 minitest (~> 5.1)
52 52 thread_safe (~> 0.3, >= 0.3.4)
53 53 tzinfo (~> 1.1)
54 54 arel (6.0.4)
55 55 autoprefixer-rails (6.6.0)
56 56 execjs
57 57 best_in_place (3.0.3)
58 58 actionpack (>= 3.2)
59 59 railties (>= 3.2)
60 60 bootstrap-sass (3.2.0.2)
61 61 sass (~> 3.2)
62 62 bootstrap-switch-rails (3.3.3)
63 63 bootstrap-toggle-rails (2.2.1.0)
64 64 builder (3.2.2)
65 65 coffee-rails (4.2.1)
66 66 coffee-script (>= 2.2.0)
67 67 railties (>= 4.0.0, < 5.2.x)
68 68 coffee-script (2.4.1)
69 69 coffee-script-source
70 70 execjs
71 71 coffee-script-source (1.12.2)
72 72 concurrent-ruby (1.0.4)
73 73 dynamic_form (1.1.4)
74 74 erubis (2.7.0)
75 75 execjs (2.7.0)
76 76 globalid (0.3.7)
77 77 activesupport (>= 4.1.0)
78 78 haml (4.0.7)
79 79 tilt
80 80 haml-rails (0.9.0)
81 81 actionpack (>= 4.0.1)
82 82 activesupport (>= 4.0.1)
83 83 haml (>= 4.0.6, < 5.0)
84 84 html2haml (>= 1.0.1)
85 85 railties (>= 4.0.1)
86 86 html2haml (2.0.0)
87 87 erubis (~> 2.7.0)
88 88 haml (~> 4.0.0)
89 89 nokogiri (~> 1.6.0)
90 90 ruby_parser (~> 3.5)
91 91 i18n (0.7.0)
92 92 in_place_editing (1.2.0)
93 93 jquery-countdown-rails (2.0.2)
94 94 jquery-rails (4.2.1)
95 95 rails-dom-testing (>= 1, < 3)
96 96 railties (>= 4.2.0)
97 97 thor (>= 0.14, < 2.0)
98 98 jquery-tablesorter (1.23.3)
99 99 railties (>= 3.2, < 6)
100 100 jquery-timepicker-addon-rails (1.4.1)
101 101 railties (>= 3.1)
102 102 jquery-ui-rails (6.0.1)
103 103 railties (>= 3.2.16)
104 104 json (1.8.3)
105 105 loofah (2.0.3)
106 106 nokogiri (>= 1.5.9)
107 107 mail (2.6.4)
108 108 mime-types (>= 1.16, < 4)
109 109 mime-types (3.1)
110 110 mime-types-data (~> 3.2015)
111 111 mime-types-data (3.2016.0521)
112 112 mini_portile2 (2.1.0)
113 113 minitest (5.10.1)
114 114 momentjs-rails (2.15.1)
115 115 railties (>= 3.1)
116 116 multi_json (1.12.1)
117 117 mysql2 (0.4.5)
118 118 nokogiri (1.6.8.1)
119 119 mini_portile2 (~> 2.1.0)
120 - power_assert (0.4.1)
121 120 rack (1.6.5)
122 121 rack-test (0.6.3)
123 122 rack (>= 1.0)
124 123 rails (4.2.7.1)
125 124 actionmailer (= 4.2.7.1)
126 125 actionpack (= 4.2.7.1)
127 126 actionview (= 4.2.7.1)
128 127 activejob (= 4.2.7.1)
129 128 activemodel (= 4.2.7.1)
130 129 activerecord (= 4.2.7.1)
131 130 activesupport (= 4.2.7.1)
132 131 bundler (>= 1.3.0, < 2.0)
133 132 railties (= 4.2.7.1)
134 133 sprockets-rails
135 134 rails-deprecated_sanitizer (1.0.3)
136 135 activesupport (>= 4.2.0.alpha)
137 136 rails-dom-testing (1.0.8)
138 137 activesupport (>= 4.2.0.beta, < 5.0)
139 138 nokogiri (~> 1.6)
140 139 rails-deprecated_sanitizer (>= 1.0.1)
141 140 rails-html-sanitizer (1.0.3)
142 141 loofah (~> 2.0)
143 142 rails_bootstrap_sortable (2.0.1)
144 143 momentjs-rails (>= 2.8.3)
145 144 railties (4.2.7.1)
146 145 actionpack (= 4.2.7.1)
147 146 activesupport (= 4.2.7.1)
148 147 rake (>= 0.8.7)
149 148 thor (>= 0.18.1, < 2.0)
150 149 rake (12.0.0)
151 150 rdiscount (2.2.0.1)
152 151 rouge (2.0.7)
153 152 ruby_parser (3.8.3)
154 153 sexp_processor (~> 4.1)
155 154 sass (3.4.23)
156 155 sass-rails (5.0.6)
157 156 railties (>= 4.0.0, < 6)
158 157 sass (~> 3.1)
159 158 sprockets (>= 2.8, < 4.0)
160 159 sprockets-rails (>= 2.0, < 4.0)
161 160 tilt (>= 1.1, < 3)
162 161 select2-rails (4.0.3)
163 162 thor (~> 0.14)
164 163 sexp_processor (4.7.0)
165 164 sprockets (3.7.1)
166 165 concurrent-ruby (~> 1.0)
167 166 rack (> 1, < 3)
168 167 sprockets-rails (3.2.0)
169 168 actionpack (>= 4.0)
170 169 activesupport (>= 4.0)
171 170 sprockets (>= 3.0.0)
172 171 sqlite3 (1.3.12)
173 - test-unit (3.2.3)
174 - power_assert
175 172 thor (0.19.4)
176 173 thread_safe (0.3.5)
177 174 tilt (2.0.5)
178 175 tzinfo (1.2.2)
179 176 thread_safe (~> 0.1)
180 177 uglifier (3.0.4)
181 178 execjs (>= 0.3.0, < 3)
182 179 will_paginate (3.0.12)
183 180
184 181 PLATFORMS
185 182 ruby
186 183
187 184 DEPENDENCIES
188 185 ace-rails-ap
189 186 activerecord-session_store
190 187 autoprefixer-rails
191 188 best_in_place (~> 3.0.1)
192 189 bootstrap-sass (~> 3.2.0)
193 190 bootstrap-switch-rails
194 191 bootstrap-toggle-rails
195 192 coffee-rails
196 193 dynamic_form
197 194 haml
198 195 haml-rails
199 196 in_place_editing
200 197 jquery-countdown-rails
201 198 jquery-rails
202 199 jquery-tablesorter
203 200 jquery-timepicker-addon-rails
204 201 jquery-ui-rails
205 202 mail
206 203 momentjs-rails
207 204 mysql2
208 205 rails (~> 4.2.0)
209 206 rails_bootstrap_sortable
210 207 rdiscount
211 208 rouge
212 209 sass-rails
213 210 select2-rails
214 211 sqlite3
215 - test-unit
216 212 uglifier
217 213 verification!
218 214 will_paginate (~> 3.0.7)
219 215
220 216 BUNDLED WITH
221 217 1.13.6
@@ -1,109 +1,110
1 1 require 'yaml'
2 2
3 3 #
4 4 # This class also contains various login of the system.
5 5 #
6 6 class GraderConfiguration < ActiveRecord::Base
7 7
8 8 SYSTEM_MODE_CONF_KEY = 'system.mode'
9 9 TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
10 10 MULTICONTESTS_KEY = 'system.multicontests'
11 11 CONTEST_TIME_LIMIT_KEY = 'contest.time_limit'
12 12 MULTIPLE_IP_LOGIN_KEY = 'right.multiple_ip_login'
13 13 VIEW_TESTCASE = 'right.view_testcase'
14 + SINGLE_USER_KEY = 'system.single_user'
14 15
15 16 cattr_accessor :config_cache
16 17 cattr_accessor :task_grading_info_cache
17 18 cattr_accessor :contest_time_str
18 19 cattr_accessor :contest_time
19 20
20 21 GraderConfiguration.config_cache = nil
21 22 GraderConfiguration.task_grading_info_cache = nil
22 23
23 24 def self.config_cached?
24 25 (defined? CONFIGURATION_CACHE_ENABLED) and (CONFIGURATION_CACHE_ENABLED)
25 26 end
26 27
27 28 def self.get(key)
28 29 if GraderConfiguration.config_cached?
29 30 if GraderConfiguration.config_cache == nil
30 31 self.read_config
31 32 end
32 33 return GraderConfiguration.config_cache[key]
33 34 else
34 35 return GraderConfiguration.read_one_key(key)
35 36 end
36 37 end
37 38
38 39 def self.[](key)
39 40 self.get(key)
40 41 end
41 42
42 43 def self.reload
43 44 self.read_config
44 45 end
45 46
46 47 def self.clear
47 48 GraderConfiguration.config_cache = nil
48 49 end
49 50
50 51 #
51 52 # View decision
52 53 #
53 54 def self.show_submitbox_to?(user)
54 55 mode = get(SYSTEM_MODE_CONF_KEY)
55 56 return false if mode=='analysis'
56 57 if (mode=='contest')
57 58 return false if (user.site!=nil) and
58 59 ((user.site.started!=true) or (user.site.finished?))
59 60 end
60 61 return true
61 62 end
62 63
63 64 def self.show_tasks_to?(user)
64 65 if time_limit_mode?
65 66 return false if not user.contest_started?
66 67 end
67 68 return true
68 69 end
69 70
70 71 def self.show_grading_result
71 72 return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
72 73 end
73 74
74 75 def self.show_testcase
75 76 return get(VIEW_TESTCASE)
76 77 end
77 78
78 79 def self.allow_test_request(user)
79 80 mode = get(SYSTEM_MODE_CONF_KEY)
80 81 early_timeout = get(TEST_REQUEST_EARLY_TIMEOUT_KEY)
81 82 if (mode=='contest')
82 83 return false if ((user.site!=nil) and
83 84 ((user.site.started!=true) or
84 85 (early_timeout and (user.site.time_left < 30.minutes))))
85 86 end
86 87 return false if mode=='analysis'
87 88 return true
88 89 end
89 90
90 91 def self.task_grading_info
91 92 if GraderConfiguration.task_grading_info_cache==nil
92 93 read_grading_info
93 94 end
94 95 return GraderConfiguration.task_grading_info_cache
95 96 end
96 97
97 98 def self.standard_mode?
98 99 return get(SYSTEM_MODE_CONF_KEY) == 'standard'
99 100 end
100 101
101 102 def self.contest_mode?
102 103 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
103 104 end
104 105
105 106 def self.indv_contest_mode?
106 107 return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
107 108 end
108 109
109 110 def self.multicontests?
@@ -1,39 +1,39
1 1 %b= GraderConfiguration['ui.front.welcome_message']
2 2 %br/
3 3
4 4 - if !@hidelogin
5 5 =t 'login.message'
6 6 %br/
7 7 %br/
8 8
9 9 - if flash[:notice]
10 10 %hr/
11 11 %b= flash[:notice]
12 12 %hr/
13 13
14 14 %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"}
15 - = form_tag :controller => 'login', :action => 'login' do
15 + = form_tag login_login_path do
16 16 %table
17 17 %tr
18 18 %td{:align => "right"}
19 19 ="#{t 'login_label'}:"
20 20 %td= text_field_tag 'login'
21 21 %tr
22 22 %td{:align => "right"}
23 23 ="#{t 'password_label'}:"
24 24 %td= password_field_tag
25 25 - unless GraderConfiguration['right.bypass_agreement']
26 26 %tr
27 27 %td{:align => "right"}= check_box_tag 'accept_agree'
28 28 %td ยอมรับข้อตกลงการใช้งาน
29 29
30 30 = submit_tag t('login.login_submit')
31 31 %br/
32 32
33 33 - if GraderConfiguration['system.online_registration']
34 34 =t 'login.participation'
35 35 %b
36 36 = "#{t 'login.please'} "
37 37 = link_to "#{t 'login.register'}", :controller => :users, :action => :new
38 38 %br/
39 39 = link_to "#{t 'login.forget_password'}", :controller => :users, :action => :forget
@@ -1,85 +1,88
1 1 CafeGrader::Application.routes.draw do
2 2 get "sources/direct_edit"
3 3
4 4 root :to => 'main#login'
5 5
6 + #logins
7 + get 'login/login', to: 'login#login'
8 +
6 9 resources :contests
7 10
8 11 resources :sites
9 12
10 13 resources :announcements do
11 14 member do
12 15 get 'toggle','toggle_front'
13 16 end
14 17 end
15 18
16 19 resources :problems do
17 20 member do
18 21 get 'toggle'
19 22 get 'toggle_test'
20 23 get 'stat'
21 24 get 'show_testcase'
22 25 end
23 26 collection do
24 27 get 'turn_all_off'
25 28 get 'turn_all_on'
26 29 get 'import'
27 30 get 'manage'
28 31 end
29 32
30 33 resources :testcases, only: [] do
31 34 member do
32 35 get 'download_input'
33 36 get 'download_sol'
34 37 end
35 38 end
36 39 end
37 40
38 41 resources :grader_configuration, controller: 'configurations'
39 42
40 43 resources :users do
41 44 member do
42 45 get 'toggle_activate', 'toggle_enable'
43 46 get 'stat'
44 47 end
45 48 end
46 49
47 50 resources :submissions do
48 51 member do
49 52 get 'download'
50 53 get 'compiler_msg'
51 54 end
52 55 collection do
53 56 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
54 57 get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
55 58 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
56 59 end
57 60 end
58 61
59 62 get 'tasks/view/:file.:ext' => 'tasks#view'
60 63 get 'tasks/download/:id/:file.:ext' => 'tasks#download'
61 64 get 'heartbeat/:id/edit' => 'heartbeat#edit'
62 65
63 66 #main
64 67 get "main/list"
65 68 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
66 69
67 70 #report
68 71 get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
69 72 get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
70 73 get "report/login"
71 74 get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
72 75 post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
73 76
74 77 #grader
75 78 get 'graders/list', to: 'graders#list', as: 'grader_list'
76 79
77 80
78 81 get 'heartbeat/:id/edit' => 'heartbeat#edit'
79 82
80 83 # See how all your routes lay out with "rake routes"
81 84
82 85 # This is a legacy wild controller route that's not recommended for RESTful applications.
83 86 # Note: This route will make all actions in every controller accessible via GET requests.
84 87 match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
85 88 end
@@ -1,38 +1,38
1 1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 2
3 3 <%
4 4 User.public_class_method :encrypt
5 5
6 6 salt = "abc"
7 7 %>
8 8
9 9 john:
10 10 login: john
11 11 full_name: john
12 12 hashed_password: <%= User.encrypt("hello",salt) %>
13 13 salt: <%= salt %>
14 14 activated: true
15 15
16 - mary:
17 - login: mary
18 - full_name: mary
19 - hashed_password: <%= User.encrypt("goodbye",salt) %>
16 + admin:
17 + login: admin
18 + full_name: admin
19 + hashed_password: <%= User.encrypt("admin",salt) %>
20 20 salt: <%= salt %>
21 21 roles: admin
22 22 activated: true
23 23
24 24 james:
25 25 login: james
26 26 full_name: James
27 27 hashed_password: <%= User.encrypt("morning",salt) %>
28 28 salt: <%= salt %>
29 29 contests: contest_a
30 30 activated: true
31 31
32 32 jack:
33 33 login: jack
34 34 full_name: Jack
35 35 hashed_password: <%= User.encrypt("morning",salt) %>
36 36 salt: <%= salt %>
37 37 contests: contest_a, contest_b
38 38 activated: true
@@ -1,13 +1,37
1 1 require 'test_helper'
2 2
3 3 class LoginTest < ActionDispatch::IntegrationTest
4 4 # test "the truth" do
5 5 # assert true
6 6 # end
7 7
8 - test "login with valid information" do
8 + test "login with invalid information" do
9 + get root_path
10 + assert_response :success
11 + post login_login_path, login: "root", password: "hahaha"
12 + assert_redirected_to root_path
13 + end
14 +
15 + test "normal user login" do
9 16 get root_path
10 17 assert_response :success
18 + post login_login_path, {login: "john", password: "hello" }
19 + assert_redirected_to main_list_path
20 + end
11 21
22 + test "normal user login in single_user mode" do
23 + GraderConfiguration[GraderConfiguration::SINGLE_USER_KEY] = 'true'
24 + get root_path
25 + assert_response :success
26 + post login_login_path, {login: "john", password: "hello" }
27 + assert_redirected_to root_path
28 + end
29 +
30 + test "root login in in single_user mode" do
31 + GraderConfiguration[GraderConfiguration::SINGLE_USER_KEY] = 'true'
32 + get root_path
33 + assert_response :success
34 + post login_login_path, {login: "admin", password: "admin" }
35 + assert_redirected_to main_list_path
12 36 end
13 37 end
You need to be logged in to leave comments. Login now