Description:
change login page, always redirect index to login
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@9 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
r6:1828434e55cd - - 4 files changed: 9 inserted, 7 deleted
@@ -1,56 +1,57 | |||||
|
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 | end |
|
10 | end |
|
10 |
|
11 | ||
|
11 | def login |
|
12 | def login |
|
12 | reset_session |
|
13 | reset_session |
|
13 | end |
|
14 | end |
|
14 |
|
15 | ||
|
15 | def list |
|
16 | def list |
|
16 | @problems = Problem.find_available_problems |
|
17 | @problems = Problem.find_available_problems |
|
17 | @prob_submissions = Array.new |
|
18 | @prob_submissions = Array.new |
|
18 | @user = User.find(session[:user_id]) |
|
19 | @user = User.find(session[:user_id]) |
|
19 | @problems.each do |p| |
|
20 | @problems.each do |p| |
|
20 | c, sub = Submission.find_by_user_and_problem(@user.id,p.id) |
|
21 | c, sub = Submission.find_by_user_and_problem(@user.id,p.id) |
|
21 | @prob_submissions << [c,sub] |
|
22 | @prob_submissions << [c,sub] |
|
22 | end |
|
23 | end |
|
23 | end |
|
24 | end |
|
24 |
|
25 | ||
|
25 | def submit |
|
26 | def submit |
|
26 | submission = Submission.new(params[:submission]) |
|
27 | submission = Submission.new(params[:submission]) |
|
27 | submission.user_id = session[:user_id] |
|
28 | submission.user_id = session[:user_id] |
|
28 | submission.language_id = 0 |
|
29 | submission.language_id = 0 |
|
29 | source = params['file'].read |
|
30 | source = params['file'].read |
|
30 | if source.length > 100_000 |
|
31 | if source.length > 100_000 |
|
31 | flash[:notice] = 'Error: file too long' |
|
32 | flash[:notice] = 'Error: file too long' |
|
32 | elsif (lang = Submission.find_language_in_source(source))==nil |
|
33 | elsif (lang = Submission.find_language_in_source(source))==nil |
|
33 | flash[:notice] = 'Error: cannot determine language used' |
|
34 | flash[:notice] = 'Error: cannot determine language used' |
|
34 | elsif ((submission.problem_id==-1) and |
|
35 | elsif ((submission.problem_id==-1) and |
|
35 | !(problem=Submission.find_problem_in_source(source))) |
|
36 | !(problem=Submission.find_problem_in_source(source))) |
|
36 | flash[:notice] = 'Error: cannot determine problem submitted' |
|
37 | flash[:notice] = 'Error: cannot determine problem submitted' |
|
37 | elsif ((submission.problem_id==-1) and |
|
38 | elsif ((submission.problem_id==-1) and |
|
38 | (problem.available == false)) |
|
39 | (problem.available == false)) |
|
39 | flash[:notice] = 'Error: problem is not available' |
|
40 | flash[:notice] = 'Error: problem is not available' |
|
40 | else |
|
41 | else |
|
41 | submission.problem_id = problem.id if submission.problem_id == -1 |
|
42 | submission.problem_id = problem.id if submission.problem_id == -1 |
|
42 | submission.source = source |
|
43 | submission.source = source |
|
43 | submission.language_id = lang.id |
|
44 | submission.language_id = lang.id |
|
44 | submission.submitted_at = Time.new |
|
45 | submission.submitted_at = Time.new |
|
45 | if submission.save == false |
|
46 | if submission.save == false |
|
46 | flash[:notice] = 'Error saving your submission' |
|
47 | flash[:notice] = 'Error saving your submission' |
|
47 | elsif Task.create(:submission_id => submission.id) == false |
|
48 | elsif Task.create(:submission_id => submission.id) == false |
|
48 | flash[:notice] = 'Error adding your submission to task queue' |
|
49 | flash[:notice] = 'Error adding your submission to task queue' |
|
49 | end |
|
50 | end |
|
50 | end |
|
51 | end |
|
51 | redirect_to :action => 'list' |
|
52 | redirect_to :action => 'list' |
|
52 | end |
|
53 | end |
|
53 |
|
54 | ||
|
54 | def get_source |
|
55 | def get_source |
|
55 | submission = Submission.find(params[:id]) |
|
56 | submission = Submission.find(params[:id]) |
|
56 | if submission.user_id == session[:user_id] |
|
57 | if submission.user_id == session[:user_id] |
@@ -1,19 +1,25 | |||||
|
1 |
- <h1> |
|
1 | + <h1>Grader</h1> |
|
|
2 | + | ||
|
|
3 | + <b>Welcome back!</b><br/> | ||
|
|
4 | + Please login to see the problem list.<br/><br/> | ||
|
2 |
|
5 | ||
|
3 | <% if flash[:notice] %> |
|
6 | <% if flash[:notice] %> |
|
4 | <hr> |
|
7 | <hr> |
|
5 | <b><%= flash[:notice] %></b> |
|
8 | <b><%= flash[:notice] %></b> |
|
6 | <hr> |
|
9 | <hr> |
|
7 | <% end %> |
|
10 | <% end %> |
|
8 |
|
11 | ||
|
|
12 | + <div style="border: solid 1px gray; padding: 2px; background: #f0f0f0;"> | ||
|
9 | <% form_tag :controller => 'login', :action => 'login' do %> |
|
13 | <% form_tag :controller => 'login', :action => 'login' do %> |
|
10 | <table> |
|
14 | <table> |
|
11 | <tr> |
|
15 | <tr> |
|
12 | <td align="right">User name:</td><td><%= text_field_tag 'login' %></td> |
|
16 | <td align="right">User name:</td><td><%= text_field_tag 'login' %></td> |
|
13 | </tr> |
|
17 | </tr> |
|
14 | <tr> |
|
18 | <tr> |
|
15 | <td align="right">Password:</td><td><%= password_field_tag %></td> |
|
19 | <td align="right">Password:</td><td><%= password_field_tag %></td> |
|
16 | </tr> |
|
20 | </tr> |
|
17 | </table> |
|
21 | </table> |
|
18 | <%= submit_tag 'Login' %> |
|
22 | <%= submit_tag 'Login' %> |
|
19 | <% end %> |
|
23 | <% end %> |
|
|
24 | + </div> | ||
|
|
25 | + |
@@ -1,23 +1,23 | |||||
|
1 | ActionController::Routing::Routes.draw do |map| |
|
1 | ActionController::Routing::Routes.draw do |map| |
|
2 | # The priority is based upon order of creation: first created -> highest priority. |
|
2 | # The priority is based upon order of creation: first created -> highest priority. |
|
3 |
|
3 | ||
|
4 | # Sample of regular route: |
|
4 | # Sample of regular route: |
|
5 | # map.connect 'products/:id', :controller => 'catalog', :action => 'view' |
|
5 | # map.connect 'products/:id', :controller => 'catalog', :action => 'view' |
|
6 | # Keep in mind you can assign values other than :controller and :action |
|
6 | # Keep in mind you can assign values other than :controller and :action |
|
7 |
|
7 | ||
|
8 | # Sample of named route: |
|
8 | # Sample of named route: |
|
9 | # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' |
|
9 | # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' |
|
10 | # This route can be invoked with purchase_url(:id => product.id) |
|
10 | # This route can be invoked with purchase_url(:id => product.id) |
|
11 |
|
11 | ||
|
12 | # You can have the root of your site routed by hooking up '' |
|
12 | # You can have the root of your site routed by hooking up '' |
|
13 | # -- just remember to delete public/index.html. |
|
13 | # -- just remember to delete public/index.html. |
|
14 | - map.connect '', :controller => 'main' |
|
14 | + map.connect '', :controller => 'main', :action => 'login' |
|
15 |
|
15 | ||
|
16 | # Allow downloading Web Service WSDL as a file with an extension |
|
16 | # Allow downloading Web Service WSDL as a file with an extension |
|
17 | # instead of a file named 'wsdl' |
|
17 | # instead of a file named 'wsdl' |
|
18 | map.connect ':controller/service.wsdl', :action => 'wsdl' |
|
18 | map.connect ':controller/service.wsdl', :action => 'wsdl' |
|
19 |
|
19 | ||
|
20 | # Install the default route as the lowest priority. |
|
20 | # Install the default route as the lowest priority. |
|
21 | map.connect ':controller/:action/:id.:format' |
|
21 | map.connect ':controller/:action/:id.:format' |
|
22 | map.connect ':controller/:action/:id' |
|
22 | map.connect ':controller/:action/:id' |
|
23 | end |
|
23 | end |
deleted file |
You need to be logged in to leave comments.
Login now