Description:
increases max password length to 50
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r776:20ee1ec7fa92 - - 1 file changed: 1 inserted, 1 deleted
@@ -1,139 +1,139 | |||||
|
1 | require 'digest/sha1' |
|
1 | require 'digest/sha1' |
|
2 | require 'net/pop' |
|
2 | require 'net/pop' |
|
3 | require 'net/https' |
|
3 | require 'net/https' |
|
4 | require 'net/http' |
|
4 | require 'net/http' |
|
5 | require 'json' |
|
5 | require 'json' |
|
6 |
|
6 | ||
|
7 | class User < ActiveRecord::Base |
|
7 | class User < ActiveRecord::Base |
|
8 |
|
8 | ||
|
9 | has_and_belongs_to_many :roles |
|
9 | has_and_belongs_to_many :roles |
|
10 |
|
10 | ||
|
11 | #has_and_belongs_to_many :groups |
|
11 | #has_and_belongs_to_many :groups |
|
12 | has_many :groups_users, class_name: GroupUser |
|
12 | has_many :groups_users, class_name: GroupUser |
|
13 | has_many :groups, :through => :groups_users |
|
13 | has_many :groups, :through => :groups_users |
|
14 |
|
14 | ||
|
15 | has_many :test_requests, -> {order(submitted_at: DESC)} |
|
15 | has_many :test_requests, -> {order(submitted_at: DESC)} |
|
16 |
|
16 | ||
|
17 | has_many :messages, -> { order(created_at: DESC) }, |
|
17 | has_many :messages, -> { order(created_at: DESC) }, |
|
18 | :class_name => "Message", |
|
18 | :class_name => "Message", |
|
19 | :foreign_key => "sender_id" |
|
19 | :foreign_key => "sender_id" |
|
20 |
|
20 | ||
|
21 | has_many :replied_messages, -> { order(created_at: DESC) }, |
|
21 | has_many :replied_messages, -> { order(created_at: DESC) }, |
|
22 | :class_name => "Message", |
|
22 | :class_name => "Message", |
|
23 | :foreign_key => "receiver_id" |
|
23 | :foreign_key => "receiver_id" |
|
24 |
|
24 | ||
|
25 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
25 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
26 |
|
26 | ||
|
27 | belongs_to :site |
|
27 | belongs_to :site |
|
28 | belongs_to :country |
|
28 | belongs_to :country |
|
29 |
|
29 | ||
|
30 | has_and_belongs_to_many :contests, -> { order(:name); uniq} |
|
30 | has_and_belongs_to_many :contests, -> { order(:name); uniq} |
|
31 |
|
31 | ||
|
32 | scope :activated_users, -> {where activated: true} |
|
32 | scope :activated_users, -> {where activated: true} |
|
33 |
|
33 | ||
|
34 | validates_presence_of :login |
|
34 | validates_presence_of :login |
|
35 | validates_uniqueness_of :login |
|
35 | validates_uniqueness_of :login |
|
36 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
36 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
37 | validates_length_of :login, :within => 3..30 |
|
37 | validates_length_of :login, :within => 3..30 |
|
38 |
|
38 | ||
|
39 | validates_presence_of :full_name |
|
39 | validates_presence_of :full_name |
|
40 | validates_length_of :full_name, :minimum => 1 |
|
40 | validates_length_of :full_name, :minimum => 1 |
|
41 |
|
41 | ||
|
42 | validates_presence_of :password, :if => :password_required? |
|
42 | validates_presence_of :password, :if => :password_required? |
|
43 |
- validates_length_of :password, :within => 4.. |
|
43 | + validates_length_of :password, :within => 4..50, :if => :password_required? |
|
44 | validates_confirmation_of :password, :if => :password_required? |
|
44 | validates_confirmation_of :password, :if => :password_required? |
|
45 |
|
45 | ||
|
46 | validates_format_of :email, |
|
46 | validates_format_of :email, |
|
47 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
47 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
48 | :if => :email_validation? |
|
48 | :if => :email_validation? |
|
49 | validate :uniqueness_of_email_from_activated_users, |
|
49 | validate :uniqueness_of_email_from_activated_users, |
|
50 | :if => :email_validation? |
|
50 | :if => :email_validation? |
|
51 | validate :enough_time_interval_between_same_email_registrations, |
|
51 | validate :enough_time_interval_between_same_email_registrations, |
|
52 | :if => :email_validation? |
|
52 | :if => :email_validation? |
|
53 |
|
53 | ||
|
54 | # these are for ytopc |
|
54 | # these are for ytopc |
|
55 | # disable for now |
|
55 | # disable for now |
|
56 | #validates_presence_of :province |
|
56 | #validates_presence_of :province |
|
57 |
|
57 | ||
|
58 | attr_accessor :password |
|
58 | attr_accessor :password |
|
59 |
|
59 | ||
|
60 | before_save :encrypt_new_password |
|
60 | before_save :encrypt_new_password |
|
61 | before_save :assign_default_site |
|
61 | before_save :assign_default_site |
|
62 | before_save :assign_default_contest |
|
62 | before_save :assign_default_contest |
|
63 |
|
63 | ||
|
64 | # this is for will_paginate |
|
64 | # this is for will_paginate |
|
65 | cattr_reader :per_page |
|
65 | cattr_reader :per_page |
|
66 | @@per_page = 50 |
|
66 | @@per_page = 50 |
|
67 |
|
67 | ||
|
68 | def self.authenticate(login, password) |
|
68 | def self.authenticate(login, password) |
|
69 | user = find_by_login(login) |
|
69 | user = find_by_login(login) |
|
70 | if user |
|
70 | if user |
|
71 | return user if user.authenticated?(password) |
|
71 | return user if user.authenticated?(password) |
|
72 | end |
|
72 | end |
|
73 | end |
|
73 | end |
|
74 |
|
74 | ||
|
75 | def authenticated?(password) |
|
75 | def authenticated?(password) |
|
76 | if self.activated |
|
76 | if self.activated |
|
77 | hashed_password == User.encrypt(password,self.salt) |
|
77 | hashed_password == User.encrypt(password,self.salt) |
|
78 | else |
|
78 | else |
|
79 | false |
|
79 | false |
|
80 | end |
|
80 | end |
|
81 | end |
|
81 | end |
|
82 |
|
82 | ||
|
83 | def admin? |
|
83 | def admin? |
|
84 | self.roles.detect {|r| r.name == 'admin' } |
|
84 | self.roles.detect {|r| r.name == 'admin' } |
|
85 | end |
|
85 | end |
|
86 |
|
86 | ||
|
87 | def email_for_editing |
|
87 | def email_for_editing |
|
88 | if self.email==nil |
|
88 | if self.email==nil |
|
89 | "(unknown)" |
|
89 | "(unknown)" |
|
90 | elsif self.email=='' |
|
90 | elsif self.email=='' |
|
91 | "(blank)" |
|
91 | "(blank)" |
|
92 | else |
|
92 | else |
|
93 | self.email |
|
93 | self.email |
|
94 | end |
|
94 | end |
|
95 | end |
|
95 | end |
|
96 |
|
96 | ||
|
97 | def email_for_editing=(e) |
|
97 | def email_for_editing=(e) |
|
98 | self.email=e |
|
98 | self.email=e |
|
99 | end |
|
99 | end |
|
100 |
|
100 | ||
|
101 | def alias_for_editing |
|
101 | def alias_for_editing |
|
102 | if self.alias==nil |
|
102 | if self.alias==nil |
|
103 | "(unknown)" |
|
103 | "(unknown)" |
|
104 | elsif self.alias=='' |
|
104 | elsif self.alias=='' |
|
105 | "(blank)" |
|
105 | "(blank)" |
|
106 | else |
|
106 | else |
|
107 | self.alias |
|
107 | self.alias |
|
108 | end |
|
108 | end |
|
109 | end |
|
109 | end |
|
110 |
|
110 | ||
|
111 | def alias_for_editing=(e) |
|
111 | def alias_for_editing=(e) |
|
112 | self.alias=e |
|
112 | self.alias=e |
|
113 | end |
|
113 | end |
|
114 |
|
114 | ||
|
115 | def activation_key |
|
115 | def activation_key |
|
116 | if self.hashed_password==nil |
|
116 | if self.hashed_password==nil |
|
117 | encrypt_new_password |
|
117 | encrypt_new_password |
|
118 | end |
|
118 | end |
|
119 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
119 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
120 | end |
|
120 | end |
|
121 |
|
121 | ||
|
122 | def verify_activation_key(key) |
|
122 | def verify_activation_key(key) |
|
123 | key == activation_key |
|
123 | key == activation_key |
|
124 | end |
|
124 | end |
|
125 |
|
125 | ||
|
126 | def self.random_password(length=5) |
|
126 | def self.random_password(length=5) |
|
127 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
127 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
128 | password = '' |
|
128 | password = '' |
|
129 | length.times { password << chars[rand(chars.length - 1)] } |
|
129 | length.times { password << chars[rand(chars.length - 1)] } |
|
130 | password |
|
130 | password |
|
131 | end |
|
131 | end |
|
132 |
|
132 | ||
|
133 | def self.find_non_admin_with_prefix(prefix='') |
|
133 | def self.find_non_admin_with_prefix(prefix='') |
|
134 | users = User.all |
|
134 | users = User.all |
|
135 | return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } |
|
135 | return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } |
|
136 | end |
|
136 | end |
|
137 |
|
137 | ||
|
138 | # Contest information |
|
138 | # Contest information |
|
139 |
|
139 |
You need to be logged in to leave comments.
Login now