Skip to content

Commit

Permalink
feat: 更改簽核系統登入方式
Browse files Browse the repository at this point in the history
從request改為fect
  • Loading branch information
Chinlinlee committed Jan 9, 2021
1 parent 22400f8 commit f76bb19
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
14 changes: 13 additions & 1 deletion models/users/School_Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,20 @@ module.exports.Auth = async function(username , password , obj ={})

module.exports.signOffAuth = async function(username , password , obj ="")
{
return new Promise ((resolve)=>
return new Promise (async (resolve)=>
{
let j = myFunc.getSignOffJar(obj);
const fetch = require('fetch-cookie')(nodefetch , j );
const params = new URLSearchParams();
params.append('txtid' , username);
params.append('txtpwd' , password);
params.append('select' , 'student');
let fetchRes = await fetch('http://system10.ntunhs.edu.tw/Workflow/Common/UserControls/loginModule.aspx?' + params , {
method : "POST"
});
let body = await fetchRes.text();
obj.session.ntunhsSignOff = await j.getCookieString('http://system10.ntunhs.edu.tw');
return resolve(body);
if (obj)
{
obj(
Expand Down
46 changes: 27 additions & 19 deletions models/users/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@ const request = require('request');
const myFunc = require('../../routes/My_Func');
const cheerio = require('cheerio');
const nodeFetch = require('node-fetch');
require('tls').DEFAULT_MIN_VERSION = 'TLSv1'

async function getSTNO (req , iFetch)
{
return new Promise (async (resolve)=>
{
let j = myFunc.getJar(req);
let option =
{
method : "GET" ,
uri : `http://system8.ntunhs.edu.tw/myNTUNHS_student/Modules/Profile/tab/Profile_tab_02.aspx` ,
followRedirect: true ,
jar : j
}
let fetchRes = await iFetch(option.uri , {method:"GET" , redirect : "follow" , follow: 100});
let fetchRes = await iFetch(option.uri , {
method:"GET"
});
let getStnoPageUri = await fetchRes.text();
//let getStnoPageUri = await myFunc.Request_func(myReqObj , option);
let $ = cheerio.load(getStnoPageUri);
let aTags = $("a")[0].attribs.href;
option =
{
method : "GET" ,
uri : aTags ,
followRedirect: true ,
jar : j
uri : aTags
}
let getStnoPageRes = await iFetch(option.uri , {method:"GET" , redirect : "follow"});
let getStnoPageRes = await iFetch(option.uri , {
method:"GET" ,
redirect : "follow"
});
let getStnoPage = await getStnoPageRes.text();
$ = cheerio.load(getStnoPage);
let frameSrc = $("#DialogFrame")[0].attribs.src;
Expand Down Expand Up @@ -60,7 +61,6 @@ module.exports = async function(passport)
},
async function (req , username , password , done)
{
let myReqObj = request.defaults({jar : true});
let loginresult = await School_Auth.Auth(username , password , req);
//req.session.myJar = myReqObj.jar;
let logingResultCode = loginresult.split('_');
Expand All @@ -74,15 +74,14 @@ module.exports = async function(passport)
let loginHomeOption =
{
method : 'GET' ,
uri : `https://system8.ntunhs.edu.tw/myNTUNHS_student/Common/UserControls/loginModule.aspx?txtid=${username}&code=${logingResultCode[1]}&from=OVGfeJ71k85Va+5tUAkRpREuBeu/vj73Xq3Nr9sDoY5sDt38lS4gFsKrX0qYogYUVoxr8f++8G+yMZLEa9IDN5SWFS76zmop52j0OW69Fks=&select=student` ,
jar : j
uri : `https://system8.ntunhs.edu.tw/myNTUNHS_student/Common/UserControls/loginModule.aspx?txtid=${username}&code=${logingResultCode[1]}&from=OVGfeJ71k85Va+5tUAkRpREuBeu/vj73Xq3Nr9sDoY5sDt38lS4gFsKrX0qYogYUVoxr8f++8G+yMZLEa9IDN5SWFS76zmop52j0OW69Fks=&select=student`
}
let fetch = require('fetch-cookie')(nodeFetch , j , false );
let homeFetchRes = await fetch(loginHomeOption.uri , {method:"GET" , redirect:"follow" , follow: 100});
let homeFetchRes = await fetch(loginHomeOption.uri ,
{
method:"GET" ,
});
let homeBody = await homeFetchRes.text();

//console.log(homeBody);
//let homeBody = await myFunc.Request_func(myReqObj ,loginHomeOption);
let $ = cheerio.load(homeBody);
let Profile = $("#ctl00_tableProfile tr");
let stuInfo = [];
Expand All @@ -107,19 +106,28 @@ module.exports = async function(passport)
}
req.session.stuInfo = stuInfoObj;
req.session.ntunhsApp = await j.getCookieString('http://system8.ntunhs.edu.tw');
let loginSginOffResult = await School_Auth.signOffAuth(username , password , myReqObj);



let siginfetch = require('fetch-cookie')(nodeFetch , signOffJar , false)
let loginSginOffResult = await School_Auth.signOffAuth(username , password , req);
//req.session.myJar = myReqObj.jar;
let loginSginOffResultCode = loginSginOffResult.split('_');
let loginSignOffoPtion =
{
method : 'GET' ,
uri : `http://system10.ntunhs.edu.tw/Workflow/Common/UserControls/loginModule.aspx?txtid=${username}&code=${loginSginOffResultCode[1]}&from=RSj5Im20848gChj8rkdWGJFBlYl/7U1mZ4gJDdbJ5OM3j763Vu+cjUoqjRZXBp6GvBdG3Ya2QodhSYM88vhcFw==&select=student` ,
uri : `http://system10.ntunhs.edu.tw/Workflow/Common/UserControls/loginModule.aspx?txtid=${username}&code=${loginSginOffResultCode[1]}&from=tyg/tU01wVvnsZtbm7tPhKak44RMjpfRkFt7mKZlzW85P4GKxNNs+wfm8PCM3+Si7dJ2HijacHOvd/jmQztdSg==&select=student` ,
jar : signOffJar ,
followRedirect : true
}
//console.log(loginSignOffoPtion.uri);
await myFunc.Request_func(myReqObj , loginSignOffoPtion);
req.session.ntunhsSignOff = signOffJar.getCookieString('http://system10.ntunhs.edu.tw');
let signOffFetch = await siginfetch(loginSignOffoPtion.uri , {
method:"GET" ,
redirect : 'follow' ,
follow : 1000
});
let signOffFetchBody = await signOffFetch.text();
req.session.ntunhsSignOff = await signOffJar.getCookieString('http://system10.ntunhs.edu.tw');
req.session.Course = [];
req.session.HistoryScore = [];
req.session.Score = [];
Expand Down

0 comments on commit f76bb19

Please sign in to comment.