Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed login request to work again #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 32 additions & 22 deletions lib/sunnyportal.js
Expand Up @@ -40,33 +40,43 @@ var SunnyPortal = function(opts) {
var _login = function(callback) {
var jar = request.jar();

var requestOpts = {
form : {
__EVENTTARGET : '',
ctl00$ContentPlaceHolder1$Logincontrol1$LoginBtn : 'Login',
ctl00$ContentPlaceHolder1$Logincontrol1$txtPassword : password,
ctl00$ContentPlaceHolder1$Logincontrol1$txtUserName : username
var options = {
'method': 'POST',
'url': url + LOGIN_URL,
'headers': {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'Origin': 'https://www.sunnyportal.com',
'Content-Type': ['application/x-www-form-urlencoded', 'application/x-www-form-urlencoded'],
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document',
'Referer': 'https://www.sunnyportal.com/Templates/Start.aspx',
'Accept-Language': 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
},
form: {
'__EVENTTARGET': '',
'__EVENTARGUMENT': '',
'ctl00$ContentPlaceHolder1$Logincontrol1$txtUserName': username,
'ctl00$ContentPlaceHolder1$Logincontrol1$txtPassword': password,
'ctl00$ContentPlaceHolder1$Logincontrol1$LoginBtn': 'Anmelden',
'ctl00$ContentPlaceHolder1$hiddenLanguage': 'de-de'
},
// Service does not have a valid cert
strictSSL : false,
jar : jar
};

request.post(url + LOGIN_URL, requestOpts, function (err, httpResponse, body) {
if (err) {
console.error('login failed:', err);
callback(err);
return ;
}
// Hack to check for login. Should forward to dashboard.
if(httpResponse.headers.location && httpResponse.headers.location=='/FixedPages/Dashboard.aspx') {
callback(err, jar);
jar : jar
};
request(options, function (error, response) {
if (error) throw new Error(error);
if(response.headers.location && response.headers.location=='/FixedPages/HoManLive.aspx') {
callback(error, jar);
} else {
callback(new Error('Login Failed'));
}


});
});

};

Expand Down