Description:
added user settings
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@37 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
r13:a663af8c2813 - - 15 files changed: 163 inserted, 108 deleted
@@ -0,0 +1,15 | |||||
|
|
1 | + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
|
|
2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
|
3 | + | ||
|
|
4 | + <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
|
|
5 | + <head> | ||
|
|
6 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | ||
|
|
7 | + <title>Grader!</title> | ||
|
|
8 | + <%= stylesheet_link_tag 'application' %> | ||
|
|
9 | + </head> | ||
|
|
10 | + <body> | ||
|
|
11 | + | ||
|
|
12 | + <%= yield %> | ||
|
|
13 | + | ||
|
|
14 | + </body> | ||
|
|
15 | + </html> |
@@ -0,0 +1,92 | |||||
|
|
1 | + # This file is auto-generated from the current state of the database. Instead of editing this file, | ||
|
|
2 | + # please use the migrations feature of ActiveRecord to incrementally modify your database, and | ||
|
|
3 | + # then regenerate this schema definition. | ||
|
|
4 | + # | ||
|
|
5 | + # Note that this schema.rb definition is the authoritative source for your database schema. If you need | ||
|
|
6 | + # to create the application database on another system, you should be using db:schema:load, not running | ||
|
|
7 | + # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
|
|
8 | + # you'll amass, the slower it'll run and the greater likelihood for issues). | ||
|
|
9 | + # | ||
|
|
10 | + # It's strongly recommended to check this file into your version control system. | ||
|
|
11 | + | ||
|
|
12 | + ActiveRecord::Schema.define(:version => 11) do | ||
|
|
13 | + | ||
|
|
14 | + create_table "languages", :force => true do |t| | ||
|
|
15 | + t.string "name", :limit => 10 | ||
|
|
16 | + t.string "pretty_name" | ||
|
|
17 | + t.string "ext", :limit => 10 | ||
|
|
18 | + end | ||
|
|
19 | + | ||
|
|
20 | + create_table "problems", :force => true do |t| | ||
|
|
21 | + t.string "name", :limit => 30 | ||
|
|
22 | + t.string "full_name" | ||
|
|
23 | + t.integer "full_score" | ||
|
|
24 | + t.date "date_added" | ||
|
|
25 | + t.boolean "available" | ||
|
|
26 | + end | ||
|
|
27 | + | ||
|
|
28 | + create_table "rights", :force => true do |t| | ||
|
|
29 | + t.string "name" | ||
|
|
30 | + t.string "controller" | ||
|
|
31 | + t.string "action" | ||
|
|
32 | + end | ||
|
|
33 | + | ||
|
|
34 | + create_table "rights_roles", :id => false, :force => true do |t| | ||
|
|
35 | + t.integer "right_id" | ||
|
|
36 | + t.integer "role_id" | ||
|
|
37 | + end | ||
|
|
38 | + | ||
|
|
39 | + add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" | ||
|
|
40 | + | ||
|
|
41 | + create_table "roles", :force => true do |t| | ||
|
|
42 | + t.string "name" | ||
|
|
43 | + end | ||
|
|
44 | + | ||
|
|
45 | + create_table "roles_users", :id => false, :force => true do |t| | ||
|
|
46 | + t.integer "role_id" | ||
|
|
47 | + t.integer "user_id" | ||
|
|
48 | + end | ||
|
|
49 | + | ||
|
|
50 | + add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" | ||
|
|
51 | + | ||
|
|
52 | + create_table "sessions", :force => true do |t| | ||
|
|
53 | + t.string "session_id" | ||
|
|
54 | + t.text "data" | ||
|
|
55 | + t.datetime "updated_at" | ||
|
|
56 | + end | ||
|
|
57 | + | ||
|
|
58 | + add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" | ||
|
|
59 | + add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" | ||
|
|
60 | + | ||
|
|
61 | + create_table "submissions", :force => true do |t| | ||
|
|
62 | + t.integer "user_id" | ||
|
|
63 | + t.integer "problem_id" | ||
|
|
64 | + t.integer "language_id" | ||
|
|
65 | + t.text "source" | ||
|
|
66 | + t.binary "binary" | ||
|
|
67 | + t.datetime "submitted_at" | ||
|
|
68 | + t.datetime "compiled_at" | ||
|
|
69 | + t.text "compiler_message" | ||
|
|
70 | + t.datetime "graded_at" | ||
|
|
71 | + t.integer "points" | ||
|
|
72 | + t.text "grader_comment" | ||
|
|
73 | + end | ||
|
|
74 | + | ||
|
|
75 | + add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" | ||
|
|
76 | + | ||
|
|
77 | + create_table "tasks", :force => true do |t| | ||
|
|
78 | + t.integer "submission_id" | ||
|
|
79 | + t.datetime "created_at" | ||
|
|
80 | + end | ||
|
|
81 | + | ||
|
|
82 | + create_table "users", :force => true do |t| | ||
|
|
83 | + t.string "login", :limit => 10 | ||
|
|
84 | + t.string "full_name" | ||
|
|
85 | + t.string "hashed_password" | ||
|
|
86 | + t.string "salt", :limit => 5 | ||
|
|
87 | + t.string "alias" | ||
|
|
88 | + end | ||
|
|
89 | + | ||
|
|
90 | + add_index "users", ["login"], :name => "index_users_on_login", :unique => true | ||
|
|
91 | + | ||
|
|
92 | + end |
@@ -1,36 +1,37 | |||||
|
1 | class MainController < ApplicationController |
|
1 | class MainController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate, :except => [:index, :login] |
|
3 | before_filter :authenticate, :except => [:index, :login] |
|
4 |
|
4 | ||
|
5 | verify :method => :post, :only => [:submit], |
|
5 | verify :method => :post, :only => [:submit], |
|
6 | :redirect_to => { :action => :index } |
|
6 | :redirect_to => { :action => :index } |
|
7 |
|
7 | ||
|
8 | def index |
|
8 | def index |
|
9 | redirect_to :action => 'login' |
|
9 | redirect_to :action => 'login' |
|
10 | end |
|
10 | end |
|
11 |
|
11 | ||
|
12 | def login |
|
12 | def login |
|
|
13 | + MainController.layout 'login' | ||
|
13 | reset_session |
|
14 | reset_session |
|
14 | end |
|
15 | end |
|
15 |
|
16 | ||
|
16 | def list |
|
17 | def list |
|
17 | @problems = Problem.find_available_problems |
|
18 | @problems = Problem.find_available_problems |
|
18 | @prob_submissions = Array.new |
|
19 | @prob_submissions = Array.new |
|
19 | @user = User.find(session[:user_id]) |
|
20 | @user = User.find(session[:user_id]) |
|
20 | @problems.each do |p| |
|
21 | @problems.each do |p| |
|
21 | c, sub = Submission.find_by_user_and_problem(@user.id,p.id) |
|
22 | c, sub = Submission.find_by_user_and_problem(@user.id,p.id) |
|
22 | @prob_submissions << [c,sub] |
|
23 | @prob_submissions << [c,sub] |
|
23 | end |
|
24 | end |
|
24 | end |
|
25 | end |
|
25 |
|
26 | ||
|
26 | def submit |
|
27 | def submit |
|
27 | submission = Submission.new(params[:submission]) |
|
28 | submission = Submission.new(params[:submission]) |
|
28 | submission.user_id = session[:user_id] |
|
29 | submission.user_id = session[:user_id] |
|
29 | submission.language_id = 0 |
|
30 | submission.language_id = 0 |
|
30 | source = params['file'].read |
|
31 | source = params['file'].read |
|
31 | if source.length > 100_000 |
|
32 | if source.length > 100_000 |
|
32 | flash[:notice] = 'Error: file too long' |
|
33 | flash[:notice] = 'Error: file too long' |
|
33 | elsif (lang = Submission.find_language_in_source(source))==nil |
|
34 | elsif (lang = Submission.find_language_in_source(source))==nil |
|
34 | flash[:notice] = 'Error: cannot determine language used' |
|
35 | flash[:notice] = 'Error: cannot determine language used' |
|
35 | elsif ((submission.problem_id==-1) and |
|
36 | elsif ((submission.problem_id==-1) and |
|
36 | !(problem=Submission.find_problem_in_source(source))) |
|
37 | !(problem=Submission.find_problem_in_source(source))) |
@@ -1,2 +1,27 | |||||
|
1 | class UsersController < ApplicationController |
|
1 | class UsersController < ApplicationController |
|
|
2 | + | ||
|
|
3 | + before_filter :authenticate | ||
|
|
4 | + | ||
|
|
5 | + verify :method => :post, :only => [:chg_passwd], | ||
|
|
6 | + :redirect_to => { :action => :index } | ||
|
|
7 | + | ||
|
|
8 | + in_place_edit_for :user, :full_name | ||
|
|
9 | + in_place_edit_for :user, :alias | ||
|
|
10 | + | ||
|
|
11 | + def index | ||
|
|
12 | + @user = User.find(session[:user_id]) | ||
|
2 | end |
|
13 | end |
|
|
14 | + | ||
|
|
15 | + def chg_passwd | ||
|
|
16 | + user = User.find(session[:user_id]) | ||
|
|
17 | + user.password = params[:passwd] | ||
|
|
18 | + user.password_confirmation = params[:passwd_verify] | ||
|
|
19 | + if user.save | ||
|
|
20 | + flash[:notice] = 'password changed' | ||
|
|
21 | + else | ||
|
|
22 | + flash[:notice] = 'Error: password changing failed' | ||
|
|
23 | + end | ||
|
|
24 | + redirect_to :action => 'index' | ||
|
|
25 | + end | ||
|
|
26 | + | ||
|
|
27 | + end |
@@ -1,3 +1,24 | |||||
|
1 | # Methods added to this helper will be available to all templates in the application. |
|
1 | # Methods added to this helper will be available to all templates in the application. |
|
2 | module ApplicationHelper |
|
2 | module ApplicationHelper |
|
|
3 | + | ||
|
|
4 | + def user_options | ||
|
|
5 | + options = '' | ||
|
|
6 | + user = User.find(session[:user_id]) | ||
|
|
7 | + if user.admin? | ||
|
|
8 | + options = options + ' ' + | ||
|
|
9 | + (link_to_unless_current '[Problem admin]', | ||
|
|
10 | + :controller => 'problems', :action => 'index') | ||
|
|
11 | + options = options + ' ' + | ||
|
|
12 | + (link_to_unless_current '[User admin]', | ||
|
|
13 | + :controller => 'user_admin', :action => 'index') | ||
|
3 | end |
|
14 | end |
|
|
15 | + options += link_to_unless_current '[Main]', | ||
|
|
16 | + :controller => 'main', :action => 'list' | ||
|
|
17 | + options += link_to_unless_current '[Settings]', | ||
|
|
18 | + :controller => 'users', :action => 'index' | ||
|
|
19 | + options = options + ' ' + | ||
|
|
20 | + link_to('[Log out]', {:controller => 'main', :action => 'login'}) | ||
|
|
21 | + options | ||
|
|
22 | + end | ||
|
|
23 | + | ||
|
|
24 | + end |
@@ -1,42 +1,26 | |||||
|
1 | module MainHelper |
|
1 | module MainHelper |
|
2 |
|
2 | ||
|
3 | - def user_options |
|
||
|
4 | - options = '' |
|
||
|
5 | - user = User.find(session[:user_id]) |
|
||
|
6 | - if user.admin? |
|
||
|
7 | - options = options + ' ' + |
|
||
|
8 | - link_to('[Problem admin]', |
|
||
|
9 | - {:controller => 'problems', :action => 'index'}) |
|
||
|
10 | - options = options + ' ' + |
|
||
|
11 | - link_to('[User admin]', |
|
||
|
12 | - {:controller => 'user_admin', :action => 'index'}) |
|
||
|
13 | - end |
|
||
|
14 | - options = options + ' ' + |
|
||
|
15 | - link_to('[Log out]', {:controller => 'main', :action => 'login'}) |
|
||
|
16 | - options |
|
||
|
17 | - end |
|
||
|
18 | - |
|
||
|
19 | def format_short_time(time) |
|
3 | def format_short_time(time) |
|
20 | now = Time.now |
|
4 | now = Time.now |
|
21 | st = '' |
|
5 | st = '' |
|
22 | if (time.yday != now.yday) or |
|
6 | if (time.yday != now.yday) or |
|
23 | (time.year != now.year) |
|
7 | (time.year != now.year) |
|
24 | st = time.strftime("%x") |
|
8 | st = time.strftime("%x") |
|
25 | end |
|
9 | end |
|
26 | st + time.strftime("%X") |
|
10 | st + time.strftime("%X") |
|
27 | end |
|
11 | end |
|
28 |
|
12 | ||
|
29 | def format_compiler_msg(sub) |
|
13 | def format_compiler_msg(sub) |
|
30 | <<cmpmsg |
|
14 | <<cmpmsg |
|
31 | <div> |
|
15 | <div> |
|
32 | <div><a href="#" onClick="n = this.parentNode.parentNode.lastChild; |
|
16 | <div><a href="#" onClick="n = this.parentNode.parentNode.lastChild; |
|
33 | if(n.style.display == 'none') { n.style.display = 'block'; } |
|
17 | if(n.style.display == 'none') { n.style.display = 'block'; } |
|
34 | else {n.style.display ='none'; } return false;"> |
|
18 | else {n.style.display ='none'; } return false;"> |
|
35 | Compiler message</a> (click to see)</div> |
|
19 | Compiler message</a> (click to see)</div> |
|
36 | <div style="display: none"> |
|
20 | <div style="display: none"> |
|
37 | <div class="compilermsgbody" style="border: thin solid grey; margin: 2px"> |
|
21 | <div class="compilermsgbody" style="border: thin solid grey; margin: 2px"> |
|
38 | #{h(sub.compiler_message).gsub(/\n/,'<br/>')} |
|
22 | #{h(sub.compiler_message).gsub(/\n/,'<br/>')} |
|
39 | </div> |
|
23 | </div> |
|
40 | </div></div> |
|
24 | </div></div> |
|
41 | cmpmsg |
|
25 | cmpmsg |
|
42 | end |
|
26 | end |
@@ -1,15 +1,22 | |||||
|
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 |
|
3 | ||
|
4 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|
4 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|
5 | <head> |
|
5 | <head> |
|
6 | <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> |
|
6 | <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> |
|
7 | <title>Grader!</title> |
|
7 | <title>Grader!</title> |
|
8 | <%= stylesheet_link_tag 'application' %> |
|
8 | <%= stylesheet_link_tag 'application' %> |
|
|
9 | + <%= javascript_include_tag :defaults %> | ||
|
9 | </head> |
|
10 | </head> |
|
10 | <body> |
|
11 | <body> |
|
11 |
|
12 | ||
|
|
13 | + <div class="usermenu"> | ||
|
|
14 | + <%= user_options %> | ||
|
|
15 | + </div> | ||
|
|
16 | + | ||
|
|
17 | + <p style="color: green"><%= flash[:notice] %></p> | ||
|
|
18 | + | ||
|
12 | <%= yield %> |
|
19 | <%= yield %> |
|
13 |
|
20 | ||
|
14 | </body> |
|
21 | </body> |
|
15 | </html> |
|
22 | </html> |
@@ -1,31 +1,27 | |||||
|
1 | <h1>Hello <%=h @user.full_name %></h1> |
|
1 | <h1>Hello <%=h @user.full_name %></h1> |
|
2 | (<%= Time.new %>) |
|
2 | (<%= Time.new %>) |
|
3 |
|
3 | ||
|
4 | - <div class="usermenu"> |
|
||
|
5 | - <%= user_options %> |
|
||
|
6 | - </div> |
|
||
|
7 | - |
|
||
|
8 | <div class="submitbox"> |
|
4 | <div class="submitbox"> |
|
9 | <% form_tag({:action => 'submit'}, :multipart => true) do %> |
|
5 | <% form_tag({:action => 'submit'}, :multipart => true) do %> |
|
10 | Problem: <%= select 'submission', 'problem_id', |
|
6 | Problem: <%= select 'submission', 'problem_id', |
|
11 | [['Specified in header','-1']] + |
|
7 | [['Specified in header','-1']] + |
|
12 | @problems.collect {|p| [p.full_name, p.id]}, |
|
8 | @problems.collect {|p| [p.full_name, p.id]}, |
|
13 | :selected => '-1' %> |
|
9 | :selected => '-1' %> |
|
14 | File: <%= file_field_tag 'file' %> |
|
10 | File: <%= file_field_tag 'file' %> |
|
15 | <%= submit_tag 'Submit' %> |
|
11 | <%= submit_tag 'Submit' %> |
|
16 | <% end %> |
|
12 | <% end %> |
|
17 | </div> |
|
13 | </div> |
|
18 |
|
14 | ||
|
19 | <hr/> |
|
15 | <hr/> |
|
20 |
|
16 | ||
|
21 | <p style="color: red"><%= flash[:notice] %></p> |
|
17 | <p style="color: red"><%= flash[:notice] %></p> |
|
22 |
|
18 | ||
|
23 | <div class="problist"> |
|
19 | <div class="problist"> |
|
24 | <% i = 0 %> |
|
20 | <% i = 0 %> |
|
25 | <% @problems.each do |p| %> |
|
21 | <% @problems.each do |p| %> |
|
26 | <div class="problist-each"> |
|
22 | <div class="problist-each"> |
|
27 | <div class="probname"> |
|
23 | <div class="probname"> |
|
28 | <%= "#{i+1}: #{p.full_name} (#{p.name})" %> |
|
24 | <%= "#{i+1}: #{p.full_name} (#{p.name})" %> |
|
29 | </div> |
|
25 | </div> |
|
30 | <div class="subinfo"> |
|
26 | <div class="subinfo"> |
|
31 | <%= format_submission(@prob_submissions[i][1], |
|
27 | <%= format_submission(@prob_submissions[i][1], |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
You need to be logged in to leave comments.
Login now