Description:
add pop3 authentication for chula
create both bookmark and branch so that github will work too
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r390:edc9bac52078 - - 1 file changed: 17 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,9 | |||
|
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 | + end | |
|
65 | 69 | end |
|
66 | 70 | |
|
67 | 71 | def authenticated?(password) |
@@ -72,6 +76,19 | |||
|
72 | 76 | end |
|
73 | 77 | end |
|
74 | 78 | |
|
79 | + def authenticated_by_pop3?(password) | |
|
80 | + Net::POP3.enable_ssl | |
|
81 | + pop = Net::POP3.new('pops.it.chula.ac.th') | |
|
82 | + authen = true | |
|
83 | + begin | |
|
84 | + pop.start(login, password) # (1) | |
|
85 | + pop.finish | |
|
86 | + return true | |
|
87 | + rescue | |
|
88 | + return false | |
|
89 | + end | |
|
90 | + end | |
|
91 | + | |
|
75 | 92 | def admin? |
|
76 | 93 | self.roles.detect {|r| r.name == 'admin' } |
|
77 | 94 | end |
You need to be logged in to leave comments.
Login now