diff --git a/public/profile/default_avatar.png b/public/profile/default_avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..45afcfe8037e158b9ab75b9e7219692e50084770 Binary files /dev/null and b/public/profile/default_avatar.png differ diff --git a/src/router/index.js b/src/router/index.js index f5e1f1d502bf0a951df30a0af638f360af166336..568aa495e35286dbcae3024e3e4f2a160998287b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router' import HomeView from '../views/HomeView.vue' import LoginView from '../views/LoginView.vue' import SelectProfileView from '../views/SelectProfileView.vue' +import ProfileCreationView from '../views/ProfileCreationView.vue' import RegisterAccountView from '../views/RegisterAccountView.vue' const router = createRouter({ @@ -22,6 +23,11 @@ const router = createRouter({ name: "selectProfile", component: SelectProfileView }, + { + path: '/newProfile', + name: "newProfile", + component: ProfileCreationView + }, { path: '/registerAccount', name: 'registerAccount', diff --git a/src/util/API.js b/src/util/API.js index 08c1a8af53845299b022368a6fe9ada95329c2c1..0eba7c0b4b30475ef866141d40393d77877d6171 100644 --- a/src/util/API.js +++ b/src/util/API.js @@ -83,8 +83,16 @@ export const API = { }, // Sends the user into the "register profile" view - addProfile: async () => { - console.log("todo"); + addProfile: async (profile) => { + const authStore = useAuthStore(); + if (!authStore.isLoggedIn) { + throw new Error(); + } + + return axios.post(import.meta.env.VITE_BACKEND_URL + '/profile', { + headers: { Authorization: "Bearer " + authStore.token }, + body: profile + }) }, // Returns all profiles to the logged in user diff --git a/src/views/ProfileCreationView.vue b/src/views/ProfileCreationView.vue new file mode 100644 index 0000000000000000000000000000000000000000..6f44c78f94307a9e7dae91cc1257dcc7e1fd1499 --- /dev/null +++ b/src/views/ProfileCreationView.vue @@ -0,0 +1,144 @@ +<script> +export default { + data: () => { + return { + image: "profile/default_avatar.png", + profile: { + profileImageUrl: "", + name: "", + isRestricted: false + } + } + }, + methods: { + submit() { + console.log(this.profile) + }, + + updateImg(e) { + let file = document.getElementById('avatar').files[0]; + let reader = new FileReader(); + + reader.onload = function(ev) { + document.getElementById("avatar_preview").src = ev.target.result; + } + + reader.readAsDataURL(file); + } + } +} +</script> + +<template> + <main> + <h1>Ny profil</h1> + + <form action="todo" method="post"> + <label for="avatar" id="avatar_label"> + <div class="img_hover"> + <img :src="image" alt="fjes" id="avatar_preview"> + <p class="hover_text"> + Klikk for å endre + </p> + </div> + </label> + <input type="file" name="avatar" id="avatar" @change="updateImg"> + <label for="name">Navn</label> + <input name="name" type="text" v-model="profile.name"> + <div class="check_container"> + <label for="child">Begrenset:</label> + <input name="child" type="checkbox" v-model="profile.isRestricted"> + </div> + </form> + <button @click="submit">Opprett</button> + </main> +</template> + +<style scoped lang="scss"> +@import '../style.scss'; + +$img-size: 150px; + +input[type="file"] { + display: none; +} + +main { + display: flex; + flex-direction: column; + + padding-top: 15%; + + flex-wrap: wrap; + justify-content: center; + align-items: center; + + gap: 1em; +} + +#avatar_label { + display: flex; + justify-content: center; + width: 100%; +} + +.check_container { + display: flex; + gap: .5em; +} + +.img_hover { + display: flex; + + justify-content: center; + align-items: center; + + &:hover .hover_text { + visibility: visible; + opacity: 1; + } + + &:hover img { + filter: brightness(70%); + border-radius: 25%; + } + + img { + height: $img-size; + width: $img-size; + border-radius: 50%; + + transition: all 300ms ease; + } +} + +.hover_text { + position: absolute; + + font-weight: bold; + + color: #fff; + visibility: hidden; + opacity: 0; + + transition: all 350ms eases; +} + +form { + display: flex; + flex-direction: column; + + max-width: 20em; +} + + +button { + padding: .5rem 1rem; + border: 2px $green solid; + border-radius: .5rem; + background-color: $light-green; + + color: white; + font-weight: bold; +} +</style> \ No newline at end of file