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