This commit is contained in:
omkieit 2024-09-07 13:18:55 +05:30
parent 690f682f12
commit 18d967f528
5 changed files with 80 additions and 24 deletions

View File

@ -8,7 +8,7 @@ const secret = process.env.SECRET_KEY;
// This is signup // This is signup
export const signup = async (req, res) => { export const signup = async (req, res) => {
const { email, password, firstName, middleName, lastName } = req.body; const { title, email, password, firstName, middleName, lastName, termsconditions } = req.body;
try { try {
// Check if user already exists // Check if user already exists
@ -22,11 +22,13 @@ export const signup = async (req, res) => {
// Create new user // Create new user
const result = await UserModal.create({ const result = await UserModal.create({
title,
email, email,
password: hashedPassword, password: hashedPassword,
firstName, firstName,
middleName, middleName,
lastName, lastName,
termsconditions,
}); });
// Generate JWT (if needed) // Generate JWT (if needed)
@ -49,6 +51,7 @@ export const signup = async (req, res) => {
} }
}; };
// This is signIn
export const signin = async (req, res) => { export const signin = async (req, res) => {
const { email, password } = req.body; const { email, password } = req.body;

View File

@ -1,11 +1,13 @@
import mongoose from "mongoose"; import mongoose from "mongoose";
const userSchema = new mongoose.Schema({ const userSchema = new mongoose.Schema({
title: {type: String, required: true },
firstName: { type: String, required: true }, firstName: { type: String, required: true },
middleName: { type: String, required: true }, middleName: { type: String, required: true },
lastName: { type: String, required: true }, lastName: { type: String, required: true },
email: { type: String, required: true, unique: true }, email: { type: String, required: true, unique: true },
password: { type: String, required: true }, password: { type: String, required: true },
termsconditions:{type: String,},
tokens:[ tokens:[
{ {
token:{ token:{

File diff suppressed because one or more lines are too long

View File

@ -27,7 +27,7 @@
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"> <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<!-- fonts --> <!-- fonts -->
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;800&family=Sen:wght@400;700;800&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;800&family=Sen:wght@400;700;800&display=swap" rel="stylesheet">
<script type="module" crossorigin src="/assets/index-BSMgqDC4.js"></script> <script type="module" crossorigin src="/assets/index-BVbzGpWG.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CyAHZLBw.css"> <link rel="stylesheet" crossorigin href="/assets/index-CyAHZLBw.css">
</head> </head>

View File

@ -10,19 +10,21 @@ import Navbar from "./Navbar";
import "primeicons/primeicons.css"; import "primeicons/primeicons.css";
const initialState = { const initialState = {
title: "None",
firstName: "", firstName: "",
middleName:"", middleName:"",
lastName: "", lastName: "",
email: "", email: "",
password: "", password: "",
confirmPassword: "", confirmPassword: "",
termsconditions: "",
}; };
const Register = () => { const Register = () => {
const [formValue, setFormValue] = useState(initialState); const [formValue, setFormValue] = useState(initialState);
const [isFormValid, setIsFormValid] = useState(false); // New state variable const [isFormValid, setIsFormValid] = useState(false); // New state variable
const { loading, error } = useSelector((state) => ({ ...state.auth })); const { loading, error } = useSelector((state) => ({ ...state.auth }));
const { email, password, firstName, middleName, lastName, confirmPassword } = formValue; const { title, email, password, firstName, middleName, lastName, confirmPassword,termsconditions } = formValue;
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
@ -35,10 +37,10 @@ const Register = () => {
useEffect(() => { useEffect(() => {
// Check if all fields are filled and all three checkboxes are selected // Check if all fields are filled and all three checkboxes are selected
const isValid = const isValid =
email && password && firstName && middleName && lastName && confirmPassword; title !== "None" && email && password && firstName && middleName && lastName && confirmPassword && termsconditions;
setIsFormValid(isValid); setIsFormValid(isValid);
}, [email, password, firstName, middleName, lastName, confirmPassword]); }, [title, email, password, firstName, middleName, lastName, confirmPassword, termsconditions]);
const handleSubmit = (e) => { const handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
@ -52,9 +54,28 @@ const Register = () => {
} }
}; };
const capitalizeFirstLetter = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
const onInputChange = (e) => { const onInputChange = (e) => {
let { name, value } = e.target; const { name, value, type, checked } = e.target;
setFormValue({ ...formValue, [name]: value });
if (type === "checkbox") {
// Set to true if checked, false if unchecked
setFormValue((prevData) => ({
...prevData,
[name]: checked,
}));
} else {
setFormValue((prevData) => ({
...prevData,
[name]:
name === "email" || name === "password" || name === "confirmPassword"
? value
: capitalizeFirstLetter(value),
}));
}
}; };
return ( return (
@ -119,6 +140,31 @@ const Register = () => {
</div> </div>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<div className="row gy-3 overflow-hidden"> <div className="row gy-3 overflow-hidden">
<div className="col-12">
<select
className="form-floating mb-3 form-control"
aria-label="Default select example"
name="title"
value={title}
onChange={onInputChange}
>
<option value="None">Please Select Title</option>
<option value="Dr">Dr</option>
<option value="Prof">Prof</option>
<option value="Mr">Mr</option>
<option value="Miss">Miss</option>
</select>
<label htmlFor="firstName" className="form-label">
{title === "Select" ? (
<span>You selected {title}</span>
) : (
`You selected ${title}`
)}
</label>
</div>
<div className="col-12"> <div className="col-12">
<div className="form-floating mb-3"> <div className="form-floating mb-3">
<input <input
@ -230,8 +276,11 @@ const Register = () => {
<input <input
className="form-check-input" className="form-check-input"
type="checkbox" type="checkbox"
name="iAgree" id="termsconditions"
id="iAgree" value={termsconditions}
name="termsconditions"
checked={termsconditions}
onChange={onInputChange}
required required
/> />
<label <label
@ -248,6 +297,8 @@ const Register = () => {
</label> </label>
</div> </div>
</div> </div>
<div className="col-12"> <div className="col-12">
<div className="d-grid"> <div className="d-grid">
<button <button