Description:
remove authenticate by pop3 and cucas
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r485:b530a9de9711 - - 1 file changed: 0 inserted, 47 deleted
@@ -58,82 +58,35 | |||||
|
58 | before_save :encrypt_new_password |
|
58 | before_save :encrypt_new_password |
|
59 | before_save :assign_default_site |
|
59 | before_save :assign_default_site |
|
60 | before_save :assign_default_contest |
|
60 | before_save :assign_default_contest |
|
61 |
|
61 | ||
|
62 | # this is for will_paginate |
|
62 | # this is for will_paginate |
|
63 | cattr_reader :per_page |
|
63 | cattr_reader :per_page |
|
64 | @@per_page = 50 |
|
64 | @@per_page = 50 |
|
65 |
|
65 | ||
|
66 | def self.authenticate(login, password) |
|
66 | def self.authenticate(login, password) |
|
67 | user = find_by_login(login) |
|
67 | user = find_by_login(login) |
|
68 | if user |
|
68 | if user |
|
69 | return user if user.authenticated?(password) |
|
69 | return user if user.authenticated?(password) |
|
70 | - if user.authenticated_by_cucas?(password) or user.authenticated_by_pop3?(password) |
|
||
|
71 | - user.password = password |
|
||
|
72 | - user.save |
|
||
|
73 | - return user |
|
||
|
74 | - end |
|
||
|
75 | end |
|
70 | end |
|
76 | end |
|
71 | end |
|
77 |
|
72 | ||
|
78 | def authenticated?(password) |
|
73 | def authenticated?(password) |
|
79 | if self.activated |
|
74 | if self.activated |
|
80 | hashed_password == User.encrypt(password,self.salt) |
|
75 | hashed_password == User.encrypt(password,self.salt) |
|
81 | else |
|
76 | else |
|
82 | false |
|
77 | false |
|
83 | end |
|
78 | end |
|
84 | end |
|
79 | end |
|
85 |
|
80 | ||
|
86 | - def authenticated_by_pop3?(password) |
|
||
|
87 | - Net::POP3.enable_ssl |
|
||
|
88 | - pop = Net::POP3.new('pops.it.chula.ac.th') |
|
||
|
89 | - authen = true |
|
||
|
90 | - begin |
|
||
|
91 | - pop.start(login, password) |
|
||
|
92 | - pop.finish |
|
||
|
93 | - return true |
|
||
|
94 | - rescue |
|
||
|
95 | - return false |
|
||
|
96 | - end |
|
||
|
97 | - end |
|
||
|
98 | - |
|
||
|
99 | - def authenticated_by_cucas?(password) |
|
||
|
100 | - url = URI.parse('https://www.cas.chula.ac.th/cas/api/?q=studentAuthenticate') |
|
||
|
101 | - appid = '41508763e340d5858c00f8c1a0f5a2bb' |
|
||
|
102 | - appsecret ='d9cbb5863091dbe186fded85722a1e31' |
|
||
|
103 | - post_args = { |
|
||
|
104 | - 'appid' => appid, |
|
||
|
105 | - 'appsecret' => appsecret, |
|
||
|
106 | - 'username' => login, |
|
||
|
107 | - 'password' => password |
|
||
|
108 | - } |
|
||
|
109 | - |
|
||
|
110 | - #simple call |
|
||
|
111 | - begin |
|
||
|
112 | - http = Net::HTTP.new('www.cas.chula.ac.th', 443) |
|
||
|
113 | - http.use_ssl = true |
|
||
|
114 | - result = [ ] |
|
||
|
115 | - http.start do |http| |
|
||
|
116 | - req = Net::HTTP::Post.new('/cas/api/?q=studentAuthenticate') |
|
||
|
117 | - param = "appid=#{appid}&appsecret=#{appsecret}&username=#{login}&password=#{password}" |
|
||
|
118 | - resp = http.request(req,param) |
|
||
|
119 | - result = JSON.parse resp.body |
|
||
|
120 | - end |
|
||
|
121 | - return true if result["type"] == "beanStudent" |
|
||
|
122 | - rescue |
|
||
|
123 | - return false |
|
||
|
124 | - end |
|
||
|
125 | - return false |
|
||
|
126 | - end |
|
||
|
127 | - |
|
||
|
128 | def admin? |
|
81 | def admin? |
|
129 | self.roles.detect {|r| r.name == 'admin' } |
|
82 | self.roles.detect {|r| r.name == 'admin' } |
|
130 | end |
|
83 | end |
|
131 |
|
84 | ||
|
132 | def email_for_editing |
|
85 | def email_for_editing |
|
133 | if self.email==nil |
|
86 | if self.email==nil |
|
134 | "(unknown)" |
|
87 | "(unknown)" |
|
135 | elsif self.email=='' |
|
88 | elsif self.email=='' |
|
136 | "(blank)" |
|
89 | "(blank)" |
|
137 | else |
|
90 | else |
|
138 | self.email |
|
91 | self.email |
|
139 | end |
|
92 | end |
You need to be logged in to leave comments.
Login now