diff --git a/software/backend/database.ts b/software/backend/database.ts index fbe9012..5f38cdb 100644 --- a/software/backend/database.ts +++ b/software/backend/database.ts @@ -23,7 +23,7 @@ export const sequelize = new Sequelize({ export function startDatabase() { // Create database and tables - sequelize.sync({ force: true }) + sequelize.sync({ force: false }) .then(() => { console.log(`Database & tables created!`) }) diff --git a/software/backend/routes/account.routes.ts b/software/backend/routes/account.routes.ts index 897eec3..658e165 100644 --- a/software/backend/routes/account.routes.ts +++ b/software/backend/routes/account.routes.ts @@ -14,13 +14,15 @@ account.get("/", (req: Request, res: Response, next: NextFunction) => { }) // Creating a new user -account.post("/", (req: Request, res: Response, next: NextFunction) => { +account.post("/register", (req: Request, res: Response, next: NextFunction) => { if (!validateString(req.body.username, 4)) { + // Status: 400 Bad request res.status(400).send({ error: "Username too short!" }) } else if (!validateString(req.body.password, 8)) { + // Status: 400 Bad request res.status(400).send({ error: "Password too short!" }) } else @@ -28,9 +30,31 @@ account.post("/", (req: Request, res: Response, next: NextFunction) => { Account.create(req.body) .then(account => { res.json(account) + + // Status: 200 OK res.status(200).send() }).catch(reason => { + // Status: 400 Bad request res.status(400).send({ error: reason }) }) } +}) + +account.post("/login", (req: Request, res: Response, next: NextFunction) => { + Account.findOne({ raw: true, where: { username: req.body.username }}) + .then(account => { + if (account != null) { + if (account.password == req.body.password) { + // Status: 200 OK + res.status(200).send({ userAccountId: account.id }) + } else { + // Status: 401 Unauthorized + res.status(401).send() + } + } else { + // Status: 401 Unauthorized + res.status(401).send() + } + } + ) }) \ No newline at end of file diff --git a/software/src/App.vue b/software/src/App.vue index 81b575b..ac189e9 100644 --- a/software/src/App.vue +++ b/software/src/App.vue @@ -1,13 +1,12 @@ + + \ No newline at end of file diff --git a/software/src/data/stores/userStore.ts b/software/src/data/stores/userStore.ts index db0d279..4d6bf6a 100644 --- a/software/src/data/stores/userStore.ts +++ b/software/src/data/stores/userStore.ts @@ -6,6 +6,7 @@ import { LanguageEnum } from "../enums/languageEnum"; export const useUserStore = defineStore('user', { state: () => ({ theme: useLocalStorage("hackmycart/userStore/theme", ThemeEnum.DARKRED), - language: useLocalStorage("hackmycart/userStore/language", LanguageEnum.GERMAN) + language: useLocalStorage("hackmycart/userStore/language", LanguageEnum.GERMAN), + userAccountId: useLocalStorage("hackmycart/userStore/userAccountId", -1) }) }) \ No newline at end of file diff --git a/software/src/locales/english.json b/software/src/locales/english.json index 54e02e9..86b8e37 100644 --- a/software/src/locales/english.json +++ b/software/src/locales/english.json @@ -46,5 +46,6 @@ "postalCode": "Postal Code", "city": "City" }, - "backToLogin": "Back to Login" + "backToLogin": "Back to Login", + "logout": "Logout" } \ No newline at end of file diff --git a/software/src/locales/german.json b/software/src/locales/german.json index f3171f4..1923388 100644 --- a/software/src/locales/german.json +++ b/software/src/locales/german.json @@ -46,5 +46,6 @@ "postalCode": "Postleitzahl", "city": "Stadt" }, - "backToLogin": "Zurück zum Login" + "backToLogin": "Zurück zum Login", + "logout": "Ausloggen" } \ No newline at end of file diff --git a/software/src/pages/loginPage/index.vue b/software/src/pages/loginPage/index.vue index 9c40b08..38e3c81 100644 --- a/software/src/pages/loginPage/index.vue +++ b/software/src/pages/loginPage/index.vue @@ -20,7 +20,7 @@ const banner = ref(new BannerModel()) - + diff --git a/software/src/pages/loginPage/loginForm.vue b/software/src/pages/loginPage/loginForm.vue index 192d29f..c512f68 100644 --- a/software/src/pages/loginPage/loginForm.vue +++ b/software/src/pages/loginPage/loginForm.vue @@ -1,5 +1,37 @@