diff --git a/AleghireDBmodel.mwb b/AleghireDBmodel.mwb index 3b62cda..84cf6c2 100644 Binary files a/AleghireDBmodel.mwb and b/AleghireDBmodel.mwb differ diff --git a/AleghireDBmodel.mwb.bak b/AleghireDBmodel.mwb.bak new file mode 100644 index 0000000..3b62cda Binary files /dev/null and b/AleghireDBmodel.mwb.bak differ diff --git a/package.json b/package.json index d366bfd..36863b9 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "start": "nodemon src/server.js" + "start": "nodemon server.js" }, "repository": { "type": "git", diff --git a/src/server.js b/server.js similarity index 50% rename from src/server.js rename to server.js index 5b2f503..9fcefc9 100644 --- a/src/server.js +++ b/server.js @@ -1,7 +1,7 @@ const express = require('express'); const mysql = require('mysql'); const cors = require('cors'); -const dotenv = require('dotenv').config({path: "../.env"}) +const dotenv = require('dotenv').config() const app = express(); app.use(express.json()); @@ -11,6 +11,7 @@ const DB_USER = process.env.DB_USER; const DB_HOST = process.env.DB_HOST; const DB_PWD = process.env.DB_PASSWORD; const DB_NAME = process.env.DB_NAME; +const PORT = process.env.PORT; const db = mysql.createConnection( { @@ -21,13 +22,31 @@ const db = mysql.createConnection( } ) +app.post("/getId", (req, res) => { + const username = req.body.username; + + console.log("Attempting to get ID."); + db.query("SELECT * FROM User WHERE username = ?", [username], (err, result) => { + if (err) { + console.log("There was an error"); + } + if (result.length < 1) { + console.log("Cant find the ID with this username: " + username); + res.send({message: "ID with username of " + username + " was not found."}); + } else { + console.log("Successfully found ID."); + res.send({result: result}); + } + }); +}); + app.post("/check-register", (req, res) => { const username = req.body.username; const email = req.body.email; console.log("Checking the availability of the credentials:\nusername=" + username + "\nemail=" + email); - db.query("SELECT * FROM users WHERE username = ? OR email = ?", + db.query("SELECT * FROM User WHERE username = ? OR email = ?", [username, email], (err, result) => { if (err) { @@ -36,7 +55,7 @@ app.post("/check-register", (req, res) => { } if (result.length > 0) { res.send({message: "User with this credentials already exists."}); - console.log("User with this credentials already exists."); + return; } console.log("The credentials are available.") res.send({message: 1}); @@ -49,7 +68,7 @@ app.post("/register", (req, res) => { const password = req.body.password; const email = req.body.email; - db.query("INSERT INTO users (username, password, email) VALUES (?, ?, ?)", + db.query("INSERT INTO User (username, password, email) VALUES (?, ?, ?)", [username, password, email], (err) => { if (err) { @@ -67,7 +86,7 @@ app.post('/login', (req, res) => { console.log("Attempting to log in with: \nusername=" + username + "\npassword" + password); - db.query("SELECT * FROM users WHERE username = ? AND password = ?", + db.query("SELECT * FROM User WHERE username = ? AND password = ?", [username, password], (err, result) => { if (err) { @@ -76,7 +95,7 @@ app.post('/login', (req, res) => { } if (result.length > 0) { res.send({message: 1}); - console.log("Successfuly logged in."); + console.log("Successfully logged in."); } else { res.send({message: "No user found"}); console.log("No user found."); @@ -85,4 +104,39 @@ app.post('/login', (req, res) => { ); }); -app.listen(3001, () => console.log("Server started on port: " + 3001)); \ No newline at end of file +app.post("/init-user", (req, res) => { + console.log("Initializing user stats."); + + const id = req.id; + const name = req.body.name; + const level = req.body.level; + const exp = req.body.exp; + const strength = req.body.strength; + const stamina = req.body.stamina; + const dexterity = req.body.dexterity; + const intelligence = req.body.intelligence; + const luck = req.body.luck; + const money = req.body.money; + + const class_ = req.body.class; + const pfp = req.body.pfp; + const religion = req.body.religion; + const guild = "None"; + + + console.log("ID: " + id); + db.query("INSERT INTO UserStats" + + " (level, exp, religion, strength, stamina, dexterity, intelligence, luck, User_id, money)" + + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + [level, exp, religion, strength, stamina, dexterity, intelligence, luck, id, money]), + (err) => { + if (err) { + console.log(err); + res.send({err: err}); + } else { + res.send({message: 1}) + } + } +}); + +app.listen(PORT, () => console.log("Server started on port: " + PORT)); \ No newline at end of file