-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
268 additions
and
74 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,66 @@ | ||
<template> | ||
<form @submit.prevent.stop="doLogin"> | ||
<label v-if="createMode">Nome</label> | ||
<input v-if="createMode" v-model="nome" required /> | ||
<label>Email</label> | ||
<input type="email" v-model="email" required /> | ||
<label>Senha</label> | ||
<input type="password" v-model="senha" required /> | ||
<hr> | ||
<button v-if="!createMode" type="submit">Login</button> | ||
<button type="button" aria-roledescription="create-mode" @click="createMode = !createMode">{{createMode ? "Cancelar" : "Criar conta"}}</button> | ||
<button v-if="createMode" type="submit">Criar</button> | ||
</form> | ||
<v-card :title="createMode ? 'Criar conta' : 'Login'"> | ||
<v-form v-model="valid" @submit.prevent.stop="doLogin" class="auth-form"> | ||
<v-text-field :rules=[requiredRule] v-if="createMode" v-model="nome" label="Nome" required></v-text-field> | ||
<v-text-field :rules=[requiredRule] v-model="email" label="Email" required type="email"></v-text-field> | ||
<v-text-field :rules=[requiredRule] v-model="senha" label="Senha" required type="password"></v-text-field> | ||
<hr /> | ||
<v-btn v-if="!createMode" type="submit">Login</v-btn> | ||
<v-btn type="button" @click="createMode = !createMode"> | ||
{{ createMode ? 'Cancelar' : 'Criar conta' }} | ||
</v-btn> | ||
<v-btn v-if="createMode" type="submit">Criar</v-btn> | ||
</v-form> | ||
</v-card> | ||
</template> | ||
<script setup> | ||
import { ref } from "vue"; | ||
import { useUserStore } from "@/stores/userStore"; | ||
const nome = ref(""); | ||
const email = ref(""); | ||
const senha = ref(""); | ||
const createMode = ref(false); | ||
import { ref } from 'vue' | ||
import { useUserStore } from '@/stores/userStore' | ||
import { router } from "@/routes/router"; | ||
const nome = ref('') | ||
const email = ref('') | ||
const senha = ref('') | ||
const createMode = ref(false) | ||
const valid = ref(false) | ||
const uState = useUserStore() | ||
const requiredRule = value => { | ||
if(value) return true | ||
return "Required field" | ||
} | ||
const doLogin = async () => { | ||
if(!valid.value) return | ||
try { | ||
if(createMode.value) { | ||
if (createMode.value) { | ||
await uState.doCreateUser({ | ||
nome: nome.value, email: email.value, senha: senha.value | ||
nome: nome.value, | ||
email: email.value, | ||
senha: senha.value | ||
}) | ||
} | ||
const result = await uState.doLogin({ email: email.value, senha: senha.value }); | ||
const result = await uState.doLogin({ email: email.value, senha: senha.value }) | ||
// TODO guardar informação do usuário logado | ||
uState.setToken(result.token) | ||
await router.push("/") | ||
} catch (e) { | ||
console.log(e); | ||
alert("Algo deu errado"); | ||
console.log(e) | ||
alert('Algo deu errado') | ||
} | ||
}; | ||
} | ||
</script> | ||
<style scoped> | ||
form { | ||
display: flex; | ||
flex-direction: column; | ||
.auth-form { | ||
display: flex; | ||
flex-direction: column; | ||
min-width: 300px; | ||
padding: 1em; | ||
} | ||
label, input, button { | ||
margin: 0.5em; | ||
label, | ||
input, | ||
button { | ||
margin: 0.5em; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
import { createApp } from 'vue' | ||
import { createPinia } from 'pinia' | ||
|
||
import 'vuetify/styles' | ||
import { createVuetify } from 'vuetify' | ||
import { md3 } from 'vuetify/blueprints' | ||
|
||
import { router } from './routes/router' | ||
|
||
import App from './App.vue' | ||
|
||
import './assets/main.css' | ||
|
||
const app = createApp(App) | ||
const vuetify = createVuetify({ | ||
blueprint: md3, | ||
defaults: { | ||
global: { | ||
variant: 'outlined' | ||
} | ||
} | ||
}) | ||
|
||
export const app = createApp(App) | ||
|
||
app.use(createPinia()) | ||
app.use(router) | ||
app.use(vuetify) | ||
|
||
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters