Skip to content
Snippets Groups Projects
Commit e9a09f97 authored by Gabriel Silva Hermida's avatar Gabriel Silva Hermida
Browse files

Issue #39: password validation

parent 62022323
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ import FormInput from "../components/fieldsSignUp/FormInput"; ...@@ -10,7 +10,7 @@ import FormInput from "../components/fieldsSignUp/FormInput";
import Paper from "@material-ui/core/Paper"; import Paper from "@material-ui/core/Paper";
import api from "../api"; import api from "../api";
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles((theme) => ({
register: { register: {
maxWidth: "1000px", maxWidth: "1000px",
background: "#ffffff", background: "#ffffff",
...@@ -18,24 +18,24 @@ const useStyles = makeStyles(theme => ({ ...@@ -18,24 +18,24 @@ const useStyles = makeStyles(theme => ({
padding: "2% 1%", padding: "2% 1%",
marginTop: "3%", marginTop: "3%",
margin: "0 auto", margin: "0 auto",
width: "95%" width: "95%",
}, },
custom_strong: { custom_strong: {
fontSize: "25px", fontSize: "25px",
textAlign: "center", textAlign: "center",
display: "block", display: "block",
color: "#46525d" color: "#46525d",
}, },
strong_description: { strong_description: {
fontSize: "14px", fontSize: "14px",
color: "#c2c6ca" color: "#c2c6ca",
}, },
form: { form: {
alignItems: "center", alignItems: "center",
textAlign: "center" textAlign: "center",
}, },
alreadyAcc: { alreadyAcc: {
marginTop: "10px" marginTop: "10px",
}, },
button: { button: {
type: "submit", type: "submit",
...@@ -47,12 +47,18 @@ const useStyles = makeStyles(theme => ({ ...@@ -47,12 +47,18 @@ const useStyles = makeStyles(theme => ({
padding: "10px 20px", padding: "10px 20px",
fontSize: "18px", fontSize: "18px",
"&:hover": { "&:hover": {
backgroundColor: "rgb(25, 109, 23)" backgroundColor: "rgb(25, 109, 23)",
}, },
["@media (max-width:550px)"]: { ["@media (max-width:550px)"]: {
width: "55%" width: "55%",
} },
} },
errorGridOpts: {
marginTop: "1%",
color: "#ff4646",
width: "100%",
fontSize: "13px",
},
})); }));
export default function SignUp() { export default function SignUp() {
const history = useHistory(); const history = useHistory();
...@@ -66,7 +72,7 @@ export default function SignUp() { ...@@ -66,7 +72,7 @@ export default function SignUp() {
password: "", password: "",
password_confirm: "", password_confirm: "",
nameError: false, nameError: false,
emailError: false emailError: false,
}); });
useEffect(() => { useEffect(() => {
!checkName() ? (values.nameError = true) : (values.nameError = false); !checkName() ? (values.nameError = true) : (values.nameError = false);
...@@ -75,7 +81,7 @@ export default function SignUp() { ...@@ -75,7 +81,7 @@ export default function SignUp() {
!checkEmail() ? (values.emailError = true) : (values.emailError = false); !checkEmail() ? (values.emailError = true) : (values.emailError = false);
}, [values.email]); }, [values.email]);
const handleChange = prop => event => { const handleChange = (prop) => (event) => {
setValues({ ...values, [prop]: event.target.value }); setValues({ ...values, [prop]: event.target.value });
}; };
function checkPassword() { function checkPassword() {
...@@ -101,6 +107,15 @@ export default function SignUp() { ...@@ -101,6 +107,15 @@ export default function SignUp() {
: false : false
: true; : true;
} }
function checkPasswordString() {
return values.password
? /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/.test(
values.password
)
: true;
}
function verifyValues() { function verifyValues() {
if ( if (
values.name && values.name &&
...@@ -133,15 +148,15 @@ export default function SignUp() { ...@@ -133,15 +148,15 @@ export default function SignUp() {
.post(`/user/signUp`, { .post(`/user/signUp`, {
email: values.email, email: values.email,
name: values.name, name: values.name,
hash: values.password hash: values.password,
}) })
.then(function(error) { .then(function (error) {
if (!error.response) { if (!error.response) {
let path = `signin`; let path = `signin`;
history.push(path); history.push(path);
} }
}) })
.catch(function(error) { .catch(function (error) {
if (error.response) { if (error.response) {
switch (error.response.data.error) { switch (error.response.data.error) {
case 'duplicate key value violates unique constraint "form_user_name_key"': case 'duplicate key value violates unique constraint "form_user_name_key"':
...@@ -169,19 +184,19 @@ export default function SignUp() { ...@@ -169,19 +184,19 @@ export default function SignUp() {
const theme = createMuiTheme({ const theme = createMuiTheme({
overrides: { overrides: {
root: { root: {
color: "white" color: "white",
}, },
MuiInput: { MuiInput: {
underline: { underline: {
"&:before": { "&:before": {
borderBottom: "1px solid #35c7fc" borderBottom: "1px solid #35c7fc",
}, },
"&:after": { "&:after": {
borderBottom: "1px solid #3f51b5" borderBottom: "1px solid #3f51b5",
} },
} },
} },
} },
}); });
return isLoged ? ( return isLoged ? (
<Redirect to="/signin" /> <Redirect to="/signin" />
...@@ -212,7 +227,18 @@ export default function SignUp() { ...@@ -212,7 +227,18 @@ export default function SignUp() {
/> />
</Grid> </Grid>
<Grid> <Grid>
<FormInput label="Senha" param="password" onUpdate={handleChange} /> <FormInput
label="Senha"
param="password"
onUpdate={handleChange}
error={!checkPasswordString()}
/>
{(!checkPasswordString() || !values.password) && (
<Grid className={classes.errorGridOpts}>
Sua senha deve conter entre 8 e X caracteres, uma letra
maiuscula, uma minuscula e um numero
</Grid>
)}
</Grid> </Grid>
<Grid> <Grid>
<FormInput <FormInput
......
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