Skip to content
Snippets Groups Projects
Commit df793c2d authored by Lucas Eduardo Schoenfelder's avatar Lucas Eduardo Schoenfelder
Browse files

fixed update email/password functionality

parent 54d09633
No related branches found
No related tags found
4 merge requests!57Merge of develop into master,!56Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments...,!39Update admin system,!32Homologa
......@@ -59,21 +59,18 @@ export default function TabPanelGerenciarConta (props) {
key : flag,
value : userInput
})
console.log(senhaAtual)
}
else if(type === 'novaSenha') {
setNovaSenha({...novaSenha,
key : flag,
value : userInput
})
console.log(novaSenha)
}
else if (type === 'confirmacao'){
setNovaSenhaConfirmacao({...novaSenhaConfirmacao,
key : flag,
value : userInput
})
console.log(novaSenhaConfirmacao)
}
}
......@@ -86,7 +83,6 @@ export default function TabPanelGerenciarConta (props) {
value : userInput
})
console.log(novoEmail)
}
const limpaCamposForm = () => {
......@@ -110,21 +106,18 @@ export default function TabPanelGerenciarConta (props) {
e.preventDefault()
if (type === 'senha'){
if (senhaAtual.value === localStorage.getItem("@portalmec/senha")) {
const login = {senhaAtual : senhaAtual.value, novaSenha : novaSenha.value, novaSenhaConfirmacao : novaSenhaConfirmacao.value}
if (!(senhaAtual.key || novaSenha.key || novaSenhaConfirmacao.key)) {
console.log(login)
limpaCamposForm()
props.handleSnackbar()
}
}
else {
console.log(localStorage.getItem("@portalmec/senha"), senhaAtual.value)
if (!(senhaAtual.key || novaSenha.key || novaSenhaConfirmacao.key)) {
const info = {user : {password : novaSenha.value}}
props.updateUserPassword(info)
limpaCamposForm()
}
}
else {
console.log(novoEmail.value)
const info = {user : {email : novoEmail.value}}
props.updateUserEmail(info)
}
}
......@@ -222,4 +215,3 @@ export default function TabPanelGerenciarConta (props) {
</>
)
}
......@@ -38,7 +38,6 @@ export default function EditProfilePage (props) {
handleSnackbar(false);
}
const updateUserInfo = (newUserInfo) => {
console.log(newUserInfo)
let config = getAxiosConfig()
......@@ -50,8 +49,48 @@ export default function EditProfilePage (props) {
if ( res.headers['access-token'] ) {
sessionStorage.setItem('@portalmec/accessToken', res.headers['access-token'])
}
props.history.push('/perfil')
},
(err) => {
console.log(err)
}
)
}
const updateUserEmail = (newUserInfo) => {
let config = getAxiosConfig()
axios.put( (`${apiUrl}/users/` + id), newUserInfo, config
).then (
(res) => {
console.log(res)
if ( res.headers['access-token'] ) {
sessionStorage.setItem('@portalmec/accessToken', res.headers['access-token'])
}
sessionStorage.setItem('@portalmec/uid', res.headers['uid'])
},
(err) => {
console.log(err)
}
)
}
const updateUserPassword = (newUserInfo) => {
let config = getAxiosConfig()
axios.put( (`${apiUrl}/users/` + id), newUserInfo, config
).then (
(res) => {
console.log(res)
if ( res.headers['access-token'] ) {
sessionStorage.setItem('@portalmec/accessToken', res.headers['access-token'])
}
handleSnackbar(true)
},
(err) => {
console.log(err)
......@@ -98,7 +137,9 @@ export default function EditProfilePage (props) {
{tabValue === 0 && <TabPanelEditarPerfil updateUserInfo={updateUserInfo}/>}
{tabValue === 1 && <TabPanelSolicitarContaProfessor/>}
</Paper>
{tabValue === 2 && <TabPanelGerenciarConta handleSnackbar={() => {handleSnackbar(true)}}/>}
{tabValue === 2 && <TabPanelGerenciarConta updateUserEmail={updateUserEmail}
updateUserPassword={updateUserPassword}
/>}
</TabContentDiv>
</MainContainerDiv>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment