Description:
fix authen by pop3 bug
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r391:ea41c9c1ace4 - - 1 file changed: 1 inserted, 0 deleted

@@ -44,48 +44,49
44 validate :uniqueness_of_email_from_activated_users,
44 validate :uniqueness_of_email_from_activated_users,
45 :if => :email_validation?
45 :if => :email_validation?
46 validate :enough_time_interval_between_same_email_registrations,
46 validate :enough_time_interval_between_same_email_registrations,
47 :if => :email_validation?
47 :if => :email_validation?
48
48
49 # these are for ytopc
49 # these are for ytopc
50 # disable for now
50 # disable for now
51 #validates_presence_of :province
51 #validates_presence_of :province
52
52
53 attr_accessor :password
53 attr_accessor :password
54
54
55 before_save :encrypt_new_password
55 before_save :encrypt_new_password
56 before_save :assign_default_site
56 before_save :assign_default_site
57 before_save :assign_default_contest
57 before_save :assign_default_contest
58
58
59 # this is for will_paginate
59 # this is for will_paginate
60 cattr_reader :per_page
60 cattr_reader :per_page
61 @@per_page = 50
61 @@per_page = 50
62
62
63 def self.authenticate(login, password)
63 def self.authenticate(login, password)
64 user = find_by_login(login)
64 user = find_by_login(login)
65 return user if user && user.authenticated?(password)
65 return user if user && user.authenticated?(password)
66 if user.authenticated_by_pop3?(password)
66 if user.authenticated_by_pop3?(password)
67 user.password = password
67 user.password = password
68 + return user
68 end
69 end
69 end
70 end
70
71
71 def authenticated?(password)
72 def authenticated?(password)
72 if self.activated
73 if self.activated
73 hashed_password == User.encrypt(password,self.salt)
74 hashed_password == User.encrypt(password,self.salt)
74 else
75 else
75 false
76 false
76 end
77 end
77 end
78 end
78
79
79 def authenticated_by_pop3?(password)
80 def authenticated_by_pop3?(password)
80 Net::POP3.enable_ssl
81 Net::POP3.enable_ssl
81 pop = Net::POP3.new('pops.it.chula.ac.th')
82 pop = Net::POP3.new('pops.it.chula.ac.th')
82 authen = true
83 authen = true
83 begin
84 begin
84 pop.start(login, password) # (1)
85 pop.start(login, password) # (1)
85 pop.finish
86 pop.finish
86 return true
87 return true
87 rescue
88 rescue
88 return false
89 return false
89 end
90 end
90 end
91 end
91
92
You need to be logged in to leave comments. Login now