Description:
fix pop3 authen
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r395:52cd3037bb5e - - 1 file changed: 2 inserted, 1 deleted
@@ -42,50 +42,51 | |||
|
42 | 42 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
43 | 43 | :if => :email_validation? |
|
44 | 44 | validate :uniqueness_of_email_from_activated_users, |
|
45 | 45 | :if => :email_validation? |
|
46 | 46 | validate :enough_time_interval_between_same_email_registrations, |
|
47 | 47 | :if => :email_validation? |
|
48 | 48 | |
|
49 | 49 | # these are for ytopc |
|
50 | 50 | # disable for now |
|
51 | 51 | #validates_presence_of :province |
|
52 | 52 | |
|
53 | 53 | attr_accessor :password |
|
54 | 54 | |
|
55 | 55 | before_save :encrypt_new_password |
|
56 | 56 | before_save :assign_default_site |
|
57 | 57 | before_save :assign_default_contest |
|
58 | 58 | |
|
59 | 59 | # this is for will_paginate |
|
60 | 60 | cattr_reader :per_page |
|
61 | 61 | @@per_page = 50 |
|
62 | 62 | |
|
63 | 63 | def self.authenticate(login, password) |
|
64 | 64 | user = find_by_login(login) |
|
65 | 65 | return user if user && user.authenticated?(password) |
|
66 | - if user.authenticated_by_pop3?(password) | |
|
66 | + if user && user.authenticated_by_pop3?(password) | |
|
67 | 67 | user.password = password |
|
68 | + user.save | |
|
68 | 69 | return user |
|
69 | 70 | end |
|
70 | 71 | end |
|
71 | 72 | |
|
72 | 73 | def authenticated?(password) |
|
73 | 74 | if self.activated |
|
74 | 75 | hashed_password == User.encrypt(password,self.salt) |
|
75 | 76 | else |
|
76 | 77 | false |
|
77 | 78 | end |
|
78 | 79 | end |
|
79 | 80 | |
|
80 | 81 | def authenticated_by_pop3?(password) |
|
81 | 82 | Net::POP3.enable_ssl |
|
82 | 83 | pop = Net::POP3.new('pops.it.chula.ac.th') |
|
83 | 84 | authen = true |
|
84 | 85 | begin |
|
85 | 86 | pop.start(login, password) # (1) |
|
86 | 87 | pop.finish |
|
87 | 88 | return true |
|
88 | 89 | rescue |
|
89 | 90 | return false |
|
90 | 91 | end |
|
91 | 92 | end |
You need to be logged in to leave comments.
Login now