Description:
fix cucas authen, the old code work on 2.1.2 but not 1.9.2
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r407:b11b67ad58fb - - 1 file changed: 8 inserted, 1 deleted
@@ -88,50 +88,57 | |||||
|
88 | pop = Net::POP3.new('pops.it.chula.ac.th') |
|
88 | pop = Net::POP3.new('pops.it.chula.ac.th') |
|
89 | authen = true |
|
89 | authen = true |
|
90 | begin |
|
90 | begin |
|
91 | pop.start(login, password) |
|
91 | pop.start(login, password) |
|
92 | pop.finish |
|
92 | pop.finish |
|
93 | return true |
|
93 | return true |
|
94 | rescue |
|
94 | rescue |
|
95 | return false |
|
95 | return false |
|
96 | end |
|
96 | end |
|
97 | end |
|
97 | end |
|
98 |
|
98 | ||
|
99 | def authenticated_by_cucas?(password) |
|
99 | def authenticated_by_cucas?(password) |
|
100 | url = URI.parse('https://www.cas.chula.ac.th/cas/api/?q=studentAuthenticate') |
|
100 | url = URI.parse('https://www.cas.chula.ac.th/cas/api/?q=studentAuthenticate') |
|
101 | appid = '41508763e340d5858c00f8c1a0f5a2bb' |
|
101 | appid = '41508763e340d5858c00f8c1a0f5a2bb' |
|
102 | appsecret ='d9cbb5863091dbe186fded85722a1e31' |
|
102 | appsecret ='d9cbb5863091dbe186fded85722a1e31' |
|
103 | post_args = { |
|
103 | post_args = { |
|
104 | 'appid' => appid, |
|
104 | 'appid' => appid, |
|
105 | 'appsecret' => appsecret, |
|
105 | 'appsecret' => appsecret, |
|
106 | 'username' => login, |
|
106 | 'username' => login, |
|
107 | 'password' => password |
|
107 | 'password' => password |
|
108 | } |
|
108 | } |
|
109 |
|
109 | ||
|
110 | #simple call |
|
110 | #simple call |
|
111 | begin |
|
111 | begin |
|
112 | - resp = Net::HTTP.post_form(url, post_args) |
|
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) | ||
|
113 | result = JSON.parse resp.body |
|
119 | result = JSON.parse resp.body |
|
|
120 | + end | ||
|
114 | return true if result["type"] == "beanStudent" |
|
121 | return true if result["type"] == "beanStudent" |
|
115 | rescue |
|
122 | rescue |
|
116 | return false |
|
123 | return false |
|
117 | end |
|
124 | end |
|
118 | return false |
|
125 | return false |
|
119 | end |
|
126 | end |
|
120 |
|
127 | ||
|
121 | def admin? |
|
128 | def admin? |
|
122 | self.roles.detect {|r| r.name == 'admin' } |
|
129 | self.roles.detect {|r| r.name == 'admin' } |
|
123 | end |
|
130 | end |
|
124 |
|
131 | ||
|
125 | def email_for_editing |
|
132 | def email_for_editing |
|
126 | if self.email==nil |
|
133 | if self.email==nil |
|
127 | "(unknown)" |
|
134 | "(unknown)" |
|
128 | elsif self.email=='' |
|
135 | elsif self.email=='' |
|
129 | "(blank)" |
|
136 | "(blank)" |
|
130 | else |
|
137 | else |
|
131 | self.email |
|
138 | self.email |
|
132 | end |
|
139 | end |
|
133 | end |
|
140 | end |
|
134 |
|
141 | ||
|
135 | def email_for_editing=(e) |
|
142 | def email_for_editing=(e) |
|
136 | self.email=e |
|
143 | self.email=e |
|
137 | end |
|
144 | end |
You need to be logged in to leave comments.
Login now