Skip to content

Commit

Permalink
RED-16 - alterar dados pessoais
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Sep 5, 2024
1 parent 2aad93f commit e49bb89
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 57 deletions.
4 changes: 1 addition & 3 deletions service-node-koa/app/controllers/usuario.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ export const delUsuarioRequest = async (ctx) => {

export const updateUserRequest = async (ctx) => {
const {usuario_id: id} = ctx.params;
const {nome, email, senha, editToken} = ctx.request.body;
const {nome, email, senha} = ctx.request.body;
if (!nome) ctx.throw(400, "Nome de usuário requerido");
if (!email) ctx.throw(400, "Email requerido");
if (!senha) ctx.throw(400, "Senha requerida");
if (!editToken) ctx.throw(400, "editToken requerido");
// TODO verificar/consumir o editToken
const affected = await updateUser({id, nome, email, senha});
// ctx.response.status = 303
// ctx.set("Location", `/dashboard`) // XXX too fancy!
Expand Down
4 changes: 1 addition & 3 deletions web-app-vue/src/pages/configuracao/card-configuracoes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ const closeExport = () => {
}
const linkPerfil = async () => {
alert('um email com o link de solicitação de alteração de dados foi enviado!')
// XXX remover depois que tiver o serviço de email configurado
await router.push('/user-details/1234')
await router.push('/user-details')
}
const logout = async () => {
Expand Down
2 changes: 1 addition & 1 deletion web-app-vue/src/pages/usuario/confirma-cadastro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const enviaChallenge = async () => {
alert('Sucesso! faça login normalmente!')
await router.push("/auth")
} else {
alert('Algo deu errado, tente novamente')
alert('Algo deu errado, tente novamente.')
}
} catch (e) {
console.log(e)
Expand Down
79 changes: 32 additions & 47 deletions web-app-vue/src/pages/usuario/user-details.vue
Original file line number Diff line number Diff line change
@@ -1,94 +1,79 @@
<script setup>
import { reactive, ref } from 'vue'
import { useUserStore } from '@/stores/userStore'
import { minSizeRule, requiredRule } from '@/services/basic-rules'
import { useRoute, useRouter } from 'vue-router'
import {reactive, ref} from 'vue'
import {useUserStore} from '@/stores/userStore'
import {minSizeRule, requiredRule} from '@/services/basic-rules'
import {useRoute, useRouter} from 'vue-router'
const valid = ref(false)
const uState = useUserStore()
const router = useRouter()
const route = useRoute()
const userUpdate = reactive({
id: uState.userData.id,
nome: uState.userData.nome,
email: uState.userData.email,
editToken: route.params.editToken,
repetirSenha: '',
senha: ''
})
const save = async () => {
if (!valid.value) return
if (confirm('Deseja realmente alterar seus dados pessoais?')) {
alert('Verifique o email de confirmação de alteração de dados')
try {
// TODO alterar os dados e descartar o link de alteração
await uState.update(userUpdate)
await uState.logout()
await router.push('/auth')
} catch (e) {
console.log(e)
alert('Problema ao atualizar')
alert(e?.message || 'Problema ao atualizar')
}
}
}
const cancelar = async () => {
if (confirm('Deseja realmente cancelar? será preciso gerar um novo link de alteração de dados!')) {
// TODO descartar o link de alteração
await uState.logout()
await router.push('/auth')
}
await router.push('/')
}
</script>
<template>
<v-card title="Editar dados pessoais" elevation="24">
<v-form v-model="valid" @submit.prevent.stop="save" class="auth-form">
<v-text-field
:rules="[requiredRule('Nome obrigatório')]"
v-model="userUpdate.nome"
label="Nome"
required
></v-text-field>
<v-text-field
:rules="[requiredRule('Email obrigatório')]"
v-model="userUpdate.email"
label="Email"
required
type="email"
:rules="[requiredRule('Nome obrigatório')]"
v-model="userUpdate.nome"
label="Nome"
required
></v-text-field>
<v-text-field
:rules="[requiredRule('Senha obrigatória'), minSizeRule(6, 'Senha deve ter no mínimo 6 caracteres')]"
v-model="userUpdate.senha"
label="Senha"
required
type="password"
:rules="[requiredRule('Email obrigatório')]"
v-model="userUpdate.email"
label="Email"
required
type="email"
></v-text-field>
<v-text-field
:rules="[requiredRule('Confirmação de senha obrigatória'), minSizeRule(6)]"
v-model="userUpdate.repetirSenha"
label=" Confirma Senha"
required
type="password"
:rules="[requiredRule('Senha obrigatória'), minSizeRule(6, 'Senha deve ter no mínimo 6 caracteres')]"
v-model="userUpdate.senha"
label="Senha"
required
type="password"
></v-text-field>
<v-divider />
<v-divider/>
<div class="row">
<v-btn
variant="outlined"
class="ma-2"
color="green"
type="submit"
icon="mdi-check"
variant="outlined"
class="ma-2"
color="green"
type="submit"
icon="mdi-check"
></v-btn>
<v-spacer></v-spacer>
<v-btn
variant="outlined"
color="red"
class="ma-2"
type="button"
@click="cancelar"
icon="mdi-close"
variant="outlined"
color="red"
class="ma-2"
type="button"
@click="cancelar"
icon="mdi-close"
></v-btn>
</div>
</v-form>
Expand Down
4 changes: 2 additions & 2 deletions web-app-vue/src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const createUser = async (newUser) => await post({ uri: '/signup', payloa
export const removeAccount = async ({ id, email, senha }) =>
await del({ uri: `/${id}/removeAccount?email=${email}&senha=${senha}` })

export const updateUser = async ({id = -1, nome, email, senha, editToken, }) =>
await put({uri:`/${id}/updateUser`, payload: {nome, email, senha, editToken}})
export const updateUser = async ({id = -1, nome, email, senha, }) =>
await put({uri:`/${id}/updateUser`, payload: {nome, email, senha}})

export const listTiposConta = async () => await get({ uri: '/tipo-conta' })

Expand Down
2 changes: 1 addition & 1 deletion web-app-vue/src/services/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const routes = [
icon: 'mdi-cog-outline'
}
},
{component: UserDetailsPage, name: '/user-details', path: '/user-details/:editToken'},
{component: UserDetailsPage, name: '/user-details', path: '/user-details'},
]

export const router = createRouter({
Expand Down

0 comments on commit e49bb89

Please sign in to comment.