-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const axios = require("axios"); | ||
const FormData = require("form-data"); | ||
|
||
let Chapter = class { | ||
#memberList; | ||
#loggedIn = false; | ||
/* the CFID and CFTOKEN are required to use the api call that returns | ||
all the chapter members. I don't know what they do, but all I know is | ||
they are required in the URL and they change every time you log in. */ | ||
#CFID = "";; | ||
#CFTOKEN = "";; | ||
|
||
// returns a promise with a success or error message | ||
async login(username, password) { | ||
// create new form data needed to log into the admin panel | ||
const form = new FormData(); | ||
form.append("username", username); | ||
form.append("password", password); | ||
|
||
/* post request sent with the form data to log into admin panel | ||
if login is successful, extract the needed CFID and CFTOKEN */ | ||
await axios | ||
.post("https://services.acm.org/public/chapters/login.cfm", form) | ||
/* a successful login attempt gives the status code 301 (redirect), and | ||
is therefor sent to the .catch block. */ | ||
.catch((response) => { | ||
// successfully logged in | ||
if (response.request.res.statusCode == 300) { | ||
this.#loggedIn = true; | ||
let res = response.request._redirectable._options.query; | ||
this.#CFID = res.slice(5, res.indexOf("&")); | ||
this.#CFTOKEN = res.slice(res.indexOf("CFTOKEN") + 8); | ||
} | ||
}); | ||
|
||
const result = new Promise((resolve, reject) => { | ||
if (this.#loggedIn) { | ||
resolve("Successfully logged in"); | ||
} | ||
else { | ||
reject("ERROR: Invalid login credentials."); | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
} | ||
|
||
module.exports = Chapter; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters