lib/lwqzx.rb in lwqzx-0.0.5 vs lib/lwqzx.rb in lwqzx-0.0.6

- old
+ new

@@ -1,22 +1,15 @@ require "lwqzx/version" -require 'nokogiri' - +require 'rest-client' +require 'json' module Lwqzx def self.auth(login,passwd) - lurl = "http://www.lwqzx.sdedu.net/kernel/net_school/active_app/login1.php" - user = "login_user_m_=#{login}" - psd = "login_password=#{passwd}" - res = %x[curl #{lurl} -s -c /tmp/cookies -d #{user} -d #{psd} ] - infos = %x[curl -s -b /tmp/cookies #{lurl}] - content=infos.encode("UTF-8","GB2312") - doc = Nokogiri::HTML(content) - uname = doc.css("span.tt1 a:nth-child(1)").text - return {} if uname == "" - groups = doc.css("span.tt1 a:nth-child(5)")[0]["title"] - %x[rm /tmp/cookies] - groups=groups.gsub("[","").gsub("]","").split("@").compact.reject(&:empty?) - return {login: login, name: uname, groups: groups} - end + lurl = "http://www.lwqzx.sdedu.net/kernel/net_school/core/jslogin.php" + res = ::RestClient.post lurl,{login: login, password: passwd} + hsh = ::JSON.parse(res.body) + return {} if hsh["name"].empty? + login = hsh["login"] + name = hsh["name"] + groups = hsh["user_group"] + return {login: login, name: name, groups: groups} + end end - -Lwqzx.auth("dsfas","dsfasd")