-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added validation to RegisterUserForm
Added LoginPage and RegisterPage Added MainLayout
- Loading branch information
OomsOoms
committed
Oct 3, 2024
1 parent
afb0b36
commit 549f9a7
Showing
8 changed files
with
140 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
client/src/features/authentication/validations/registerValidations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import validator from 'validator'; | ||
|
||
const usernameValidations = (username) => { | ||
if (!username) { | ||
return 'Username is required' | ||
} else if (!validator.isLength(username, { min: 3 })) { | ||
return 'Username is too short' | ||
} else if (!validator.isLength(username, { max: 20 })) { | ||
return 'Username is too long' | ||
} else if (!/^[a-zA-Z0-9_]*$/.test(username)) { | ||
return 'Please only use letters, numbers, underscores, hyphens or fullstops'; // dont have to specify the case of the letters because the input doesnt allow uppercase | ||
}else { | ||
return null; | ||
} | ||
} | ||
|
||
const emailValidations = (email) => { | ||
if (!email) { | ||
return 'Email is required'; | ||
} else if (!validator.isEmail(email)) { | ||
return 'Invalid email'; | ||
} | ||
} | ||
|
||
const passwordValidations = (password) => { | ||
if (!password) { | ||
return 'Password is required'; | ||
} else if (!validator.isLength(password, { min: 8 })) { | ||
return 'Password is too short'; | ||
} else if (!/[a-z]/.test(password)) { | ||
return 'Password must contain a lowercase letter'; | ||
} else if (!/[A-Z]/.test(password)) { | ||
return 'Password must contain a capital letter'; | ||
} else if (!/\d/.test(password)) { | ||
return 'Password must contain a number'; | ||
} | ||
} | ||
|
||
export { | ||
usernameValidations, | ||
emailValidations, | ||
passwordValidations | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const MainLayout = ({ children }) => { | ||
return ( | ||
<div className="main-layout"> | ||
<header>Header Content</header> | ||
<main>{children}</main> | ||
<footer>Footer Content</footer> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MainLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { LoginForm } from "../features/authentication"; | ||
|
||
import MainLayout from '../layouts/MainLayout.jsx'; | ||
|
||
const LoginPage = () => { | ||
return ( | ||
<MainLayout> | ||
<div className="login-page"> | ||
<h1>Login</h1> | ||
<LoginForm /> | ||
<p>Don't have an account? <a href="/register">Register</a></p> | ||
</div> | ||
</MainLayout> | ||
); | ||
}; | ||
|
||
export default LoginPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { RegisterForm } from "../features/authentication"; | ||
|
||
import MainLayout from '../layouts/MainLayout.jsx'; | ||
|
||
const LoginPage = () => { | ||
return ( | ||
<MainLayout> | ||
<div className="register-page"> | ||
<h1>Register</h1> | ||
<RegisterForm /> | ||
<p>Already have an account? <a href="/login">Login</a></p> | ||
</div> | ||
</MainLayout> | ||
); | ||
}; | ||
|
||
export default LoginPage; |