-
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
0 parents
commit 4e249bc
Showing
32 changed files
with
22,074 additions
and
0 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,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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 @@ | ||
node_modules | ||
npm-debug.log |
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,3 @@ | ||
|
||
node_modules | ||
.env |
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,7 @@ | ||
const express=require('express'); | ||
const Router=express.Router(); | ||
const userService=require('../Services/userService'); | ||
|
||
Router.post('/login',userService.userLogin) | ||
Router.post('/register',userService.userSignup) | ||
module.exports=Router |
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,77 @@ | ||
const db = require("../config/dbConfig"); | ||
const bcrypt = require("bcryptjs"); | ||
const jwt = require("jsonwebtoken"); | ||
|
||
const securityKey = "12345@Ra"; | ||
const tableName = "user_information_80001_7788"; // This is your specific table name | ||
|
||
const userLogin = async (req, res) => { | ||
const { email, password } = req.body; | ||
|
||
const { results } = await db | ||
.prepare(`SELECT * FROM ${tableName} WHERE email = ?;`) | ||
.bind(email) | ||
.all(); | ||
|
||
if (results.length === 0) { | ||
res.json({ | ||
status: 400, | ||
message: "user not matched", | ||
}); | ||
} else { | ||
if (await bcrypt.compare(password, results[0].password)) { | ||
const auth = jwt.sign({ data: results[0] }, securityKey); | ||
res.json({ | ||
status: 200, | ||
message: "Login success", | ||
token: auth, | ||
}); | ||
} else { | ||
res.json({ | ||
status: 400, | ||
message: "Please check the password", | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
const userSignup = async (req, res) => { | ||
const { username, email, password } = req.body; | ||
const salt = await bcrypt.genSalt(10); | ||
const hashpwd = await bcrypt.hash(password, salt); | ||
|
||
const { results } = await db | ||
.prepare(`SELECT * FROM ${tableName} WHERE email = ?;`) | ||
.bind(email) | ||
.all(); | ||
|
||
if (results.length > 0) { | ||
res.json({ | ||
status: 400, | ||
message: "User already exists", | ||
}); | ||
} else { | ||
try { | ||
const { meta: insert } = await db | ||
.prepare( | ||
`INSERT INTO ${tableName} (username, email, password) VALUES (?, ?, ?);` | ||
) | ||
.bind(username, email, hashpwd) | ||
.run(); | ||
|
||
await insert.txn.wait(); | ||
|
||
res.json({ | ||
status: 200, | ||
message: `Successfully registered ${username}`, | ||
}); | ||
} catch (error) { | ||
res.json({ | ||
status: 400, | ||
message: error, | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = { userSignup, userLogin }; |
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,18 @@ | ||
const express = require("express"); | ||
const env = require("dotenv").config(); | ||
const bodyparser = require("body-parser"); | ||
const cors = require("cors"); | ||
|
||
const app = express(); | ||
const user = require("./Routes/userRouter"); | ||
|
||
// Middleware configuration | ||
app.use(bodyparser.json()); | ||
app.use(cors()); | ||
app.use("/user", user); | ||
|
||
const PORT = process.env.PORT || 4000; // Corrected the fallback to default value for PORT | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server listening on port ${PORT}`); | ||
}); |
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,21 @@ | ||
const env = require("dotenv").config(); | ||
|
||
|
||
const ethers = require("ethers"); | ||
const tableland = require("@tableland/sdk"); | ||
|
||
// Set up the provider and wallet using your private key. | ||
let provider = new ethers.providers.JsonRpcProvider( | ||
"https://capable-winter-paper.matic-testnet.quiknode.pro/152107c19beb0243104885340d25c00808394af7/" | ||
); | ||
let privateKey = | ||
"0x522c6ab985d1f22f3bf1f918ef1e19cd52e986fa91bfe8c18208d20a00ecbbde"; // Your private key | ||
let wallet = new ethers.Wallet(privateKey, provider); | ||
|
||
// Connect the wallet to the provider. | ||
let signer = wallet.connect(provider); | ||
|
||
// Create the Tableland database instance using the signer. | ||
const db = new tableland.Database({ signer }); | ||
|
||
module.exports = db; |
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,14 @@ | ||
FROM node:18 | ||
# Create app directory | ||
WORKDIR /d/Work/Spheron/loginpage/Backend | ||
# Install app dependencies | ||
# A wildcard is used to ensure both package.json AND package-lock.json are copied | ||
# where available (npm@5+) | ||
COPY package*.json ./ | ||
RUN npm install | ||
# If you are building your code for production | ||
# RUN npm ci --omit=dev | ||
# Bundle app source | ||
COPY . . | ||
EXPOSE 8080 | ||
CMD [ "node", "app.js" ] |
Oops, something went wrong.