Description:
added 'user_setting_enabled' option git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@295 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r156:e751e4e9d100 - - 3 files changed: 16 inserted, 4 deleted

@@ -1,30 +1,31
1 class UsersController < ApplicationController
1 class UsersController < ApplicationController
2
2
3 - before_filter :authenticate
3 + before_filter :authenticate, :except => [:new, :register]
4
4
5 verify :method => :post, :only => [:chg_passwd],
5 verify :method => :post, :only => [:chg_passwd],
6 :redirect_to => { :action => :index }
6 :redirect_to => { :action => :index }
7
7
8 in_place_edit_for :user, :alias_for_editing
8 in_place_edit_for :user, :alias_for_editing
9 in_place_edit_for :user, :email_for_editing
9 in_place_edit_for :user, :email_for_editing
10
10
11 def index
11 def index
12 - # uncomment below to disable settings
12 + if !Configuration['system.user_setting_enabled']
13 - #redirect_to :controller => 'main', :action => 'list'
13 + redirect_to :controller => 'main', :action => 'list'
14 -
14 + else
15 @user = User.find(session[:user_id])
15 @user = User.find(session[:user_id])
16 end
16 end
17 + end
17
18
18 def chg_passwd
19 def chg_passwd
19 user = User.find(session[:user_id])
20 user = User.find(session[:user_id])
20 user.password = params[:passwd]
21 user.password = params[:passwd]
21 user.password_confirmation = params[:passwd_verify]
22 user.password_confirmation = params[:passwd_verify]
22 if user.save
23 if user.save
23 flash[:notice] = 'password changed'
24 flash[:notice] = 'password changed'
24 else
25 else
25 flash[:notice] = 'Error: password changing failed'
26 flash[:notice] = 'Error: password changing failed'
26 end
27 end
27 redirect_to :action => 'index'
28 redirect_to :action => 'index'
28 end
29 end
29
30
30 end
31 end
@@ -1,115 +1,118
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
3
4 SYSTEM_MODE_CONF_KEY = 'system.mode'
4 SYSTEM_MODE_CONF_KEY = 'system.mode'
5
5
6 def user_header
6 def user_header
7 menu_items = ''
7 menu_items = ''
8 user = User.find(session[:user_id])
8 user = User.find(session[:user_id])
9
9
10 if (user!=nil) and (session[:admin])
10 if (user!=nil) and (session[:admin])
11 # admin menu
11 # admin menu
12 menu_items << "<b>Administrative task:</b> "
12 menu_items << "<b>Administrative task:</b> "
13 append_to menu_items, '[Announcements]', 'announcements', 'index'
13 append_to menu_items, '[Announcements]', 'announcements', 'index'
14 append_to menu_items, '[Msg console]', 'messages', 'console'
14 append_to menu_items, '[Msg console]', 'messages', 'console'
15 append_to menu_items, '[Problem admin]', 'problems', 'index'
15 append_to menu_items, '[Problem admin]', 'problems', 'index'
16 append_to menu_items, '[User admin]', 'user_admin', 'index'
16 append_to menu_items, '[User admin]', 'user_admin', 'index'
17 append_to menu_items, '[User stat]', 'user_admin', 'user_stat'
17 append_to menu_items, '[User stat]', 'user_admin', 'user_stat'
18 append_to menu_items, '[Graders]', 'graders', 'list'
18 append_to menu_items, '[Graders]', 'graders', 'list'
19 append_to menu_items, '[Site config]', 'configurations', 'index'
19 append_to menu_items, '[Site config]', 'configurations', 'index'
20 menu_items << "<br/>"
20 menu_items << "<br/>"
21 end
21 end
22
22
23 # main page
23 # main page
24 append_to menu_items, '[Main]', 'main', 'list'
24 append_to menu_items, '[Main]', 'main', 'list'
25 append_to menu_items, '[Messages]', 'messages', 'list'
25 append_to menu_items, '[Messages]', 'messages', 'list'
26
26
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
28 append_to menu_items, '[Tasks]', 'tasks', 'list'
28 append_to menu_items, '[Tasks]', 'tasks', 'list'
29 append_to menu_items, '[Submissions]', 'main', 'submission'
29 append_to menu_items, '[Submissions]', 'main', 'submission'
30 append_to menu_items, '[Test]', 'test', 'index'
30 append_to menu_items, '[Test]', 'test', 'index'
31 end
31 end
32 append_to menu_items, '[Help]', 'main', 'help'
32 append_to menu_items, '[Help]', 'main', 'help'
33 +
34 + if Configuration['system.user_setting_enabled']
33 append_to menu_items, '[Settings]', 'users', 'index'
35 append_to menu_items, '[Settings]', 'users', 'index'
36 + end
34 append_to menu_items, '[Log out]', 'main', 'login'
37 append_to menu_items, '[Log out]', 'main', 'login'
35
38
36 menu_items
39 menu_items
37 end
40 end
38
41
39 def append_to(option,label, controller, action)
42 def append_to(option,label, controller, action)
40 option << ' ' if option!=''
43 option << ' ' if option!=''
41 option << link_to_unless_current(label,
44 option << link_to_unless_current(label,
42 :controller => controller,
45 :controller => controller,
43 :action => action)
46 :action => action)
44 end
47 end
45
48
46 def format_short_time(time)
49 def format_short_time(time)
47 now = Time.now.gmtime
50 now = Time.now.gmtime
48 st = ''
51 st = ''
49 if (time.yday != now.yday) or
52 if (time.yday != now.yday) or
50 (time.year != now.year)
53 (time.year != now.year)
51 st = time.strftime("%x ")
54 st = time.strftime("%x ")
52 end
55 end
53 st + time.strftime("%X")
56 st + time.strftime("%X")
54 end
57 end
55
58
56 def read_textfile(fname,max_size=2048)
59 def read_textfile(fname,max_size=2048)
57 begin
60 begin
58 File.open(fname).read(max_size)
61 File.open(fname).read(max_size)
59 rescue
62 rescue
60 nil
63 nil
61 end
64 end
62 end
65 end
63
66
64 def user_title_bar(user)
67 def user_title_bar(user)
65 header = ''
68 header = ''
66 time_left = ''
69 time_left = ''
67
70
68 #
71 #
69 # if the contest is over
72 # if the contest is over
70 if Configuration[SYSTEM_MODE_CONF_KEY]=='contest'
73 if Configuration[SYSTEM_MODE_CONF_KEY]=='contest'
71 if user.site!=nil and user.site.finished?
74 if user.site!=nil and user.site.finished?
72 header = <<CONTEST_OVER
75 header = <<CONTEST_OVER
73 <tr><td colspan="2" align="center">
76 <tr><td colspan="2" align="center">
74 <span class="contest-over-msg">THE CONTEST IS OVER</span>
77 <span class="contest-over-msg">THE CONTEST IS OVER</span>
75 </td></tr>
78 </td></tr>
76 CONTEST_OVER
79 CONTEST_OVER
77 end
80 end
78 if user.site!=nil
81 if user.site!=nil
79 time_left = ". Time left: #{Time.at(user.site.time_left).gmtime.strftime("%X")}"
82 time_left = ". Time left: #{Time.at(user.site.time_left).gmtime.strftime("%X")}"
80 end
83 end
81 end
84 end
82
85
83 #
86 #
84 # if the contest is in the anaysis mode
87 # if the contest is in the anaysis mode
85 if Configuration[SYSTEM_MODE_CONF_KEY]=='analysis'
88 if Configuration[SYSTEM_MODE_CONF_KEY]=='analysis'
86 header = <<ANALYSISMODE
89 header = <<ANALYSISMODE
87 <tr><td colspan="2" align="center">
90 <tr><td colspan="2" align="center">
88 <span class="contest-over-msg">ANALYSIS MODE</span>
91 <span class="contest-over-msg">ANALYSIS MODE</span>
89 </td></tr>
92 </td></tr>
90 ANALYSISMODE
93 ANALYSISMODE
91 end
94 end
92
95
93 contest_name = Configuration['contest.name']
96 contest_name = Configuration['contest.name']
94
97
95 #
98 #
96 # build real title bar
99 # build real title bar
97 <<TITLEBAR
100 <<TITLEBAR
98 <div class="title">
101 <div class="title">
99 <table>
102 <table>
100 #{header}
103 #{header}
101 <tr>
104 <tr>
102 <td class="left-col">
105 <td class="left-col">
103 #{user.full_name}<br/>
106 #{user.full_name}<br/>
104 Current time is #{format_short_time(Time.new.gmtime)} UTC
107 Current time is #{format_short_time(Time.new.gmtime)} UTC
105 #{time_left}
108 #{time_left}
106 <br/>
109 <br/>
107 </td>
110 </td>
108 <td class="right-col">#{contest_name}</td>
111 <td class="right-col">#{contest_name}</td>
109 </tr>
112 </tr>
110 </table>
113 </table>
111 </div>
114 </div>
112 TITLEBAR
115 TITLEBAR
113 end
116 end
114
117
115 end
118 end
@@ -1,23 +1,31
1 class AddMoreOptionsToConfigurations < ActiveRecord::Migration
1 class AddMoreOptionsToConfigurations < ActiveRecord::Migration
2 def self.up
2 def self.up
3 # If the server is in contest mode and
3 # If the server is in contest mode and
4 # Configuration['contest.multisites'] is true
4 # Configuration['contest.multisites'] is true
5 # the menu for site administrator is shown.
5 # the menu for site administrator is shown.
6
6
7 Configuration.create(:key => 'contest.multisites',
7 Configuration.create(:key => 'contest.multisites',
8 :value_type => 'boolean',
8 :value_type => 'boolean',
9 :value => 'false')
9 :value => 'false')
10
10
11 # If Configuration['system.online_registration'] is true,
11 # If Configuration['system.online_registration'] is true,
12 # the registration menu would appear
12 # the registration menu would appear
13
13
14 Configuration.create(:key => 'system.online_registration',
14 Configuration.create(:key => 'system.online_registration',
15 :value_type => 'boolean',
15 :value_type => 'boolean',
16 :value => 'false')
16 :value => 'false')
17 +
18 + # If Configuration['system.user_setting_enabled'] is true,
19 + # users can change their settings
20 +
21 + Configuration.create(:key => 'system.user_setting_enabled',
22 + :value_type => 'boolean',
23 + :value => 'true')
17 end
24 end
18
25
19 def self.down
26 def self.down
20 Configuration.find_by_key('contest.multisites').destroy
27 Configuration.find_by_key('contest.multisites').destroy
21 Configuration.find_by_key('system.online_registration').destroy
28 Configuration.find_by_key('system.online_registration').destroy
29 + Configuration.find_by_key('system.user_setting_enabled').destroy
22 end
30 end
23 end
31 end
You need to be logged in to leave comments. Login now