Skip to content

Commit

Permalink
id-init-not-working
Browse files Browse the repository at this point in the history
  • Loading branch information
fatcatt013 committed Feb 28, 2022
1 parent 5bcb1e5 commit dd4036b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
Binary file modified AleghireDBmodel.mwb
Binary file not shown.
Binary file added AleghireDBmodel.mwb.bak
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/server.js"
"start": "nodemon server.js"
},
"repository": {
"type": "git",
Expand Down
68 changes: 61 additions & 7 deletions src/server.js → server.js
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -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(
{
Expand All @@ -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) {
Expand All @@ -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});
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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.");
Expand All @@ -85,4 +104,39 @@ app.post('/login', (req, res) => {
);
});

app.listen(3001, () => console.log("Server started on port: " + 3001));
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));

0 comments on commit dd4036b

Please sign in to comment.