-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
9146a68
commit 2d3f768
Showing
10 changed files
with
3,576 additions
and
3,229 deletions.
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,30 @@ | ||
name: CI express-2fa | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
paths: | ||
- "express-2fa/**" | ||
pull_request: | ||
branches: [master] | ||
paths: | ||
- "express-2fa/**" | ||
|
||
jobs: | ||
type-check: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: express-2fa | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x, 22.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm run type-check |
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,9 @@ | ||
module.exports = { | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
}, | ||
rules: { | ||
'new-cap': 'off', | ||
'no-console': 'off', | ||
}, | ||
}; |
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 @@ | ||
20.17.0 |
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,2 @@ | ||
nodejs 20.17.0 | ||
npm 10.8.1 |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import mysql from "mysql"; | ||
|
||
let connection: mysql.Connection; | ||
|
||
const config: mysql.ConnectionConfig = { | ||
host: process.env.DB_SERVER_NAME, | ||
user: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
}; | ||
|
||
const dbConnection = (config: mysql.ConnectionConfig) => { | ||
connection = mysql.createConnection(config); | ||
return new Promise<void>((resolve, reject) => { | ||
connection.connect((err, result) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export const insertUser = async ( | ||
name: string, | ||
password: string, | ||
number: string | ||
) => { | ||
try { | ||
await dbConnection(config); | ||
} catch (err) { | ||
console.log("Error connecting to the database"); | ||
console.log(err); | ||
} | ||
const query = | ||
"INSERT INTO `users`(`username`, `password`, `phone`, `verified`) VALUES (?, ?, ?, 0)"; | ||
|
||
return new Promise((resolve, reject) => { | ||
connection.query(query, [name, password, number], (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
console.log(`Inserted 1 user`); | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export const verifyUser = async (name: string) => { | ||
try { | ||
await dbConnection(config); | ||
} catch (err) { | ||
console.log("Error connecting to the database"); | ||
console.log(err); | ||
} | ||
|
||
const query = "UPDATE `users` SET `verified`=1 WHERE `username`=?"; | ||
|
||
return new Promise((resolve, reject) => { | ||
connection.query(query, [name], (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
console.log(`Verified ${name} in the database`); | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export const getUsername = async (name: string) => { | ||
try { | ||
await dbConnection(config); | ||
} catch (err) { | ||
console.log("Error connecting to the database"); | ||
console.log(err); | ||
} | ||
const query = "SELECT * FROM `users` WHERE `username`=?"; | ||
|
||
return new Promise<unknown[]>((resolve, reject) => { | ||
connection.query(query, [name], (err, rows) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(rows); | ||
} | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.