Description:
start working on e-mail registration
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@294 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
r155:f1e975d4e9fc - - 14 files changed: 142 inserted, 6 deleted
@@ -0,0 +1,23 | |||
|
1 | + class AddMoreOptionsToConfigurations < ActiveRecord::Migration | |
|
2 | + def self.up | |
|
3 | + # If the server is in contest mode and | |
|
4 | + # Configuration['contest.multisites'] is true | |
|
5 | + # the menu for site administrator is shown. | |
|
6 | + | |
|
7 | + Configuration.create(:key => 'contest.multisites', | |
|
8 | + :value_type => 'boolean', | |
|
9 | + :value => 'false') | |
|
10 | + | |
|
11 | + # If Configuration['system.online_registration'] is true, | |
|
12 | + # the registration menu would appear | |
|
13 | + | |
|
14 | + Configuration.create(:key => 'system.online_registration', | |
|
15 | + :value_type => 'boolean', | |
|
16 | + :value => 'false') | |
|
17 | + end | |
|
18 | + | |
|
19 | + def self.down | |
|
20 | + Configuration.find_by_key('contest.multisites').destroy | |
|
21 | + Configuration.find_by_key('system.online_registration').destroy | |
|
22 | + end | |
|
23 | + end |
@@ -0,0 +1,15 | |||
|
1 | + class AddActivatedToUsers < ActiveRecord::Migration | |
|
2 | + def self.up | |
|
3 | + add_column :users, :activated, :boolean, :default => 0 | |
|
4 | + | |
|
5 | + User.find(:all).each do |user| | |
|
6 | + user.activated = true | |
|
7 | + user.save | |
|
8 | + end | |
|
9 | + end | |
|
10 | + | |
|
11 | + | |
|
12 | + def self.down | |
|
13 | + remove_column :users, :activated | |
|
14 | + end | |
|
15 | + end |
@@ -0,0 +1,3 | |||
|
1 | + #!/usr/bin/env ruby | |
|
2 | + require File.dirname(__FILE__) + '/../config/boot' | |
|
3 | + require 'commands/dbconsole' |
@@ -0,0 +1,3 | |||
|
1 | + #!/usr/bin/env ruby | |
|
2 | + require File.dirname(__FILE__) + '/../../config/boot' | |
|
3 | + require 'commands/performance/request' |
@@ -0,0 +1,53 | |||
|
1 | + | |
|
2 | + require File.dirname(__FILE__) + '/../spec_helper' | |
|
3 | + | |
|
4 | + describe User do | |
|
5 | + | |
|
6 | + before(:each) do | |
|
7 | + @password = "hello" | |
|
8 | + @salt = "123" | |
|
9 | + @john = stub_model(User, :salt => @salt, | |
|
10 | + :hashed_password => User.encrypt(@password,@salt)) | |
|
11 | + end | |
|
12 | + | |
|
13 | + it "should authenticate activated user" do | |
|
14 | + @john.should_receive(:activated).and_return(true) | |
|
15 | + @john.authenticated?(@password).should == true | |
|
16 | + end | |
|
17 | + | |
|
18 | + it "should not authenticate inactivated user" do | |
|
19 | + @john.should_receive(:activated).and_return(false) | |
|
20 | + @john.authenticated?(@password).should == false | |
|
21 | + end | |
|
22 | + | |
|
23 | + it "should not authenticate user with incorrect password" do | |
|
24 | + @john.should_receive(:activated).and_return(true) | |
|
25 | + @john.should_receive(:hashed_password).and_return("byebye") | |
|
26 | + @john.authenticated?(@password).should == false | |
|
27 | + end | |
|
28 | + | |
|
29 | + end | |
|
30 | + | |
|
31 | + describe User, "during registration" do | |
|
32 | + | |
|
33 | + class User | |
|
34 | + public :encrypt_new_password | |
|
35 | + end | |
|
36 | + | |
|
37 | + before(:each) do | |
|
38 | + @john = User.new(:login => 'john', :password => 'hello') | |
|
39 | + @john.encrypt_new_password | |
|
40 | + end | |
|
41 | + | |
|
42 | + it "should produce and accept activation key" do | |
|
43 | + activation_key = @john.activation_key | |
|
44 | + | |
|
45 | + @john.verify_activation_key(activation_key).should == true | |
|
46 | + end | |
|
47 | + | |
|
48 | + it "should not accept invalid activation key" do | |
|
49 | + @john.verify_activation_key("12345").should == false | |
|
50 | + end | |
|
51 | + | |
|
52 | + | |
|
53 | + end |
@@ -1,94 +1,96 | |||
|
1 | 1 | class UserAdminController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | list |
|
7 | 7 | render :action => 'list' |
|
8 | 8 | end |
|
9 | 9 | |
|
10 | 10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 | 11 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
12 | 12 | :redirect_to => { :action => :list } |
|
13 | 13 | |
|
14 | 14 | def list |
|
15 | 15 | @users = User.find(:all) |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def show |
|
19 | 19 | @user = User.find(params[:id]) |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def new |
|
23 | 23 | @user = User.new |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def create |
|
27 | 27 | @user = User.new(params[:user]) |
|
28 | + @user.activated = true | |
|
28 | 29 | if @user.save |
|
29 | 30 | flash[:notice] = 'User was successfully created.' |
|
30 | 31 | redirect_to :action => 'list' |
|
31 | 32 | else |
|
32 | 33 | render :action => 'new' |
|
33 | 34 | end |
|
34 | 35 | end |
|
35 | 36 | |
|
36 | 37 | def create_from_list |
|
37 | 38 | lines = params[:user_list] |
|
38 | 39 | lines.split("\n").each do |line| |
|
39 | 40 | items = line.chomp.split(',') |
|
40 | 41 | if items.length==4 |
|
41 | 42 | user = User.new |
|
42 | 43 | user.login = items[0] |
|
43 | 44 | user.full_name = items[1] |
|
44 | 45 | user.alias = items[2] |
|
45 | 46 | user.password = items[3] |
|
46 | 47 | user.password_confirmation = items[3] |
|
48 | + user.activated = true | |
|
47 | 49 | user.save |
|
48 | 50 | end |
|
49 | 51 | end |
|
50 | 52 | redirect_to :action => 'list' |
|
51 | 53 | end |
|
52 | 54 | |
|
53 | 55 | def edit |
|
54 | 56 | @user = User.find(params[:id]) |
|
55 | 57 | end |
|
56 | 58 | |
|
57 | 59 | def update |
|
58 | 60 | @user = User.find(params[:id]) |
|
59 | 61 | if @user.update_attributes(params[:user]) |
|
60 | 62 | flash[:notice] = 'User was successfully updated.' |
|
61 | 63 | redirect_to :action => 'show', :id => @user |
|
62 | 64 | else |
|
63 | 65 | render :action => 'edit' |
|
64 | 66 | end |
|
65 | 67 | end |
|
66 | 68 | |
|
67 | 69 | def destroy |
|
68 | 70 | User.find(params[:id]).destroy |
|
69 | 71 | redirect_to :action => 'list' |
|
70 | 72 | end |
|
71 | 73 | |
|
72 | 74 | def user_stat |
|
73 | 75 | @problems = Problem.find_available_problems |
|
74 | 76 | @users = User.find(:all) |
|
75 | 77 | @scorearray = Array.new |
|
76 | 78 | @users.each do |u| |
|
77 | 79 | ustat = Array.new |
|
78 | 80 | ustat[0] = u.login |
|
79 | 81 | ustat[1] = u.full_name |
|
80 | 82 | @problems.each do |p| |
|
81 | 83 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
82 | 84 | if (sub!=nil) and (sub.points!=nil) |
|
83 | 85 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
84 | 86 | else |
|
85 | 87 | ustat << [0,false] |
|
86 | 88 | end |
|
87 | 89 | end |
|
88 | 90 | @scorearray << ustat |
|
89 | 91 | end |
|
90 | 92 | end |
|
91 | 93 | |
|
92 | 94 | def import |
|
93 | 95 | if params[:file]=='' |
|
94 | 96 | flash[:notice] = 'Error importing no file' |
@@ -58,58 +58,62 | |||
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def self.show_grading_result |
|
61 | 61 | return (get(SYSTEM_MODE_CONF_KEY)=='analysis') |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def self.allow_test_request(user) |
|
65 | 65 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
66 | 66 | if (mode=='contest') |
|
67 | 67 | return false if (user.site!=nil) and ((user.site.started!=true) or (user.site.time_left < 30.minutes)) |
|
68 | 68 | end |
|
69 | 69 | return false if mode=='analysis' |
|
70 | 70 | return true |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def self.task_grading_info |
|
74 | 74 | if @@task_grading_info==nil |
|
75 | 75 | read_grading_info |
|
76 | 76 | end |
|
77 | 77 | return @@task_grading_info |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | protected |
|
81 | 81 | |
|
82 | 82 | def self.convert_type(val,type) |
|
83 | 83 | case type |
|
84 | 84 | when 'string' |
|
85 | 85 | return val |
|
86 | 86 | |
|
87 | 87 | when 'integer' |
|
88 | 88 | return val.to_i |
|
89 | 89 | |
|
90 | 90 | when 'boolean' |
|
91 | 91 | return (val=='true') |
|
92 | 92 | end |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def self.read_config |
|
96 | 96 | @@configurations = {} |
|
97 | 97 | Configuration.find(:all).each do |conf| |
|
98 | 98 | key = conf.key |
|
99 | 99 | val = conf.value |
|
100 | 100 | @@configurations[key] = Configuration.convert_type(val,conf.value_type) |
|
101 | 101 | end |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | def self.read_one_key(key) |
|
105 | 105 | conf = Configuration.find_by_key(key) |
|
106 | + if conf | |
|
106 | 107 | return Configuration.convert_type(conf.value,conf.value_type) |
|
108 | + else | |
|
109 | + return nil | |
|
110 | + end | |
|
107 | 111 | end |
|
108 | 112 | |
|
109 | 113 | def self.read_grading_info |
|
110 | 114 | f = File.open(TASK_GRADING_INFO_FILENAME) |
|
111 | 115 | @@task_grading_info = YAML.load(f) |
|
112 | 116 | f.close |
|
113 | 117 | end |
|
114 | 118 | |
|
115 | 119 | end |
@@ -1,89 +1,101 | |||
|
1 | 1 | require 'digest/sha1' |
|
2 | 2 | |
|
3 | 3 | class User < ActiveRecord::Base |
|
4 | 4 | |
|
5 | 5 | has_and_belongs_to_many :roles |
|
6 | 6 | |
|
7 | 7 | has_many :test_requests, :order => "submitted_at DESC" |
|
8 | 8 | |
|
9 | 9 | has_many :messages, |
|
10 | 10 | :class_name => "Message", |
|
11 | 11 | :foreign_key => "sender_id", |
|
12 | 12 | :order => 'created_at DESC' |
|
13 | 13 | |
|
14 | 14 | has_many :replied_messages, |
|
15 | 15 | :class_name => "Message", |
|
16 | 16 | :foreign_key => "receiver_id", |
|
17 | 17 | :order => 'created_at DESC' |
|
18 | 18 | |
|
19 | 19 | belongs_to :site |
|
20 | 20 | belongs_to :country |
|
21 | 21 | |
|
22 | 22 | validates_presence_of :login |
|
23 | 23 | validates_presence_of :full_name |
|
24 | 24 | validates_length_of :full_name, :minimum => 1 |
|
25 | 25 | |
|
26 | 26 | validates_presence_of :password, :if => :password_required? |
|
27 | 27 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
28 | 28 | validates_confirmation_of :password, :if => :password_required? |
|
29 | 29 | |
|
30 | 30 | attr_accessor :password |
|
31 | 31 | |
|
32 | 32 | before_save :encrypt_new_password |
|
33 | 33 | |
|
34 | 34 | def self.authenticate(login, password) |
|
35 | 35 | user = find_by_login(login) |
|
36 | 36 | return user if user && user.authenticated?(password) |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def authenticated?(password) |
|
40 | + if self.activated | |
|
40 | 41 | hashed_password == User.encrypt(password,self.salt) |
|
42 | + else | |
|
43 | + false | |
|
44 | + end | |
|
41 | 45 | end |
|
42 | 46 | |
|
43 | 47 | def admin? |
|
44 | 48 | self.roles.detect {|r| r.name == 'admin' } |
|
45 | 49 | end |
|
46 | 50 | |
|
47 | 51 | def email_for_editing |
|
48 | 52 | if self.email==nil |
|
49 | 53 | "(unknown)" |
|
50 | 54 | elsif self.email=='' |
|
51 | 55 | "(blank)" |
|
52 | 56 | else |
|
53 | 57 | self.email |
|
54 | 58 | end |
|
55 | 59 | end |
|
56 | 60 | |
|
57 | 61 | def email_for_editing=(e) |
|
58 | 62 | self.email=e |
|
59 | 63 | end |
|
60 | 64 | |
|
61 | 65 | def alias_for_editing |
|
62 | 66 | if self.alias==nil |
|
63 | 67 | "(unknown)" |
|
64 | 68 | elsif self.alias=='' |
|
65 | 69 | "(blank)" |
|
66 | 70 | else |
|
67 | 71 | self.alias |
|
68 | 72 | end |
|
69 | 73 | end |
|
70 | 74 | |
|
71 | 75 | def alias_for_editing=(e) |
|
72 | 76 | self.alias=e |
|
73 | 77 | end |
|
74 | 78 | |
|
79 | + def activation_key | |
|
80 | + Digest::SHA1.hexdigest(self.hashed_password)[0..7] | |
|
81 | + end | |
|
82 | + | |
|
83 | + def verify_activation_key(key) | |
|
84 | + key == activation_key | |
|
85 | + end | |
|
86 | + | |
|
75 | 87 | protected |
|
76 | 88 | def encrypt_new_password |
|
77 | 89 | return if password.blank? |
|
78 | 90 | self.salt = (10+rand(90)).to_s |
|
79 | 91 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
80 | 92 | end |
|
81 | 93 | |
|
82 | 94 | def password_required? |
|
83 | 95 | self.hashed_password.blank? || !self.password.blank? |
|
84 | 96 | end |
|
85 | 97 | |
|
86 | 98 | def self.encrypt(string,salt) |
|
87 | 99 | Digest::SHA1.hexdigest(salt + string) |
|
88 | 100 | end |
|
89 | 101 | end |
@@ -1,62 +1,69 | |||
|
1 | 1 | %h1= Configuration['ui.front.title'] |
|
2 | 2 | |
|
3 | 3 | - if @announcements.length!=0 |
|
4 | 4 | .announcementbox |
|
5 | 5 | %span{:class => 'title'} |
|
6 | 6 | Announcements |
|
7 | 7 | = render :partial => 'announcement', :collection => @announcements |
|
8 | 8 | |
|
9 | 9 | %b= Configuration['ui.front.welcome_message'] |
|
10 | 10 | %br/ |
|
11 | 11 | Please login to see the problem list. |
|
12 | 12 | %br/ |
|
13 | 13 | %br/ |
|
14 | 14 | |
|
15 | 15 | - if flash[:notice] |
|
16 | 16 | %hr/ |
|
17 | 17 | %b= flash[:notice] |
|
18 | 18 | %hr/ |
|
19 | 19 | |
|
20 | 20 | %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} |
|
21 | 21 | - form_tag :controller => 'login', :action => 'login' do |
|
22 | 22 | %table |
|
23 | 23 | %tr |
|
24 | 24 | %td{:align => "right"} Login: |
|
25 | 25 | %td= text_field_tag 'login' |
|
26 | 26 | %tr |
|
27 | 27 | %td{:align => "right"} Password: |
|
28 | 28 | %td= password_field_tag |
|
29 | 29 | = submit_tag 'Login' |
|
30 | 30 | |
|
31 | 31 | %br/ |
|
32 | 32 | |
|
33 |
- - if Configuration['system. |
|
|
33 | + -# if Configuration['system.online_registration'] | |
|
34 | + Want to participate? | |
|
35 | + %b | |
|
36 | + Please | |
|
37 | + = link_to 'register.', :controller => :users, :action => :new | |
|
38 | + %br/ | |
|
39 | + | |
|
40 | + - if (Configuration['system.mode']=='contest') and (Configuration['contest.multisites']) | |
|
34 | 41 | %script{:type => 'text/javascript'} |
|
35 | 42 | var siteList = new Array(); |
|
36 | 43 | - @countries.each do |country| |
|
37 | 44 | = "siteList[#{country.id}] = new Array();" |
|
38 | 45 | - country.sites.each do |site| |
|
39 | 46 | = "siteList[#{country.id}][#{site.id}] = \"#{site.name}\";" |
|
40 | 47 | |
|
41 | 48 | var allSiteList = new Array(); |
|
42 | 49 | - @site_select.each do |sel| |
|
43 | 50 | = "allSiteList[#{sel[1]}]=\"#{sel[0]}\";" |
|
44 | 51 | |
|
45 | 52 | %script{:type => 'text/javascript', :src => '/javascripts/site_update.js'} |
|
46 | 53 | |
|
47 | 54 | %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} |
|
48 | 55 | %b For Site Administrator. |
|
49 | 56 | %br/ |
|
50 | 57 | Please select your country and site and login. |
|
51 | 58 | - form_for :login, nil, :url => {:controller => 'login', :action => 'site_login'} do |f| |
|
52 | 59 | Country: |
|
53 | 60 | = select :site_country, :id, @country_select_with_all, {}, {:onchange => "updateSiteList();", :onclick => "updateSiteList();" } |
|
54 | 61 | Site: |
|
55 | 62 | = select :login, :site_id, @site_select |
|
56 | 63 | %br/ |
|
57 | 64 | Password: |
|
58 | 65 | = f.password_field :password |
|
59 | 66 | = submit_tag "Site Administrator Login" |
|
60 | 67 | |
|
61 | 68 | %script{:type => 'text/javascript'} |
|
62 | 69 | updateSiteList(); |
@@ -37,73 +37,73 | |||
|
37 | 37 | def run |
|
38 | 38 | load_initializer |
|
39 | 39 | Rails::Initializer.run(:set_load_path) |
|
40 | 40 | end |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | class VendorBoot < Boot |
|
44 | 44 | def load_initializer |
|
45 | 45 | require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" |
|
46 | 46 | Rails::Initializer.run(:install_gem_spec_stubs) |
|
47 | 47 | end |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | class GemBoot < Boot |
|
51 | 51 | def load_initializer |
|
52 | 52 | self.class.load_rubygems |
|
53 | 53 | load_rails_gem |
|
54 | 54 | require 'initializer' |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def load_rails_gem |
|
58 | 58 | if version = self.class.gem_version |
|
59 | 59 | gem 'rails', version |
|
60 | 60 | else |
|
61 | 61 | gem 'rails' |
|
62 | 62 | end |
|
63 | 63 | rescue Gem::LoadError => load_error |
|
64 | 64 | $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) |
|
65 | 65 | exit 1 |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | class << self |
|
69 | 69 | def rubygems_version |
|
70 | 70 | Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def gem_version |
|
74 | 74 | if defined? RAILS_GEM_VERSION |
|
75 | 75 | RAILS_GEM_VERSION |
|
76 | 76 | elsif ENV.include?('RAILS_GEM_VERSION') |
|
77 | 77 | ENV['RAILS_GEM_VERSION'] |
|
78 | 78 | else |
|
79 | 79 | parse_gem_version(read_environment_rb) |
|
80 | 80 | end |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def load_rubygems |
|
84 | 84 | require 'rubygems' |
|
85 | - | |
|
86 |
- unless rubygems_version >= |
|
|
87 |
- $stderr.puts %(Rails requires RubyGems >= |
|
|
85 | + min_version = '1.1.1' | |
|
86 | + unless rubygems_version >= min_version | |
|
87 | + $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) | |
|
88 | 88 | exit 1 |
|
89 | 89 | end |
|
90 | 90 | |
|
91 | 91 | rescue LoadError |
|
92 |
- $stderr.puts %(Rails requires RubyGems >= |
|
|
92 | + $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) | |
|
93 | 93 | exit 1 |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def parse_gem_version(text) |
|
97 | 97 | $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | private |
|
101 | 101 | def read_environment_rb |
|
102 | 102 | File.read("#{RAILS_ROOT}/config/environment.rb") |
|
103 | 103 | end |
|
104 | 104 | end |
|
105 | 105 | end |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | # All that for this: |
|
109 | 109 | Rails.boot! |
@@ -1,67 +1,74 | |||
|
1 | 1 | # Be sure to restart your web server when you modify this file. |
|
2 | 2 | |
|
3 | 3 | # Uncomment below to force Rails into production mode when |
|
4 | 4 | # you don't control web/app server and can't set it the proper way |
|
5 | 5 | # ENV['RAILS_ENV'] ||= 'production' |
|
6 | 6 | |
|
7 | 7 | # Specifies gem version of Rails to use when vendor/rails is not present |
|
8 | 8 | RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION |
|
9 | 9 | |
|
10 | 10 | # Bootstrap the Rails environment, frameworks, and default configuration |
|
11 | 11 | require File.join(File.dirname(__FILE__), 'boot') |
|
12 | 12 | |
|
13 | 13 | Rails::Initializer.run do |config| |
|
14 | 14 | # Settings in config/environments/* take precedence over those specified here |
|
15 | 15 | |
|
16 | 16 | # Skip frameworks you're not going to use (only works if using vendor/rails) |
|
17 | 17 | # config.frameworks -= [ :action_web_service, :action_mailer ] |
|
18 | 18 | |
|
19 | 19 | # Only load the plugins named here, by default all plugins in vendor/plugins are loaded |
|
20 | 20 | # config.plugins = %W( exception_notification ssl_requirement ) |
|
21 | 21 | |
|
22 | 22 | # Add additional load paths for your own custom dirs |
|
23 | 23 | # config.load_paths += %W( #{RAILS_ROOT}/extras ) |
|
24 | 24 | |
|
25 | 25 | # Force all environments to use the same logger level |
|
26 | 26 | # (by default production uses :info, the others :debug) |
|
27 | 27 | # config.log_level = :debug |
|
28 | 28 | |
|
29 | 29 | # Use the database for sessions instead of the file system |
|
30 | 30 | # (create the session table with 'rake db:sessions:create') |
|
31 | 31 | config.action_controller.session_store = :active_record_store |
|
32 | 32 | |
|
33 | 33 | # Use SQL instead of Active Record's schema dumper when creating the test database. |
|
34 | 34 | # This is necessary if your schema can't be completely dumped by the schema dumper, |
|
35 | 35 | # like if you have constraints or database-specific column types |
|
36 | 36 | # config.active_record.schema_format = :sql |
|
37 | 37 | |
|
38 | 38 | # Activate observers that should always be running |
|
39 | 39 | # config.active_record.observers = :cacher, :garbage_collector |
|
40 | 40 | |
|
41 | 41 | # Make Active Record use UTC-base instead of local time |
|
42 | 42 | config.active_record.default_timezone = :utc |
|
43 | 43 | |
|
44 | 44 | # See Rails::Configuration for more options |
|
45 | 45 | |
|
46 | + # ------------- | |
|
47 | + # Required gems | |
|
48 | + # ------------- | |
|
49 | + | |
|
46 | 50 | # This is for rspec |
|
47 | 51 | config.gem "rspec-rails", :lib => "spec" |
|
52 | + config.gem "haml" | |
|
53 | + config.gem "pony" | |
|
54 | + #config.gem "BlueCloth", :lig => "bluecloth" | |
|
48 | 55 | end |
|
49 | 56 | |
|
50 | 57 | # Add new inflection rules using the following format |
|
51 | 58 | # (all these examples are active by default): |
|
52 | 59 | # Inflector.inflections do |inflect| |
|
53 | 60 | # inflect.plural /^(ox)$/i, '\1en' |
|
54 | 61 | # inflect.singular /^(ox)en/i, '\1' |
|
55 | 62 | # inflect.irregular 'person', 'people' |
|
56 | 63 | # inflect.uncountable %w( fish sheep ) |
|
57 | 64 | # end |
|
58 | 65 | |
|
59 | 66 | # Add new mime types for use in respond_to blocks: |
|
60 | 67 | # Mime::Type.register "text/richtext", :rtf |
|
61 | 68 | # Mime::Type.register "application/x-mobile", :mobile |
|
62 | 69 | |
|
63 | 70 | # Include your application configuration below |
|
64 | 71 | |
|
65 | 72 | # These are where inputs and outputs of test requests are stored |
|
66 | 73 | TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input' |
|
67 | 74 | TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output' |
@@ -1,60 +1,60 | |||
|
1 | 1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
2 | 2 | # please use the migrations feature of Active Record to incrementally modify your database, and |
|
3 | 3 | # then regenerate this schema definition. |
|
4 | 4 | # |
|
5 | 5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
6 | 6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | 7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | 8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
9 | 9 | # |
|
10 | 10 | # It's strongly recommended to check this file into your version control system. |
|
11 | 11 | |
|
12 |
- ActiveRecord::Schema.define(:version => 20081 |
|
|
12 | + ActiveRecord::Schema.define(:version => 20081204122651) do | |
|
13 | 13 | |
|
14 | 14 | create_table "announcements", :force => true do |t| |
|
15 | 15 | t.string "author" |
|
16 | 16 | t.text "body" |
|
17 | 17 | t.boolean "published" |
|
18 | 18 | t.datetime "created_at" |
|
19 | 19 | t.datetime "updated_at" |
|
20 | 20 | t.boolean "frontpage", :default => false |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | 23 | create_table "configurations", :force => true do |t| |
|
24 | 24 | t.string "key" |
|
25 | 25 | t.string "value_type" |
|
26 | 26 | t.string "value" |
|
27 | 27 | t.datetime "created_at" |
|
28 | 28 | t.datetime "updated_at" |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | create_table "countries", :force => true do |t| |
|
32 | 32 | t.string "name" |
|
33 | 33 | t.datetime "created_at" |
|
34 | 34 | t.datetime "updated_at" |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | create_table "descriptions", :force => true do |t| |
|
38 | 38 | t.text "body" |
|
39 | 39 | t.boolean "markdowned" |
|
40 | 40 | t.datetime "created_at" |
|
41 | 41 | t.datetime "updated_at" |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | create_table "grader_processes", :force => true do |t| |
|
45 | 45 | t.string "host", :limit => 20 |
|
46 | 46 | t.integer "pid" |
|
47 | 47 | t.string "mode" |
|
48 | 48 | t.boolean "active" |
|
49 | 49 | t.datetime "created_at" |
|
50 | 50 | t.datetime "updated_at" |
|
51 | 51 | t.integer "task_id" |
|
52 | 52 | t.string "task_type" |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
56 | 56 | |
|
57 | 57 | create_table "languages", :force => true do |t| |
|
58 | 58 | t.string "name", :limit => 10 |
|
59 | 59 | t.string "pretty_name" |
|
60 | 60 | t.string "ext", :limit => 10 |
@@ -137,53 +137,54 | |||
|
137 | 137 | t.datetime "graded_at" |
|
138 | 138 | t.integer "points" |
|
139 | 139 | t.text "grader_comment" |
|
140 | 140 | t.integer "number" |
|
141 | 141 | t.string "source_filename" |
|
142 | 142 | end |
|
143 | 143 | |
|
144 | 144 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
145 | 145 | add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" |
|
146 | 146 | |
|
147 | 147 | create_table "tasks", :force => true do |t| |
|
148 | 148 | t.integer "submission_id" |
|
149 | 149 | t.datetime "created_at" |
|
150 | 150 | t.integer "status" |
|
151 | 151 | t.datetime "updated_at" |
|
152 | 152 | end |
|
153 | 153 | |
|
154 | 154 | create_table "test_requests", :force => true do |t| |
|
155 | 155 | t.integer "user_id" |
|
156 | 156 | t.integer "problem_id" |
|
157 | 157 | t.integer "submission_id" |
|
158 | 158 | t.string "input_file_name" |
|
159 | 159 | t.string "output_file_name" |
|
160 | 160 | t.string "running_stat" |
|
161 | 161 | t.integer "status" |
|
162 | 162 | t.datetime "updated_at" |
|
163 | 163 | t.datetime "submitted_at" |
|
164 | 164 | t.datetime "compiled_at" |
|
165 | 165 | t.text "compiler_message" |
|
166 | 166 | t.datetime "graded_at" |
|
167 | 167 | t.string "grader_comment" |
|
168 | 168 | t.datetime "created_at" |
|
169 | 169 | t.float "running_time" |
|
170 | 170 | t.string "exit_status" |
|
171 | 171 | t.integer "memory_usage" |
|
172 | 172 | end |
|
173 | 173 | |
|
174 | 174 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
175 | 175 | |
|
176 | 176 | create_table "users", :force => true do |t| |
|
177 | 177 | t.string "login", :limit => 10 |
|
178 | 178 | t.string "full_name" |
|
179 | 179 | t.string "hashed_password" |
|
180 | 180 | t.string "salt", :limit => 5 |
|
181 | 181 | t.string "alias" |
|
182 | 182 | t.string "email" |
|
183 | 183 | t.integer "site_id" |
|
184 | 184 | t.integer "country_id" |
|
185 | + t.boolean "activated", :default => false | |
|
185 | 186 | end |
|
186 | 187 | |
|
187 | 188 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
188 | 189 | |
|
189 | 190 | end |
@@ -1,53 +1,58 | |||
|
1 | 1 | |
|
2 | 2 | require File.dirname(__FILE__) + '/../spec_helper' |
|
3 | 3 | |
|
4 | 4 | describe Configuration do |
|
5 | 5 | |
|
6 | + # only work with cached configuration | |
|
7 | + class Configuration | |
|
8 | + @@cache = true | |
|
9 | + end | |
|
10 | + | |
|
6 | 11 | before(:each) do |
|
7 | 12 | @int_config = mock(Configuration, |
|
8 | 13 | :id => 1, |
|
9 | 14 | :key => 'mode', |
|
10 | 15 | :value_type => 'integer', |
|
11 | 16 | :value => '30') |
|
12 | 17 | |
|
13 | 18 | @string_config = mock(Configuration, |
|
14 | 19 | :id => 2, |
|
15 | 20 | :key => 'title', |
|
16 | 21 | :value_type => 'string', |
|
17 | 22 | :value => 'Hello') |
|
18 | 23 | |
|
19 | 24 | @boolean_config = mock(Configuration, |
|
20 | 25 | :id => 3, |
|
21 | 26 | :key => 'single_user_mode', |
|
22 | 27 | :value_type => 'boolean', |
|
23 | 28 | :value => 'true') |
|
24 | 29 | end |
|
25 | 30 | |
|
26 | 31 | it "should retrieve int config" do |
|
27 | 32 | Configuration.should_receive(:find).once.with(:all). |
|
28 | 33 | and_return([@int_config, @string_config, @boolean_config]) |
|
29 | 34 | |
|
30 | 35 | Configuration.clear |
|
31 | 36 | val = Configuration.get('mode') |
|
32 | 37 | val.should == 30 |
|
33 | 38 | end |
|
34 | 39 | |
|
35 | 40 | it "should retrieve boolean config" do |
|
36 | 41 | Configuration.should_receive(:find).once.with(:all). |
|
37 | 42 | and_return([@int_config, @string_config, @boolean_config]) |
|
38 | 43 | |
|
39 | 44 | Configuration.clear |
|
40 | 45 | val = Configuration.get('single_user_mode') |
|
41 | 46 | val.should == true |
|
42 | 47 | end |
|
43 | 48 | |
|
44 | 49 | it "should retrieve string config" do |
|
45 | 50 | Configuration.should_receive(:find).once.with(:all). |
|
46 | 51 | and_return([@int_config, @string_config, @boolean_config]) |
|
47 | 52 | |
|
48 | 53 | Configuration.clear |
|
49 | 54 | val = Configuration.get('title') |
|
50 | 55 | val.should == "Hello" |
|
51 | 56 | end |
|
52 | 57 | |
|
53 | 58 | it "should retrieve config with []" do |
You need to be logged in to leave comments.
Login now