Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/update-profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"algohub": patch:feat
---

Support for updating profile information and account activation.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"words": [
"algohub",
"confirmationservice",
"covector",
"icns",
"persistedstate",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"primeicons": "^7.0.0",
"primevue": "^4.2.2",
"vue": "^3.5.13",
"vue-picture-cropper": "^0.7.0",
"vue-router": "^4.4.5",
"zod": "^3.23.8"
},
Expand Down
57 changes: 49 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import App from "@/App.vue";
import PrimeVue from "primevue/config";
import Aura from "@primevue/themes/aura";
import ToastService from "primevue/toastservice";
import ConfirmationService from 'primevue/confirmationservice';

import router from "./router";
import { createPinia } from "pinia";
Expand All @@ -30,5 +31,6 @@ app.use(PrimeVue, {
},
});
app.use(ToastService);
app.use(ConfirmationService);

app.mount("#app");
58 changes: 58 additions & 0 deletions src/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,61 @@ export const register = async (form: Register) => {
} as ErrorResponse;
}
};

interface UploadAvatar {
id: string;
token: string;
file: File;
}

interface UploadAvatarResponse {
uri: string;
}

export const uploadAvatar = async (form: UploadAvatar) => {
try {
const response = await axios.put("/account/content/upload", form, {
headers: {
"Content-Type": "multipart/form-data",
},
});
return response.data as Response<UploadAvatarResponse>;
} catch (error) {
return {
success: false,
message: AxiosError.from(error).message,
} as ErrorResponse;
}
};

interface Profile {
avatar?: string;
signature?: string;
links?: string[];
nickname?: string;
sex?: boolean;
birthday?: string;
name?: string;
student_id?: string;
school?: string;
college?: string;
major?: string;
}

interface ProfileForm {
id: string;
token: string;
profile: Profile;
}

export const updateProfile = async (form: ProfileForm) => {
try {
const response = await axios.post("/account/profile", form);
return response.data as Response<undefined>;
} catch (error) {
return {
success: false,
message: AxiosError.from(error).message,
};
}
};
53 changes: 52 additions & 1 deletion src/scripts/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { computed, ref } from "vue";

const prefersDarkMode = () => {
return (
Expand Down Expand Up @@ -34,3 +34,54 @@ export const useThemeStore = defineStore(
persist: true,
}
);

interface Account {
id?: string;
token?: string;

username: string;
email: string;
avatar?: string;
signature?: string;
links?: string[];

nickname?: string;
sex?: boolean;
birthday?: Date;

name?: string;
student_id?: string;
school?: string;
college?: string;
major?: string;

rating?: number;
role?: number;
active?: boolean;
}

export const useAccountStore = defineStore(
"account",
() => {
const account = ref<Account | null>(null);

const isLoggedIn = computed(
() => account.value !== null && account.value.token
);

const mergeProfile = (profile: Partial<Account>) => {
if (account.value) {
Object.assign(account.value, profile);
}
};

const logout = () => {
account.value = null;
};

return { account, isLoggedIn, mergeProfile, logout };
},
{
persist: true,
}
);
6 changes: 5 additions & 1 deletion src/views/index.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<script setup lang="ts">
import { useAccountStore } from "@/scripts/store";
import { onMounted } from "vue";
import { useRouter } from 'vue-router';

const router = useRouter();
const accountStore = useAccountStore();

onMounted(() => {
router.push("/login");
if (!accountStore.isLoggedIn) {
router.push("/login");
}
})
</script>

Expand Down
Loading