Skip to content

Commit 5ccef85

Browse files
committed
fix: improve code readability and consistency in API routes
1 parent 303f55b commit 5ccef85

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

API/server.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ app.post('/api/login', async (req, res) => {
4040
let _count = new Database("users", ["username"], [username]);
4141
let __count = await _count.count();
4242

43-
if(__count >= 1) {
43+
if (__count >= 1) {
4444
let DB = new Database("users", ["username"], [username]);
4545
let values = await DB.read();
4646

@@ -53,8 +53,8 @@ app.post('/api/login', async (req, res) => {
5353
const now = new Date();
5454
const expire = new Date(now.getTime() + 5 * 60 * 1000);
5555

56-
while(true) {
57-
if(Array.isArray(pendingLogin[rndID])) {
56+
while (true) {
57+
if (Array.isArray(pendingLogin[rndID])) {
5858
rndID = Math.floor(Math.random() * 9999999999);
5959
}
6060
else {
@@ -64,13 +64,13 @@ app.post('/api/login', async (req, res) => {
6464

6565
pendingLogin[rndID] = pendingLogin[rndID] || [];
6666

67-
pendingLogin[rndID].push({
68-
USERNAME: username,
67+
pendingLogin[rndID].push({
68+
USERNAME: username,
6969
TOTP_SECRET_KEY: values[0].totp_secret_key,
7070
EXPIRE: expire,
7171
ATTEMPTS: 0
7272
});
73-
73+
7474
const data = {
7575
"STATUS": "SUCCESS",
7676
"MESSAGE": "ACCEPTED - VALID CREDENTIALS, NOW YOU MUST VALIDATE YOUR ACCESS WITH THE OTP",
@@ -118,8 +118,8 @@ app.post('/api/otp_verification', async (req, res) => {
118118

119119
let _expire = new Date(expire);
120120
let now = new Date();
121-
122-
if(now > _expire) {
121+
122+
if (now > _expire) {
123123
// The pending request has expired
124124
delete pendingLogin[pendingID];
125125

@@ -135,8 +135,8 @@ app.post('/api/otp_verification', async (req, res) => {
135135

136136
else {
137137
let otpIsValid = checkIsValid(otp, totp_secretKey);
138-
139-
if(otpIsValid) {
138+
139+
if (otpIsValid) {
140140
// Done, the user is authenticated! :)
141141
// You can now implement token management for user logins, including expiration control, multiple login management, and other related features
142142

@@ -161,7 +161,7 @@ app.post('/api/otp_verification', async (req, res) => {
161161
pendingLogin[pendingID][0].ATTEMPTS = attemps + 1;
162162

163163
// Incorrect OTP entered 5 times in a row, i'm canceling the request for security reasons
164-
if(attemps >= 5) {
164+
if (attemps >= 5) {
165165
delete pendingLogin[pendingID];
166166

167167
const data = {
@@ -278,14 +278,14 @@ app.post('/api/signup', async (req, res) => {
278278

279279
return;
280280
}
281-
281+
282282
const cryptedPasswd = await hashPassword(password);
283283

284284
let _newSecretKey = newSecretKey();
285-
285+
286286
const columns = ["username", "password", "totp_secret_key"];
287287
const parameters = [username, cryptedPasswd, _newSecretKey];
288-
288+
289289
let mysqlCMD = new Database("users", columns, parameters);
290290
mysqlCMD.insert();
291291

0 commit comments

Comments
 (0)