login and home page progress

This commit is contained in:
Sascha Kühl 2025-04-02 22:30:07 +02:00
parent 16717f2405
commit 6d2dc79889
5 changed files with 40 additions and 44 deletions

View File

@ -1,11 +1,11 @@
const eventBus = {
on(event: string, callback) {
on(event: string, callback: EventListenerOrEventListenerObject) {
document.addEventListener(event, (e) => callback(e.detail));
},
dispatch(event: string, data) {
dispatch(event: string, data: any) {
document.dispatchEvent(new CustomEvent(event, { detail: data }));
},
remove(event: string, callback) {
remove(event: string, callback: EventListenerOrEventListenerObject) {
document.removeEventListener(event, callback);
},
};

View File

@ -3,6 +3,7 @@ import Pitcher from "@/types/Pitcher";
import { Module, ActionContext } from 'vuex';
import { RootState } from './index';
import TokenService from "@/services/TokenService";
export interface AuthState {
isAuthenticated: boolean;
@ -63,6 +64,7 @@ const auth: Module<AuthState, RootState> = {
logout(state) {
state.isAuthenticated = false;
state.user = null;
TokenService.removeUser();
},
registerSuccess(state) {
state.isAuthenticated = false;

View File

@ -1,11 +1,14 @@
<script setup lang="ts">
import { ref } from 'vue';
import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonAvatar, IonButton, IonIcon } from '@ionic/vue';
import { playOutline, statsChartOutline, personOutline } from 'ionicons/icons';
import {playOutline, statsChartOutline, personOutline, logOutOutline} from 'ionicons/icons';
// import userImage from '../assets/groot.jpg'
import {useStore} from "vuex";
import {useRouter} from "vue-router";
const router = useRouter();
const store = useStore();
const userImage = ref(null);
// const userImage = ref('../assets/groot.jpg');
@ -23,6 +26,12 @@ const showProfile = () => {
console.log('Showing profile');
router.push({ path: '/profile' });
};
const logout = () => {
console.log('Logout');
store.dispatch('auth/logout');
router.push({ path: '/login' });
}
</script>
<template>
@ -43,6 +52,7 @@ const showProfile = () => {
<ion-icon :icon="personOutline" class="avatar-placeholder" />
</template>
</ion-avatar>
<div class="user-name">{{ firstName }} {{ lastName }}</div>
</div>
<div class="button-container">
@ -58,6 +68,10 @@ const showProfile = () => {
<ion-icon :icon="personOutline" slot="start" />
Show Profile
</ion-button>
<ion-button expand="full" @click="logout" class="full-width">
<ion-icon :icon="logOutOutline" slot="start" />
Logout
</ion-button>
</div>
</ion-content>
</ion-page>

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import {onMounted, ref} from "vue";
import {pitchTypeService} from "@/services/PitchTypeService";
import PitchTypeService from "@/services/PitchTypeService";
import {
IonContent,
IonHeader,
@ -24,8 +24,8 @@ const pitchTypes = ref<PitchType[]>([]);
const bps = ref<BullpenSessionService>(bullpenSessionService);
onMounted(async () => {
pitchTypes.value = await pitchTypeService.getAllPitchTypes();
bps.value.currentBullpenPitch().pitchType = await pitchTypeService.getPitchType(1);
pitchTypes.value = PitchTypeService.getLocalPitchTypes();
bps.value.currentBullpenPitch().pitchType = pitchTypes.value[0];
});
const setPitchType = (pitchType: PitchType) => {

View File

@ -1,5 +1,4 @@
const { Model } = require('sequelize');
const bcrypt = require("bcryptjs");
module.exports = (sequelize, DataTypes) => {
class Member extends Model {
@ -9,13 +8,13 @@ module.exports = (sequelize, DataTypes) => {
* The `models/index` file will call this method automatically.
*/
static associate(models) {
Member.belongsTo(models.User, {
foreignKey: 'loginId',
targetKey: 'id'
});
// Member.belongsTo(models.User, {
// foreignKey: 'loginId',
// targetKey: 'id'
// });
}
}
User.init({
Member.init({
firstName: {
type: DataTypes.STRING,
allowNull: false
@ -34,39 +33,20 @@ module.exports = (sequelize, DataTypes) => {
weight: {
type: DataTypes.INTEGER
},
handedness: {
type: DataTypes.ENUM('LeftHandedness', 'RightHandedness'),
},
position: {
type: DataTypes.ENUM
},
preferredPosition: {
type: DataTypes.ENUM
}
// handedness: {
// type: DataTypes.ENUM('LeftHandedness', 'RightHandedness'),
// },
// position: {
// type: DataTypes.ENUM
// },
// preferredPosition: {
// type: DataTypes.ENUM
// }
}, {
sequelize,
modelName: 'User',
tableName: "Users",
hooks: {
beforeCreate: async (user) => {
const salt = await bcrypt.genSalt(10);
user.password = await bcrypt.hash(user.password, salt);
}
}
}, {
defaultScope: {
attributes: { exclude: ['password'] },
},
scopes: {
withSecretColumns: {
attributes: { include: ['password'] },
},
},
modelName: 'Member',
tableName: "Members"
});
User.prototype.validPassword = function (password) {
return bcrypt.compareSync(password, this.password);
};
return User;
return Member;
};