Commit 498a7bbb authored by Mathias Engelbrecht Pilegård's avatar Mathias Engelbrecht Pilegård
Browse files

added valid password checking on signup

parent 847a7a0a
......@@ -18,6 +18,7 @@ const SignUp = () => {
const [lastname, setlastname] = useState('')
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
useEffect(() => {
const pageClickEvent = (e) => {
......@@ -61,17 +62,34 @@ const SignUp = () => {
const handleSignUpFormSubmit = (e) => {
e.preventDefault();
fetch(config.serviceAPI.createNewUserURL, loginRequestOptions)
.then((res) => {
if (!res.ok) {
window.alert("Error")
Promise.reject("")
return
}
if (res.ok) {
handleSignInFormSubmit(e)
}
})
if (!password || !confirmPassword) {
window.alert("A password field is blank")
return
}
if (!(confirmPassword.length >= 7)) {
window.alert("Password must consist of 8 characters or more")
return
}
if (!(password == confirmPassword)) {
window.alert("Passwords fo not match")
return
}
else {
fetch(config.serviceAPI.createNewUserURL, loginRequestOptions)
.then((res) => {
if (!res.ok) {
window.alert("Error")
Promise.reject("")
return
}
if (res.ok) {
handleSignInFormSubmit(e)
}
})
}
}
const handleSignInFormSubmit = (e) => {
......@@ -103,6 +121,10 @@ const SignUp = () => {
setPassword(e.target.value)
}
const handleConfirmPasswordChange = (e) => {
setConfirmPassword(e.target.value)
}
if (sessionToken) {
// Hide form while sessionToken is converted into id/access tokens
return null;
......@@ -165,6 +187,13 @@ const SignUp = () => {
value={password}
onChange={handlePasswordChange} />
</label>
<label>
Confirm Password:
<input
id="password" type="password"
value={confirmPassword}
onChange={handleConfirmPasswordChange} />
</label>
<label className="password-requirements">
Requirements: At least 8 characters, no parts of your username
</label>
......
Supports Markdown
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