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) { ...@@ -59,21 +59,18 @@ export default function TabPanelGerenciarConta (props) {
key : flag, key : flag,
value : userInput value : userInput
}) })
console.log(senhaAtual)
} }
else if(type === 'novaSenha') { else if(type === 'novaSenha') {
setNovaSenha({...novaSenha, setNovaSenha({...novaSenha,
key : flag, key : flag,
value : userInput value : userInput
}) })
console.log(novaSenha)
} }
else if (type === 'confirmacao'){ else if (type === 'confirmacao'){
setNovaSenhaConfirmacao({...novaSenhaConfirmacao, setNovaSenhaConfirmacao({...novaSenhaConfirmacao,
key : flag, key : flag,
value : userInput value : userInput
}) })
console.log(novaSenhaConfirmacao)
} }
} }
...@@ -86,7 +83,6 @@ export default function TabPanelGerenciarConta (props) { ...@@ -86,7 +83,6 @@ export default function TabPanelGerenciarConta (props) {
value : userInput value : userInput
}) })
console.log(novoEmail)
} }
const limpaCamposForm = () => { const limpaCamposForm = () => {
...@@ -110,21 +106,18 @@ export default function TabPanelGerenciarConta (props) { ...@@ -110,21 +106,18 @@ export default function TabPanelGerenciarConta (props) {
e.preventDefault() e.preventDefault()
if (type === 'senha'){ 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)) { if (!(senhaAtual.key || novaSenha.key || novaSenhaConfirmacao.key)) {
console.log(login) const info = {user : {password : novaSenha.value}}
props.updateUserPassword(info)
limpaCamposForm() limpaCamposForm()
props.handleSnackbar()
}
}
else {
console.log(localStorage.getItem("@portalmec/senha"), senhaAtual.value)
} }
} }
else { else {
console.log(novoEmail.value) const info = {user : {email : novoEmail.value}}
props.updateUserEmail(info)
} }
} }
...@@ -222,4 +215,3 @@ export default function TabPanelGerenciarConta (props) { ...@@ -222,4 +215,3 @@ export default function TabPanelGerenciarConta (props) {
</> </>
) )
} }
...@@ -38,7 +38,6 @@ export default function EditProfilePage (props) { ...@@ -38,7 +38,6 @@ export default function EditProfilePage (props) {
handleSnackbar(false); handleSnackbar(false);
} }
const updateUserInfo = (newUserInfo) => { const updateUserInfo = (newUserInfo) => {
console.log(newUserInfo) console.log(newUserInfo)
let config = getAxiosConfig() let config = getAxiosConfig()
...@@ -52,6 +51,46 @@ export default function EditProfilePage (props) { ...@@ -52,6 +51,46 @@ export default function EditProfilePage (props) {
} }
props.history.push('/perfil') 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) => { (err) => {
console.log(err) console.log(err)
...@@ -98,7 +137,9 @@ export default function EditProfilePage (props) { ...@@ -98,7 +137,9 @@ export default function EditProfilePage (props) {
{tabValue === 0 && <TabPanelEditarPerfil updateUserInfo={updateUserInfo}/>} {tabValue === 0 && <TabPanelEditarPerfil updateUserInfo={updateUserInfo}/>}
{tabValue === 1 && <TabPanelSolicitarContaProfessor/>} {tabValue === 1 && <TabPanelSolicitarContaProfessor/>}
</Paper> </Paper>
{tabValue === 2 && <TabPanelGerenciarConta handleSnackbar={() => {handleSnackbar(true)}}/>} {tabValue === 2 && <TabPanelGerenciarConta updateUserEmail={updateUserEmail}
updateUserPassword={updateUserPassword}
/>}
</TabContentDiv> </TabContentDiv>
</MainContainerDiv> </MainContainerDiv>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment