login and home page progress
This commit is contained in:
parent
16717f2405
commit
6d2dc79889
|
|
@ -1,11 +1,11 @@
|
||||||
const eventBus = {
|
const eventBus = {
|
||||||
on(event: string, callback) {
|
on(event: string, callback: EventListenerOrEventListenerObject) {
|
||||||
document.addEventListener(event, (e) => callback(e.detail));
|
document.addEventListener(event, (e) => callback(e.detail));
|
||||||
},
|
},
|
||||||
dispatch(event: string, data) {
|
dispatch(event: string, data: any) {
|
||||||
document.dispatchEvent(new CustomEvent(event, { detail: data }));
|
document.dispatchEvent(new CustomEvent(event, { detail: data }));
|
||||||
},
|
},
|
||||||
remove(event: string, callback) {
|
remove(event: string, callback: EventListenerOrEventListenerObject) {
|
||||||
document.removeEventListener(event, callback);
|
document.removeEventListener(event, callback);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import Pitcher from "@/types/Pitcher";
|
||||||
|
|
||||||
import { Module, ActionContext } from 'vuex';
|
import { Module, ActionContext } from 'vuex';
|
||||||
import { RootState } from './index';
|
import { RootState } from './index';
|
||||||
|
import TokenService from "@/services/TokenService";
|
||||||
|
|
||||||
export interface AuthState {
|
export interface AuthState {
|
||||||
isAuthenticated: boolean;
|
isAuthenticated: boolean;
|
||||||
|
|
@ -63,6 +64,7 @@ const auth: Module<AuthState, RootState> = {
|
||||||
logout(state) {
|
logout(state) {
|
||||||
state.isAuthenticated = false;
|
state.isAuthenticated = false;
|
||||||
state.user = null;
|
state.user = null;
|
||||||
|
TokenService.removeUser();
|
||||||
},
|
},
|
||||||
registerSuccess(state) {
|
registerSuccess(state) {
|
||||||
state.isAuthenticated = false;
|
state.isAuthenticated = false;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonAvatar, IonButton, IonIcon } from '@ionic/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 userImage from '../assets/groot.jpg'
|
||||||
|
import {useStore} from "vuex";
|
||||||
import {useRouter} from "vue-router";
|
import {useRouter} from "vue-router";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const store = useStore();
|
||||||
|
|
||||||
const userImage = ref(null);
|
const userImage = ref(null);
|
||||||
// const userImage = ref('../assets/groot.jpg');
|
// const userImage = ref('../assets/groot.jpg');
|
||||||
|
|
||||||
|
|
@ -23,6 +26,12 @@ const showProfile = () => {
|
||||||
console.log('Showing profile');
|
console.log('Showing profile');
|
||||||
router.push({ path: '/profile' });
|
router.push({ path: '/profile' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const logout = () => {
|
||||||
|
console.log('Logout');
|
||||||
|
store.dispatch('auth/logout');
|
||||||
|
router.push({ path: '/login' });
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -43,6 +52,7 @@ const showProfile = () => {
|
||||||
<ion-icon :icon="personOutline" class="avatar-placeholder" />
|
<ion-icon :icon="personOutline" class="avatar-placeholder" />
|
||||||
</template>
|
</template>
|
||||||
</ion-avatar>
|
</ion-avatar>
|
||||||
|
<div class="user-name">{{ firstName }} {{ lastName }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="button-container">
|
<div class="button-container">
|
||||||
|
|
@ -58,6 +68,10 @@ const showProfile = () => {
|
||||||
<ion-icon :icon="personOutline" slot="start" />
|
<ion-icon :icon="personOutline" slot="start" />
|
||||||
Show Profile
|
Show Profile
|
||||||
</ion-button>
|
</ion-button>
|
||||||
|
<ion-button expand="full" @click="logout" class="full-width">
|
||||||
|
<ion-icon :icon="logOutOutline" slot="start" />
|
||||||
|
Logout
|
||||||
|
</ion-button>
|
||||||
</div>
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</ion-page>
|
</ion-page>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {onMounted, ref} from "vue";
|
import {onMounted, ref} from "vue";
|
||||||
import {pitchTypeService} from "@/services/PitchTypeService";
|
import PitchTypeService from "@/services/PitchTypeService";
|
||||||
import {
|
import {
|
||||||
IonContent,
|
IonContent,
|
||||||
IonHeader,
|
IonHeader,
|
||||||
|
|
@ -24,8 +24,8 @@ const pitchTypes = ref<PitchType[]>([]);
|
||||||
const bps = ref<BullpenSessionService>(bullpenSessionService);
|
const bps = ref<BullpenSessionService>(bullpenSessionService);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
pitchTypes.value = await pitchTypeService.getAllPitchTypes();
|
pitchTypes.value = PitchTypeService.getLocalPitchTypes();
|
||||||
bps.value.currentBullpenPitch().pitchType = await pitchTypeService.getPitchType(1);
|
bps.value.currentBullpenPitch().pitchType = pitchTypes.value[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
const setPitchType = (pitchType: PitchType) => {
|
const setPitchType = (pitchType: PitchType) => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
const { Model } = require('sequelize');
|
const { Model } = require('sequelize');
|
||||||
const bcrypt = require("bcryptjs");
|
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
class Member extends Model {
|
class Member extends Model {
|
||||||
|
|
@ -9,13 +8,13 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
* The `models/index` file will call this method automatically.
|
* The `models/index` file will call this method automatically.
|
||||||
*/
|
*/
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
Member.belongsTo(models.User, {
|
// Member.belongsTo(models.User, {
|
||||||
foreignKey: 'loginId',
|
// foreignKey: 'loginId',
|
||||||
targetKey: 'id'
|
// targetKey: 'id'
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
User.init({
|
Member.init({
|
||||||
firstName: {
|
firstName: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
|
|
@ -34,39 +33,20 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
weight: {
|
weight: {
|
||||||
type: DataTypes.INTEGER
|
type: DataTypes.INTEGER
|
||||||
},
|
},
|
||||||
handedness: {
|
// handedness: {
|
||||||
type: DataTypes.ENUM('LeftHandedness', 'RightHandedness'),
|
// type: DataTypes.ENUM('LeftHandedness', 'RightHandedness'),
|
||||||
},
|
// },
|
||||||
position: {
|
// position: {
|
||||||
type: DataTypes.ENUM
|
// type: DataTypes.ENUM
|
||||||
},
|
// },
|
||||||
preferredPosition: {
|
// preferredPosition: {
|
||||||
type: DataTypes.ENUM
|
// type: DataTypes.ENUM
|
||||||
}
|
// }
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'User',
|
modelName: 'Member',
|
||||||
tableName: "Users",
|
tableName: "Members"
|
||||||
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'] },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
User.prototype.validPassword = function (password) {
|
return Member;
|
||||||
return bcrypt.compareSync(password, this.password);
|
|
||||||
};
|
|
||||||
|
|
||||||
return User;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue