Show More
Commit Description:
changed styling on status view
Commit Description:
changed styling on status view
File last commit:
Show/Diff file:
Action:
app/models/user.rb | 298 lines | 7.8 KiB | text/x-ruby | RubyLexer |
pramook
initial commit...
r0 require 'digest/sha1'
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
jittat
[web] improving readability of test_interface, re: ticket #10...
r64 has_many :test_requests, :order => "submitted_at DESC"
jittat
test interface upload...
r36
jittat
[web] added message feature...
r102 has_many :messages,
:class_name => "Message",
:foreign_key => "sender_id",
:order => 'created_at DESC'
has_many :replied_messages,
:class_name => "Message",
:foreign_key => "receiver_id",
:order => 'created_at DESC'
Jittat Fakcharoenphol
added test pair assignment, requests new input, downloads input
r213 has_many :test_pair_assignments, :dependent => :delete_all
Jittat Fakcharoenphol
added submission_status to store grading results, first page shows only unpassed problems.
r216 has_many :submission_statuses
Jittat Fakcharoenphol
added test pair assignment, requests new input, downloads input
r213
Jittat Fakcharoenphol
added individual contest mode
r217 has_one :contest_stat, :class_name => "UserContestStat"
jittat
[web] added site and time out basic functionality...
r85 belongs_to :site
jittat
[web] import from site...
r106 belongs_to :country
jittat
[web] added site and time out basic functionality...
r85
Jittat Fakcharoenphol
added codejom_status model for computing level with basic user update
r219 # For Code Jom
has_one :codejom_status
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 named_scope :activated_users, :conditions => {:activated => true}
jittat
more work on registration...
r157
pramook
initial commit...
r0 validates_presence_of :login
jittat
more work on registration...
r157 validates_uniqueness_of :login
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/
validates_length_of :login, :within => 3..30
jittat
more work on registration...
r157
pramook
initial commit...
r0 validates_presence_of :full_name
jittat
disable fullname editing...
r23 validates_length_of :full_name, :minimum => 1
pramook
initial commit...
r0
validates_presence_of :password, :if => :password_required?
validates_length_of :password, :within => 4..20, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 validates_format_of :email,
:with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
:if => :email_validation?
validate :uniqueness_of_email_from_activated_users,
:if => :email_validation?
validate :enough_time_interval_between_same_email_registrations,
:if => :email_validation?
jittat
more work on registration...
r157
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 # these are for ytopc
# disable for now
#validates_presence_of :province
jittat
more work on registration...
r157
pramook
initial commit...
r0 attr_accessor :password
before_save :encrypt_new_password
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 before_save :assign_default_site
pramook
initial commit...
r0
def self.authenticate(login, password)
user = find_by_login(login)
return user if user && user.authenticated?(password)
end
def authenticated?(password)
jittat
start working on e-mail registration...
r155 if self.activated
hashed_password == User.encrypt(password,self.salt)
else
false
end
pramook
initial commit...
r0 end
def admin?
self.roles.detect {|r| r.name == 'admin' }
end
Jittat Fakcharoenphol
added test pair assignment, requests new input, downloads input
r213 # These are methods related to test pairs
def get_test_pair_assignments_for(problem)
test_pair_assignments.find_all { |a| a.problem_id == problem.id }
end
def get_recent_test_pair_assignment_for(problem)
assignments = get_test_pair_assignments_for problem
if assignments.length == 0
return nil
else
recent = assignments[0]
assignments.each do |a|
recent = a if a.request_number > recent.request_number
end
return recent
end
end
def can_request_new_test_pair_for?(problem)
recent = get_recent_test_pair_assignment_for problem
return (recent == nil or recent.submitted)
end
def get_new_test_pair_assignment_for(problem)
previous_assignment_numbers =
get_test_pair_assignments_for(problem).collect {|a| a.test_pair_number }
test_pair = problem.random_test_pair(previous_assignment_numbers)
if test_pair
assignment = TestPairAssignment.new(:user => self,
:problem => problem,
:test_pair => test_pair,
:test_pair_number => test_pair.number,
:request_number =>
previous_assignment_numbers.length + 1,
:submitted => false)
return assignment
else
return nil
end
end
Jittat Fakcharoenphol
added submission_status to store grading results, first page shows only unpassed problems.
r216 def get_submission_status_for(problem)
SubmissionStatus.find(:first,
:conditions => {
:user_id => id,
:problem_id => problem.id
})
end
jittat
add_email_to_user, fix empty problem for_in_place_editing...
r18 def email_for_editing
jittat
disable fullname editing...
r23 if self.email==nil
"(unknown)"
elsif self.email==''
"(blank)"
else
jittat
add_email_to_user, fix empty problem for_in_place_editing...
r18 self.email
end
end
def email_for_editing=(e)
self.email=e
end
def alias_for_editing
jittat
disable fullname editing...
r23 if self.alias==nil
"(unknown)"
elsif self.alias==''
"(blank)"
else
jittat
add_email_to_user, fix empty problem for_in_place_editing...
r18 self.alias
end
end
def alias_for_editing=(e)
self.alias=e
end
jittat
start working on e-mail registration...
r155 def activation_key
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 if self.hashed_password==nil
encrypt_new_password
end
jittat
start working on e-mail registration...
r155 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
end
def verify_activation_key(key)
key == activation_key
end
jittat
more work on registration...
r157 def self.random_password(length=5)
chars = 'abcdefghjkmnopqrstuvwxyz'
password = ''
length.times { password << chars[rand(chars.length - 1)] }
password
end
jittat
added random user passwords, better user creation by list....
r200 def self.find_non_admin_with_prefix(prefix='')
users = User.find(:all)
return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
end
Jittat Fakcharoenphol
added individual contest mode
r217 # Contest information
def contest_time_left
if Configuration.contest_mode?
return nil if site==nil
return site.time_left
elsif Configuration.indv_contest_mode?
time_limit = Configuration.contest_time_limit
if contest_stat==nil
return (Time.now.gmtime + time_limit) - Time.now.gmtime
else
finish_time = contest_stat.started_at + time_limit
current_time = Time.now.gmtime
if current_time > finish_time
return 0
else
return finish_time - current_time
end
end
else
return nil
end
end
def contest_finished?
if Configuration.contest_mode?
return false if site==nil
return site.finished?
elsif Configuration.indv_contest_mode?
time_limit = Configuration.contest_time_limit
return false if contest_stat==nil
return contest_time_left == 0
else
return false
end
end
def contest_started?
if Configuration.contest_mode?
return true if site==nil
return site.started
else
return true
end
end
Jittat Fakcharoenphol
added codejom_status model for computing level with basic user update
r219 # For Code Jom
def update_codejom_status
status = codejom_status || CodejomStatus.new(:user => self)
problem_count = Problem.available_problem_count
status.num_problems_passed = (self.submission_statuses.find_all {|s| s.passed}).length
status.alive = (problem_count - (status.num_problems_passed)) <= CODEJOM_MAX_ALIVE_LEVEL
status.save
end
def codejom_level
problem_count = Problem.available_problem_count
if codejom_status!=nil
return problem_count - codejom_status.num_problems_passed
else
return problem_count
end
end
jittat
add_email_to_user, fix empty problem for_in_place_editing...
r18 protected
pramook
initial commit...
r0 def encrypt_new_password
return if password.blank?
self.salt = (10+rand(90)).to_s
jittat
[web] added graders_right_to_admin_role, added a few functional tests: main, user_admin, graders, login...
r58 self.hashed_password = User.encrypt(self.password,self.salt)
pramook
initial commit...
r0 end
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 def assign_default_site
# have to catch error when migrating (because self.site is not available).
begin
if self.site==nil
self.site = Site.find_by_name('default')
jittat
MERGED change set 372:399 from ytopc08-2 branch...
r190 if self.site==nil
self.site = Site.find(1) # when 'default has be renamed'
end
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 end
rescue
end
end
pramook
initial commit...
r0 def password_required?
jittat
[web] added graders_right_to_admin_role, added a few functional tests: main, user_admin, graders, login...
r58 self.hashed_password.blank? || !self.password.blank?
pramook
initial commit...
r0 end
jittat
[web] added graders_right_to_admin_role, added a few functional tests: main, user_admin, graders, login...
r58 def self.encrypt(string,salt)
pramook
initial commit...
r0 Digest::SHA1.hexdigest(salt + string)
end
jittat
more work on registration...
r157
def uniqueness_of_email_from_activated_users
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 user = User.activated_users.find_by_email(self.email)
if user and (user.login != self.login)
jittat
more work on registration...
r157 self.errors.add_to_base("Email has already been taken")
end
end
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158
def enough_time_interval_between_same_email_registrations
jittat
fixed user confirmation bug...
r160 return if !self.new_record?
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 return if self.activated
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 open_user = User.find_by_email(self.email,
:order => 'created_at DESC')
if open_user and open_user.created_at and
(open_user.created_at > Time.now.gmtime - 5.minutes)
self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
end
end
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162
def email_validation?
begin
return VALIDATE_USER_EMAILS
rescue
return false
end
end
pramook
initial commit...
r0 end