More feedback on account creation, bugfix on account creation
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { AccountModel } from "../data/models/user/accountModel";
|
||||
import { useFeedbackStore } from "./feedback.store";
|
||||
import { deleteAccount, fetchAllAccounts, getAccount, login, registerAccount, updateAccount } from "../data/api/accountApi";
|
||||
import { deleteAccount, fetchAllAccounts, getAccount, getLogin, registerAccount, updateAccount } from "../data/api/accountApi";
|
||||
import { fetchUserOrders } from "../data/api/orderApi";
|
||||
import { BannerStateEnum } from "../data/enums/bannerStateEnum";
|
||||
import { AddressModel } from "../data/models/user/addressModel";
|
||||
@@ -38,10 +38,13 @@ export const useAccountStore = defineStore("accountStore", {
|
||||
}),
|
||||
|
||||
actions: {
|
||||
/**
|
||||
* Fetch all accounts on the database
|
||||
*/
|
||||
async getAllAccounts() {
|
||||
this.fetchInProgress = true
|
||||
|
||||
fetchAllAccounts()
|
||||
fetchAllAccounts(this.userAccountToken)
|
||||
.then(response => {
|
||||
this.accounts = response.data
|
||||
this.fetchInProgress = false
|
||||
@@ -68,7 +71,7 @@ export const useAccountStore = defineStore("accountStore", {
|
||||
}
|
||||
else
|
||||
{
|
||||
await login(this.loginData.username, this.loginData.password)
|
||||
await getLogin(this.loginData.username, this.loginData.password)
|
||||
.then(async result => {
|
||||
this.userAccountToken = result.data.token
|
||||
|
||||
@@ -100,6 +103,9 @@ export const useAccountStore = defineStore("accountStore", {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reload account information about current logged in user
|
||||
*/
|
||||
async refreshAccount() {
|
||||
getAccount(this.userAccountToken)
|
||||
.then(response => {
|
||||
@@ -123,32 +129,42 @@ export const useAccountStore = defineStore("accountStore", {
|
||||
const exerciseStore = useExerciseStore()
|
||||
this.fetchInProgress = true
|
||||
|
||||
await registerAccount(this.registerData)
|
||||
.then(async res => {
|
||||
if (res.status == 201) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTREGISTERSUCCESSFUL)
|
||||
exerciseStore.solveExercise(0, 1)
|
||||
}
|
||||
if (this.registerData.username == null || this.registerData.username.length < 4) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTUSERNAMETOOSHORT)
|
||||
} else if (this.registerData.password == null || this.registerData.password.length < 8) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTPASSWORDTOOSHORT)
|
||||
} else if (!this.registerData.email.match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTMAILADDRESSUNVALID)
|
||||
}
|
||||
else {
|
||||
await registerAccount(this.registerData)
|
||||
.then(async res => {
|
||||
if (res.status == 201) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTREGISTERSUCCESSFUL)
|
||||
exerciseStore.solveExercise(0, 1)
|
||||
}
|
||||
|
||||
this.loginData = {
|
||||
username: this.registerData.username,
|
||||
password: this.registerData.password
|
||||
}
|
||||
this.loginData = {
|
||||
username: this.registerData.username,
|
||||
password: this.registerData.password
|
||||
}
|
||||
|
||||
this.fetchInProgress = false
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.status == 400) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTREGISTERERROR)
|
||||
} else if (error.status == 409) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTREGISTERUSERNAMEINUSE)
|
||||
}
|
||||
this.fetchInProgress = false
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.status == 400) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTREGISTERERROR)
|
||||
} else if (error.status == 409) {
|
||||
feedbackStore.addSnackbar(BannerStateEnum.ACCOUNTREGISTERUSERNAMEORMAILINUSE)
|
||||
}
|
||||
|
||||
this.fetchInProgress = false
|
||||
return false
|
||||
})
|
||||
this.fetchInProgress = false
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return false
|
||||
this.fetchInProgress = false
|
||||
return false
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -229,6 +245,11 @@ export const useAccountStore = defineStore("accountStore", {
|
||||
)
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete user account
|
||||
*
|
||||
* @param account Account which should be deleted
|
||||
*/
|
||||
async deleteAccount(account: AccountModel) {
|
||||
this.fetchInProgress = true
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export const useBasketStore = defineStore('basketStore', {
|
||||
*/
|
||||
removeItemFromBasket(item: BasketItemModel) {
|
||||
const feedbackStore = useFeedbackStore()
|
||||
feedbackStore.addSnackbar(BannerStateEnum.BASKETPRODUCTREMOVED)
|
||||
feedbackStore.addSnackbar(BannerStateEnum.BASKETTICKETREMOVED)
|
||||
|
||||
this.itemsInBasket = this.itemsInBasket.filter((basketItemModel: BasketItemModel) =>
|
||||
basketItemModel.concert.id != item.concert.id
|
||||
|
||||
@@ -46,10 +46,10 @@ export const useFeedbackStore = defineStore("feedbackStore", {
|
||||
case BannerStateEnum.ERROR:
|
||||
return this.i18n.t('bannerMessages.error')
|
||||
|
||||
case BannerStateEnum.BASKETPRODUCTADDED:
|
||||
case BannerStateEnum.BASKETTICKETADDED:
|
||||
return this.i18n.t('bannerMessages.basketTicketAdded')
|
||||
|
||||
case BannerStateEnum.BASKETPRODUCTREMOVED:
|
||||
case BannerStateEnum.BASKETTICKETREMOVED:
|
||||
return this.i18n.t("bannerMessages.basketTicketRemoved")
|
||||
|
||||
|
||||
@@ -127,8 +127,8 @@ export const useFeedbackStore = defineStore("feedbackStore", {
|
||||
case BannerStateEnum.ACCOUNTREGISTERERROR:
|
||||
return this.i18n.t("bannerMessages.registerSuccessful")
|
||||
|
||||
case BannerStateEnum.ACCOUNTREGISTERUSERNAMEINUSE:
|
||||
return this.i18n.t("bannerMessages.usernameInUse")
|
||||
case BannerStateEnum.ACCOUNTREGISTERUSERNAMEORMAILINUSE:
|
||||
return this.i18n.t("bannerMessages.usernameOrMailInUse")
|
||||
|
||||
case BannerStateEnum.ACCOUNTUPDATESUCCESSFUL:
|
||||
return this.i18n.t("bannerMessages.accountUpdated")
|
||||
@@ -136,6 +136,15 @@ export const useFeedbackStore = defineStore("feedbackStore", {
|
||||
case BannerStateEnum.ACCOUNTLOGOUTSUCCESSFUL:
|
||||
return this.i18n.t('bannerMessages.logoutSuccessful')
|
||||
|
||||
case BannerStateEnum.ACCOUNTPASSWORDTOOSHORT:
|
||||
return this.i18n.t('bannerMessages.accountPasswordTooShort')
|
||||
|
||||
case BannerStateEnum.ACCOUNTUSERNAMETOOSHORT:
|
||||
return this.i18n.t('bannerMessages.accountUsernameTooShort')
|
||||
|
||||
case BannerStateEnum.ACCOUNTMAILADDRESSUNVALID:
|
||||
return this.i18n.t('bannerMessages.accountMailAddressUnvalid')
|
||||
|
||||
|
||||
////////// API Endpoint /orders //////////
|
||||
|
||||
@@ -180,14 +189,17 @@ export const useFeedbackStore = defineStore("feedbackStore", {
|
||||
case BannerStateEnum.ACCOUNTLOGINERROR:
|
||||
case BannerStateEnum.ACCOUNTLOGINWRONGLOGIN:
|
||||
case BannerStateEnum.ACCOUNTREGISTERERROR:
|
||||
case BannerStateEnum.ACCOUNTREGISTERUSERNAMEINUSE:
|
||||
case BannerStateEnum.ACCOUNTREGISTERUSERNAMEORMAILINUSE:
|
||||
case BannerStateEnum.ACCOUNTPASSWORDTOOSHORT:
|
||||
case BannerStateEnum.ACCOUNTUSERNAMETOOSHORT:
|
||||
case BannerStateEnum.ACCOUNTMAILADDRESSUNVALID:
|
||||
case BannerStateEnum.BANDDELETEERROR:
|
||||
case BannerStateEnum.BANDSAVEDERROR:
|
||||
case BannerStateEnum.GENREDELETEERROR:
|
||||
case BannerStateEnum.GENRESAVEDERROR:
|
||||
return "red"
|
||||
|
||||
case BannerStateEnum.BASKETPRODUCTADDED:
|
||||
case BannerStateEnum.BASKETTICKETADDED:
|
||||
case BannerStateEnum.DATABASERESETSUCCESSFUL:
|
||||
case BannerStateEnum.ACCOUNTLOGINSUCCESSFUL:
|
||||
case BannerStateEnum.ACCOUNTREGISTERSUCCESSFUL:
|
||||
@@ -215,7 +227,7 @@ export const useFeedbackStore = defineStore("feedbackStore", {
|
||||
case BannerStateEnum.EXERCISESOLVED32:
|
||||
return "purple"
|
||||
|
||||
case BannerStateEnum.BASKETPRODUCTREMOVED:
|
||||
case BannerStateEnum.BASKETTICKETREMOVED:
|
||||
return "blue"
|
||||
}
|
||||
},
|
||||
@@ -229,7 +241,10 @@ export const useFeedbackStore = defineStore("feedbackStore", {
|
||||
case BannerStateEnum.ACCOUNTLOGINERROR:
|
||||
case BannerStateEnum.ACCOUNTLOGINWRONGLOGIN:
|
||||
case BannerStateEnum.ACCOUNTREGISTERERROR:
|
||||
case BannerStateEnum.ACCOUNTREGISTERUSERNAMEINUSE:
|
||||
case BannerStateEnum.ACCOUNTPASSWORDTOOSHORT:
|
||||
case BannerStateEnum.ACCOUNTUSERNAMETOOSHORT:
|
||||
case BannerStateEnum.ACCOUNTMAILADDRESSUNVALID:
|
||||
case BannerStateEnum.ACCOUNTREGISTERUSERNAMEORMAILINUSE:
|
||||
return "mdi-account"
|
||||
|
||||
case BannerStateEnum.EXERCISESOLVED01:
|
||||
@@ -250,8 +265,8 @@ export const useFeedbackStore = defineStore("feedbackStore", {
|
||||
case BannerStateEnum.EXERCISEPROGRESSRESETSUCCESSFUL:
|
||||
return "mdi-database-refresh"
|
||||
|
||||
case BannerStateEnum.BASKETPRODUCTADDED:
|
||||
case BannerStateEnum.BASKETPRODUCTREMOVED:
|
||||
case BannerStateEnum.BASKETTICKETADDED:
|
||||
case BannerStateEnum.BASKETTICKETREMOVED:
|
||||
return "mdi-basket"
|
||||
|
||||
case BannerStateEnum.ORDERPLACESUCCESSFUL:
|
||||
|
||||
Reference in New Issue
Block a user