2022-10-17 23:46:04 +00:00
|
|
|
const axios = require('axios').default;
|
|
|
|
|
2023-05-04 19:22:22 +00:00
|
|
|
const loginCheckEndpoint = 'https://ez-pp.farm/login/check';
|
2023-05-31 05:02:05 +00:00
|
|
|
let retries = 0;
|
2022-10-17 23:46:04 +00:00
|
|
|
|
|
|
|
const performLogin = async (username, password) => {
|
|
|
|
const result = await axios.post(loginCheckEndpoint, { username, password });
|
2023-05-31 05:02:05 +00:00
|
|
|
const code = result.data.code ?? 404;
|
|
|
|
if (code === 200 || code === 403) {
|
|
|
|
retries = 0;
|
|
|
|
return result.data;
|
|
|
|
} else {
|
|
|
|
if (retries++ >= 5) return { code: 403, message: "Login failed." }
|
|
|
|
return await performLogin(username, password);
|
|
|
|
}
|
2022-10-17 23:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { performLogin };
|