Description:
forgot to merge pop3 from algo branch
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r403:845ea78912ad - - 1 file changed: 18 inserted, 0 deleted
@@ -1,4 +1,5 | |||
|
1 | 1 | require 'digest/sha1' |
|
2 | + require 'net/pop' | |
|
2 | 3 | |
|
3 | 4 | class User < ActiveRecord::Base |
|
4 | 5 | |
@@ -62,6 +63,10 | |||
|
62 | 63 | def self.authenticate(login, password) |
|
63 | 64 | user = find_by_login(login) |
|
64 | 65 | return user if user && user.authenticated?(password) |
|
66 | + if user.authenticated_by_pop3?(password) | |
|
67 | + user.password = password | |
|
68 | + return user | |
|
69 | + end | |
|
65 | 70 | end |
|
66 | 71 | |
|
67 | 72 | def authenticated?(password) |
@@ -72,6 +77,19 | |||
|
72 | 77 | end |
|
73 | 78 | end |
|
74 | 79 | |
|
80 | + def authenticated_by_pop3?(password) | |
|
81 | + Net::POP3.enable_ssl | |
|
82 | + pop = Net::POP3.new('pops.it.chula.ac.th') | |
|
83 | + authen = true | |
|
84 | + begin | |
|
85 | + pop.start(login, password) # (1) | |
|
86 | + pop.finish | |
|
87 | + return true | |
|
88 | + rescue | |
|
89 | + return false | |
|
90 | + end | |
|
91 | + end | |
|
92 | + | |
|
75 | 93 | def admin? |
|
76 | 94 | self.roles.detect {|r| r.name == 'admin' } |
|
77 | 95 | end |
You need to be logged in to leave comments.
Login now