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

r410:1c14a43c4f1f - - 11 files changed: 115 inserted, 74 deleted

@@ -0,0 +1,3
1 + # Place all the behaviors and hooks related to the matching controller here.
2 + # All this logic will automatically be available in application.js.
3 + # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3
1 + // Place all the styles related to the report controller here.
2 + // They will automatically be included in application.css.
3 + // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,13
1 + class ReportController < ApplicationController
2 + def login_stat
3 + @logins = Array.new
4 + login = Login.all
5 + User.all.each do |user|
6 + @logins << { login: user.login,
7 + full_name: user.full_name,
8 + count: Login.where(user_id: user.id).count(:id),
9 + min: Login.where(user_id: user.id).maximum(:created_at),
10 + max: Login.where(user_id: user.id).minimum(:created_at) }
11 + end
12 + end
13 + end
@@ -0,0 +1,2
1 + module ReportHelper
2 + end
@@ -0,0 +1,3
1 + class Login < ActiveRecord::Base
2 + attr_accessible :ip_address, :logged_in_at, :user_id
3 + end
@@ -0,0 +1,26
1 + %h1 Login status
2 +
3 +
4 + .task-menu
5 + Reports
6 + %br/
7 + = link_to '[Submission]', :action => 'submit_stat'
8 + = link_to '[Login]', :action => 'login_stat'
9 +
10 + %table.info
11 + %thead
12 + %tr.info-head
13 + %th login
14 + %th full name
15 + %th login count
16 + %th earliest
17 + %th latest
18 + %tbody
19 + - @logins.each do |l|
20 + %tr{class: cycle('info-even','info-odd')}
21 + %td= l[:login]
22 + %td= l[:full_name]
23 + %td= l[:count]
24 + %td= l[:min]
25 + %td= l[:max]
26 +
@@ -0,0 +1,10
1 + class CreateLogins < ActiveRecord::Migration
2 + def change
3 + create_table :logins do |t|
4 + t.string :user_id
5 + t.string :ip_address
6 +
7 + t.timestamps
8 + end
9 + end
10 + end
@@ -0,0 +1,5
1 + require 'spec_helper'
2 +
3 + describe Login do
4 + pending "add some examples to (or delete) #{__FILE__}"
5 + end
@@ -1,51 +1,54
1 class LoginController < ApplicationController
1 class LoginController < ApplicationController
2
2
3 def index
3 def index
4 # show login screen
4 # show login screen
5 reset_session
5 reset_session
6 redirect_to :controller => 'main', :action => 'login'
6 redirect_to :controller => 'main', :action => 'login'
7 end
7 end
8
8
9 def login
9 def login
10 if user = User.authenticate(params[:login], params[:password])
10 if user = User.authenticate(params[:login], params[:password])
11 session[:user_id] = user.id
11 session[:user_id] = user.id
12 session[:admin] = user.admin?
12 session[:admin] = user.admin?
13
13
14 # clear forced logout flag for multicontests contest change
14 # clear forced logout flag for multicontests contest change
15 if GraderConfiguration.multicontests?
15 if GraderConfiguration.multicontests?
16 contest_stat = user.contest_stat
16 contest_stat = user.contest_stat
17 if contest_stat.respond_to? :forced_logout
17 if contest_stat.respond_to? :forced_logout
18 if contest_stat.forced_logout
18 if contest_stat.forced_logout
19 contest_stat.forced_logout = false
19 contest_stat.forced_logout = false
20 contest_stat.save
20 contest_stat.save
21 end
21 end
22 end
22 end
23 end
23 end
24
24
25 + #save login information
26 + Login.create(user_id: user.id, ip_address: request.remote_ip)
27 +
25 redirect_to :controller => 'main', :action => 'list'
28 redirect_to :controller => 'main', :action => 'list'
26 else
29 else
27 flash[:notice] = 'Wrong password'
30 flash[:notice] = 'Wrong password'
28 redirect_to :controller => 'main', :action => 'login'
31 redirect_to :controller => 'main', :action => 'login'
29 end
32 end
30 end
33 end
31
34
32 def site_login
35 def site_login
33 begin
36 begin
34 site = Site.find(params[:login][:site_id])
37 site = Site.find(params[:login][:site_id])
35 rescue ActiveRecord::RecordNotFound
38 rescue ActiveRecord::RecordNotFound
36 site = nil
39 site = nil
37 end
40 end
38 if site==nil
41 if site==nil
39 flash[:notice] = 'Wrong site'
42 flash[:notice] = 'Wrong site'
40 redirect_to :controller => 'main', :action => 'login' and return
43 redirect_to :controller => 'main', :action => 'login' and return
41 end
44 end
42 if (site.password) and (site.password == params[:login][:password])
45 if (site.password) and (site.password == params[:login][:password])
43 session[:site_id] = site.id
46 session[:site_id] = site.id
44 redirect_to :controller => 'site', :action => 'index'
47 redirect_to :controller => 'site', :action => 'index'
45 else
48 else
46 flash[:notice] = 'Wrong site password'
49 flash[:notice] = 'Wrong site password'
47 redirect_to :controller => 'site', :action => 'login'
50 redirect_to :controller => 'site', :action => 'login'
48 end
51 end
49 end
52 end
50
53
51 end
54 end
@@ -1,49 +1,53
1 CafeGrader::Application.routes.draw do
1 CafeGrader::Application.routes.draw do
2 + get "report/login"
3 +
4 + get "logins/list"
5 +
2 resources :contests
6 resources :contests
3
7
4 resources :announcements
8 resources :announcements
5 resources :sites
9 resources :sites
6
10
7 # The priority is based upon order of creation:
11 # The priority is based upon order of creation:
8 # first created -> highest priority.
12 # first created -> highest priority.
9
13
10 # Sample of regular route:
14 # Sample of regular route:
11 # match 'products/:id' => 'catalog#view'
15 # match 'products/:id' => 'catalog#view'
12 # Keep in mind you can assign values other than :controller and :action
16 # Keep in mind you can assign values other than :controller and :action
13
17
14 # Sample of named route:
18 # Sample of named route:
15 # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
19 # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
16 # This route can be invoked with purchase_url(:id => product.id)
20 # This route can be invoked with purchase_url(:id => product.id)
17
21
18 # Sample resource route (maps HTTP verbs to controller actions automatically):
22 # Sample resource route (maps HTTP verbs to controller actions automatically):
19 # resources :products
23 # resources :products
20
24
21 # Sample resource route with options:
25 # Sample resource route with options:
22 # resources :products do
26 # resources :products do
23 # member do
27 # member do
24 # get 'short'
28 # get 'short'
25 # post 'toggle'
29 # post 'toggle'
26 # end
30 # end
27 #
31 #
28 # collection do
32 # collection do
29 # get 'sold'
33 # get 'sold'
30 # end
34 # end
31 # end
35 # end
32
36
33 # Sample resource route with sub-resources:
37 # Sample resource route with sub-resources:
34 # resources :products do
38 # resources :products do
35 # resources :comments, :sales
39 # resources :comments, :sales
36 # resource :seller
40 # resource :seller
37 # end
41 # end
38
42
39 # Sample resource route with more complex sub-resources
43 # Sample resource route with more complex sub-resources
40 # resources :products do
44 # resources :products do
41 # resources :comments
45 # resources :comments
42 # resources :sales do
46 # resources :sales do
43 # get 'recent', :on => :collection
47 # get 'recent', :on => :collection
44 # end
48 # end
45 # end
49 # end
46
50
47 # Sample resource route within a namespace:
51 # Sample resource route within a namespace:
48 # namespace :admin do
52 # namespace :admin do
49 # # Directs /admin/products/* to Admin::ProductsController
53 # # Directs /admin/products/* to Admin::ProductsController
@@ -1,273 +1,242
1 # encoding: UTF-8
1 # encoding: UTF-8
2 # This file is auto-generated from the current state of the database. Instead
2 # This file is auto-generated from the current state of the database. Instead
3 # of editing this file, please use the migrations feature of Active Record to
3 # of editing this file, please use the migrations feature of Active Record to
4 # incrementally modify your database, and then regenerate this schema definition.
4 # incrementally modify your database, and then regenerate this schema definition.
5 #
5 #
6 # Note that this schema.rb definition is the authoritative source for your
6 # Note that this schema.rb definition is the authoritative source for your
7 # database schema. If you need to create the application database on another
7 # database schema. If you need to create the application database on another
8 # system, you should be using db:schema:load, not running all the migrations
8 # system, you should be using db:schema:load, not running all the migrations
9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 # you'll amass, the slower it'll run and the greater likelihood for issues).
10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 #
11 #
12 # It's strongly recommended to check this file into your version control system.
12 # It's strongly recommended to check this file into your version control system.
13
13
14 - ActiveRecord::Schema.define(:version => 20121001033508) do
14 + ActiveRecord::Schema.define(:version => 20140826095949) do
15
15
16 create_table "announcements", :force => true do |t|
16 create_table "announcements", :force => true do |t|
17 t.string "author"
17 t.string "author"
18 t.text "body"
18 t.text "body"
19 t.boolean "published"
19 t.boolean "published"
20 - t.datetime "created_at"
20 + t.datetime "created_at", :null => false
21 - t.datetime "updated_at"
21 + t.datetime "updated_at", :null => false
22 t.boolean "frontpage", :default => false
22 t.boolean "frontpage", :default => false
23 t.boolean "contest_only", :default => false
23 t.boolean "contest_only", :default => false
24 t.string "title"
24 t.string "title"
25 t.string "notes"
25 t.string "notes"
26 end
26 end
27
27
28 - create_table "codejom_statuses", :force => true do |t|
29 - t.integer "user_id"
30 - t.boolean "alive"
31 - t.integer "num_problems_passed"
32 - t.datetime "created_at"
33 - t.datetime "updated_at"
34 - end
35 -
36 create_table "contests", :force => true do |t|
28 create_table "contests", :force => true do |t|
37 t.string "title"
29 t.string "title"
38 t.boolean "enabled"
30 t.boolean "enabled"
39 - t.datetime "created_at"
31 + t.datetime "created_at", :null => false
40 - t.datetime "updated_at"
32 + t.datetime "updated_at", :null => false
41 t.string "name"
33 t.string "name"
42 end
34 end
43
35
44 create_table "contests_problems", :id => false, :force => true do |t|
36 create_table "contests_problems", :id => false, :force => true do |t|
45 t.integer "contest_id"
37 t.integer "contest_id"
46 t.integer "problem_id"
38 t.integer "problem_id"
47 end
39 end
48
40
49 create_table "contests_users", :id => false, :force => true do |t|
41 create_table "contests_users", :id => false, :force => true do |t|
50 t.integer "contest_id"
42 t.integer "contest_id"
51 t.integer "user_id"
43 t.integer "user_id"
52 end
44 end
53
45
54 create_table "countries", :force => true do |t|
46 create_table "countries", :force => true do |t|
55 t.string "name"
47 t.string "name"
56 - t.datetime "created_at"
48 + t.datetime "created_at", :null => false
57 - t.datetime "updated_at"
49 + t.datetime "updated_at", :null => false
58 end
50 end
59
51
60 create_table "descriptions", :force => true do |t|
52 create_table "descriptions", :force => true do |t|
61 t.text "body"
53 t.text "body"
62 t.boolean "markdowned"
54 t.boolean "markdowned"
63 - t.datetime "created_at"
55 + t.datetime "created_at", :null => false
64 - t.datetime "updated_at"
56 + t.datetime "updated_at", :null => false
65 end
57 end
66
58
67 create_table "grader_configurations", :force => true do |t|
59 create_table "grader_configurations", :force => true do |t|
68 t.string "key"
60 t.string "key"
69 t.string "value_type"
61 t.string "value_type"
70 t.string "value"
62 t.string "value"
71 - t.datetime "created_at"
63 + t.datetime "created_at", :null => false
72 - t.datetime "updated_at"
64 + t.datetime "updated_at", :null => false
73 t.text "description"
65 t.text "description"
74 end
66 end
75
67
76 create_table "grader_processes", :force => true do |t|
68 create_table "grader_processes", :force => true do |t|
77 t.string "host", :limit => 20
69 t.string "host", :limit => 20
78 t.integer "pid"
70 t.integer "pid"
79 t.string "mode"
71 t.string "mode"
80 t.boolean "active"
72 t.boolean "active"
81 - t.datetime "created_at"
73 + t.datetime "created_at", :null => false
82 - t.datetime "updated_at"
74 + t.datetime "updated_at", :null => false
83 t.integer "task_id"
75 t.integer "task_id"
84 t.string "task_type"
76 t.string "task_type"
85 t.boolean "terminated"
77 t.boolean "terminated"
86 end
78 end
87
79
88 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
80 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
89
81
90 create_table "languages", :force => true do |t|
82 create_table "languages", :force => true do |t|
91 t.string "name", :limit => 10
83 t.string "name", :limit => 10
92 t.string "pretty_name"
84 t.string "pretty_name"
93 t.string "ext", :limit => 10
85 t.string "ext", :limit => 10
94 t.string "common_ext"
86 t.string "common_ext"
95 end
87 end
96
88
89 + create_table "logins", :force => true do |t|
90 + t.string "user_id"
91 + t.string "ip_address"
92 + t.datetime "created_at", :null => false
93 + t.datetime "updated_at", :null => false
94 + end
95 +
97 create_table "messages", :force => true do |t|
96 create_table "messages", :force => true do |t|
98 t.integer "sender_id"
97 t.integer "sender_id"
99 t.integer "receiver_id"
98 t.integer "receiver_id"
100 t.integer "replying_message_id"
99 t.integer "replying_message_id"
101 t.text "body"
100 t.text "body"
102 t.boolean "replied"
101 t.boolean "replied"
103 - t.datetime "created_at"
102 + t.datetime "created_at", :null => false
104 - t.datetime "updated_at"
103 + t.datetime "updated_at", :null => false
105 end
104 end
106
105
107 create_table "problems", :force => true do |t|
106 create_table "problems", :force => true do |t|
108 - t.string "name", :limit => 30
107 + t.string "name", :limit => 30
109 - t.string "full_name"
108 + t.string "full_name"
110 - t.integer "full_score"
109 + t.integer "full_score"
111 - t.date "date_added"
110 + t.date "date_added"
112 - t.boolean "available"
111 + t.boolean "available"
113 - t.string "url"
112 + t.string "url"
114 - t.integer "description_id"
113 + t.integer "description_id"
115 - t.boolean "test_allowed"
114 + t.boolean "test_allowed"
116 - t.boolean "output_only"
115 + t.boolean "output_only"
117 - t.integer "level", :default => 0
116 + t.string "description_filename"
118 - t.datetime "updated_at"
119 - t.string "description_filename"
120 end
117 end
121
118
122 create_table "rights", :force => true do |t|
119 create_table "rights", :force => true do |t|
123 t.string "name"
120 t.string "name"
124 t.string "controller"
121 t.string "controller"
125 t.string "action"
122 t.string "action"
126 end
123 end
127
124
128 create_table "rights_roles", :id => false, :force => true do |t|
125 create_table "rights_roles", :id => false, :force => true do |t|
129 t.integer "right_id"
126 t.integer "right_id"
130 t.integer "role_id"
127 t.integer "role_id"
131 end
128 end
132
129
133 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
130 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
134
131
135 create_table "roles", :force => true do |t|
132 create_table "roles", :force => true do |t|
136 t.string "name"
133 t.string "name"
137 end
134 end
138
135
139 create_table "roles_users", :id => false, :force => true do |t|
136 create_table "roles_users", :id => false, :force => true do |t|
140 t.integer "role_id"
137 t.integer "role_id"
141 t.integer "user_id"
138 t.integer "user_id"
142 end
139 end
143
140
144 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
141 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
145
142
146 create_table "sessions", :force => true do |t|
143 create_table "sessions", :force => true do |t|
147 t.string "session_id"
144 t.string "session_id"
148 t.text "data"
145 t.text "data"
149 t.datetime "updated_at"
146 t.datetime "updated_at"
150 end
147 end
151
148
152 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
149 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
153 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
150 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
154
151
155 create_table "sites", :force => true do |t|
152 create_table "sites", :force => true do |t|
156 t.string "name"
153 t.string "name"
157 t.boolean "started"
154 t.boolean "started"
158 t.datetime "start_time"
155 t.datetime "start_time"
159 - t.datetime "created_at"
156 + t.datetime "created_at", :null => false
160 - t.datetime "updated_at"
157 + t.datetime "updated_at", :null => false
161 t.integer "country_id"
158 t.integer "country_id"
162 t.string "password"
159 t.string "password"
163 end
160 end
164
161
165 - create_table "submission_statuses", :force => true do |t|
166 - t.integer "user_id"
167 - t.integer "problem_id"
168 - t.boolean "passed"
169 - t.integer "submission_count"
170 - t.datetime "created_at"
171 - t.datetime "updated_at"
172 - end
173 -
174 create_table "submissions", :force => true do |t|
162 create_table "submissions", :force => true do |t|
175 t.integer "user_id"
163 t.integer "user_id"
176 t.integer "problem_id"
164 t.integer "problem_id"
177 t.integer "language_id"
165 t.integer "language_id"
178 t.text "source"
166 t.text "source"
179 t.binary "binary"
167 t.binary "binary"
180 t.datetime "submitted_at"
168 t.datetime "submitted_at"
181 t.datetime "compiled_at"
169 t.datetime "compiled_at"
182 t.text "compiler_message"
170 t.text "compiler_message"
183 t.datetime "graded_at"
171 t.datetime "graded_at"
184 t.integer "points"
172 t.integer "points"
185 t.text "grader_comment"
173 t.text "grader_comment"
186 t.integer "number"
174 t.integer "number"
187 t.string "source_filename"
175 t.string "source_filename"
188 end
176 end
189
177
190 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
178 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
191 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
179 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
192
180
193 create_table "tasks", :force => true do |t|
181 create_table "tasks", :force => true do |t|
194 t.integer "submission_id"
182 t.integer "submission_id"
195 t.datetime "created_at"
183 t.datetime "created_at"
196 t.integer "status"
184 t.integer "status"
197 t.datetime "updated_at"
185 t.datetime "updated_at"
198 end
186 end
199
187
200 - create_table "test_pair_assignments", :force => true do |t|
201 - t.integer "user_id"
202 - t.integer "problem_id"
203 - t.integer "test_pair_id"
204 - t.integer "test_pair_number"
205 - t.integer "request_number"
206 - t.datetime "created_at"
207 - t.datetime "updated_at"
208 - t.boolean "submitted"
209 - end
210 -
211 create_table "test_pairs", :force => true do |t|
188 create_table "test_pairs", :force => true do |t|
212 t.integer "problem_id"
189 t.integer "problem_id"
213 t.text "input", :limit => 16777215
190 t.text "input", :limit => 16777215
214 t.text "solution", :limit => 16777215
191 t.text "solution", :limit => 16777215
215 - t.datetime "created_at"
192 + t.datetime "created_at", :null => false
216 - t.datetime "updated_at"
193 + t.datetime "updated_at", :null => false
217 - t.integer "number"
218 end
194 end
219
195
220 create_table "test_requests", :force => true do |t|
196 create_table "test_requests", :force => true do |t|
221 t.integer "user_id"
197 t.integer "user_id"
222 t.integer "problem_id"
198 t.integer "problem_id"
223 t.integer "submission_id"
199 t.integer "submission_id"
224 t.string "input_file_name"
200 t.string "input_file_name"
225 t.string "output_file_name"
201 t.string "output_file_name"
226 t.string "running_stat"
202 t.string "running_stat"
227 t.integer "status"
203 t.integer "status"
228 - t.datetime "updated_at"
204 + t.datetime "updated_at", :null => false
229 t.datetime "submitted_at"
205 t.datetime "submitted_at"
230 t.datetime "compiled_at"
206 t.datetime "compiled_at"
231 t.text "compiler_message"
207 t.text "compiler_message"
232 t.datetime "graded_at"
208 t.datetime "graded_at"
233 t.string "grader_comment"
209 t.string "grader_comment"
234 - t.datetime "created_at"
210 + t.datetime "created_at", :null => false
235 t.float "running_time"
211 t.float "running_time"
236 t.string "exit_status"
212 t.string "exit_status"
237 t.integer "memory_usage"
213 t.integer "memory_usage"
238 end
214 end
239
215
240 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
216 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
241
217
242 create_table "user_contest_stats", :force => true do |t|
218 create_table "user_contest_stats", :force => true do |t|
243 t.integer "user_id"
219 t.integer "user_id"
244 t.datetime "started_at"
220 t.datetime "started_at"
245 - t.datetime "created_at"
221 + t.datetime "created_at", :null => false
246 - t.datetime "updated_at"
222 + t.datetime "updated_at", :null => false
247 t.boolean "forced_logout"
223 t.boolean "forced_logout"
248 end
224 end
249
225
250 create_table "users", :force => true do |t|
226 create_table "users", :force => true do |t|
251 - t.string "login", :limit => 50
227 + t.string "login", :limit => 50
252 t.string "full_name"
228 t.string "full_name"
253 t.string "hashed_password"
229 t.string "hashed_password"
254 - t.string "salt", :limit => 5
230 + t.string "salt", :limit => 5
255 t.string "alias"
231 t.string "alias"
256 t.string "email"
232 t.string "email"
257 t.integer "site_id"
233 t.integer "site_id"
258 t.integer "country_id"
234 t.integer "country_id"
259 - t.boolean "activated", :default => false
235 + t.boolean "activated", :default => false
260 t.datetime "created_at"
236 t.datetime "created_at"
261 t.datetime "updated_at"
237 t.datetime "updated_at"
262 - t.string "member1_full_name"
263 - t.string "member2_full_name"
264 - t.string "member3_full_name"
265 - t.boolean "high_school"
266 - t.string "member1_school_name"
267 - t.string "member2_school_name"
268 - t.string "member3_school_name"
269 end
238 end
270
239
271 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
240 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
272
241
273 end
242 end
You need to be logged in to leave comments. Login now