Commit 56073408 authored by Matheus Horstmann's avatar Matheus Horstmann 🐴 Committed by Rafael S Castilho

Change Password

Signed-off-by: Matheus Horstmann's avatarMatheus Horstmann <mch15@inf.ufpr.br>
parent 76d7486a
......@@ -153,12 +153,14 @@ export function Options(props) {
{"icon":locationIcon,"text":"Gerenciamento de Setores", "link":"/gerenciasetores" },
{"icon":locationIcon,"text":"Gerenciamento de Blocos", "link":"/gerenciabloco" },
{"icon":locationIcon,"text":"Gerenciamento de Usuarios", "link":"/gerenciausuarios" },
{"icon":locationIcon,"text":"Mudar Senha", "link":"/mudarsenha" },
]
break;
case "secretario_setor":
list_options = [
{"icon":locationIcon,"text":"Gerenciamento de Blocos", "link":"/gerenciabloco" },
{"icon":salasIcon,"text":"Gerenciamento de Salas", "link":"/gerenciasala" },
{"icon":locationIcon,"text":"Mudar Senha", "link":"/mudarsenha" },
]
break;
case "comissao":
......@@ -174,6 +176,7 @@ export function Options(props) {
{"icon":locationIcon,"text":"Gerenciamento de Setores", "link":"/gerenciasetores" },
{"icon":locationIcon,"text":"Gerenciamento de Blocos", "link":"/gerenciabloco" },
{"icon":locationIcon,"text":"Gerenciamento de Usuarios", "link":"/gerenciausuarios" },
{"icon":locationIcon,"text":"Mudar Senha", "link":"/mudarsenha" },
]
break;
case "secretario_dpto":
......@@ -181,6 +184,7 @@ export function Options(props) {
{"icon":locationIcon,"text":"Gerenciamento de Disciplinas", "link":"/gerenciadisciplina" },
{"icon":locationIcon,"text":"Gerenciamento de Turmas", "link":"/gerenciaturma" },
{"icon":professoresIcon,"text":"Gerenciamento de Professores", "link":"/gerenciaprofessores" },
{"icon":locationIcon,"text":"Mudar Senha", "link":"/mudarsenha" },
]
break;
......
import React, { useState, useEffect } from 'react';
import Container from '@material-ui/core/Container';
import CssBaseline from '@material-ui/core/CssBaseline';
import Input from '@material-ui/core/Input';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import Grid from '@material-ui/core/Grid';
import { makeStyles } from '@material-ui/core/styles';
import {Messages,MessageActive} from "../messagesystem"
import Button from '@material-ui/core/Button';
import api from '../api'
async function change_password(evt,old_password,new_password, setMessage, setMessageActive) {
evt.preventDefault()
var params = {
oldPassword: old_password,
newPassword: new_password
};
var formBody = [];
for (var property in params) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(params[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
var header = {
'Content-Type': 'application/x-www-form-urlencoded;',
'Accept': 'application/json'
}
try {
var response = await api.post("/usuarios/change-password",formBody,header)
console.log(response)
setMessage("Senha alterada com sucesso")
setMessageActive(true)
} catch (e) {
console.log(e)
console.log(response)
setMessage("Senha Incorreta")
setMessageActive(true)
}
}
const useStyles = makeStyles(theme => ({
container: {
display: 'grid',
gridTemplateColumns: 'repeat(12, 1fr)',
gridGap: theme.spacing(3),
},
button: {
backgroundColor: "#ADD68B",
width: "190px",
height: "45px",
textAlign: 'left',
fontFamily: 'Open Sans,SemiBold',
color: "#FFFFFF"
},
buttonsend: {
color: "#ADD68B",
fontFamily: 'Open Sans,SemiBold',
},
buttoncancel: {
color: "red",
fontFamily: 'Open Sans,SemiBold',
},
input: {
display: 'none',
},
textField: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
width: 200,
},
}));
export function ChangePasswordForm(props) {
const styles_info = { backgroundColor: '#F6F6F6',border: " 2px solid #CECECE", height: '270px', width: '405px' }
const classes = useStyles();
var [old_password,setOldPassword] = useState({})
var [new_password,setNewPassword] = useState("")
var [confirm_password,setConfirmPassword] = useState("")
const {message_active,setMessageActive} = React.useContext(MessageActive)
const {message,setMessage} = React.useContext(Messages);
return (
<div style={styles_info}>
<form onSubmit={(evt)=>{change_password(evt,old_password,new_password, setMessage,setMessageActive)}} className={{display: 'flex', flexWrap: 'wrap'}} noValidate>
<Grid container spacing={2} alignItems="center" justify="space-around" direction="column">
<Grid item >
<TextField
id="old-password"
label="Senha Antiga"
type="password"
required={true}
onChange={(event) =>{setOldPassword(event.target.value)}}
autoComplete="current-password"
className={classes.textField}
InputLabelProps={{ shrink: true, }}
/>
</Grid>
<Grid item >
<TextField
id="new-password"
label="Nova Senha"
type="password"
required={true}
onChange={(event) =>{setNewPassword(event.target.value)}}
className={classes.textField}
InputLabelProps={{ shrink: true, }}
/>
</Grid>
<Grid item >
<TextField
error={(new_password !== confirm_password) && !(confirm_password.length === 0)}
helperText={((new_password !== confirm_password) && !(confirm_password.length === 0)) ? 'Senhas são diferentes' : ''}
id="confirm-password"
label="Confirme a Senha"
type="password"
required={true}
className={classes.textField}
onChange={(event) =>{setConfirmPassword(event.target.value)}}
InputLabelProps={{ shrink: true, }}
/>
</Grid>
<Grid item >
<Button
type="submit"
className={classes.buttonsend}
disabled={new_password !== confirm_password || confirm_password.length === 0 || new_password.length===0}
>
Mudar Senha
</Button>
</Grid>
</Grid>
</form>
</div>
);
}
export function ChangePassword(props) {
const styles = { backgroundColor: '#F6F6F6',border: " 2px solid #CECECE", height: '220px', width: '375px' }
const classes = useStyles();
const {message,setMessage} = React.useContext(Messages)
return (
<Grid
container
spacing={10}
direction="column"
alignItems="center"
justify="center"
style={{minHeight: '100vh'}}
>
<ChangePasswordForm></ChangePasswordForm>
</Grid>
);
}
......@@ -13,6 +13,7 @@ import {GerenciarProfessor} from './pages/gerenciarprofessor.jsx';
import {GerenciarSala} from './pages/gerenciarsala.jsx';
import {GerenciarEnsalador} from './pages/gerenciarensalamento.jsx';
import {PaginaInicial} from './pages/paginainicial.jsx';
import {ChangePassword} from './pages/mudarsenha.jsx';
import {Header} from './components/header/Header';
import './App.css';
......@@ -45,6 +46,7 @@ const Routes = () => (
<PrivateRoute path="/gerenciasetores" component={()=><GerenciarSetores/>} />
<PrivateRoute path="/gerenciadisciplina" component={()=><GerenciarDisciplina/>} />
<PrivateRoute path="/gerenciacurso" component={()=><GerenciarCurso/>} />
<PrivateRoute path="/mudarsenha" component={()=><ChangePassword/>} />
<PrivateRoute path="/gerenciasala" component={()=><GerenciarSala/>} />
<PrivateRoute path="/gerenciabloco" component={()=><GerenciarBloco/>} />
<PrivateRoute path="/gerenciaprofessores" component={()=><GerenciarProfessor/>} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment