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

View File

@ -1,11 +1,13 @@
import mongoose from "mongoose";
const userSchema = new mongoose.Schema({
title: {type: String, required: true },
firstName: { type: String, required: true },
middleName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
termsconditions:{type: String,},
tokens:[
{
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">
<!-- 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">
<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">
</head>

View File

@ -10,19 +10,21 @@ import Navbar from "./Navbar";
import "primeicons/primeicons.css";
const initialState = {
title: "None",
firstName: "",
middleName:"",
lastName: "",
email: "",
password: "",
confirmPassword: "",
termsconditions: "",
};
const Register = () => {
const [formValue, setFormValue] = useState(initialState);
const [isFormValid, setIsFormValid] = useState(false); // New state variable
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 navigate = useNavigate();
@ -35,10 +37,10 @@ const Register = () => {
useEffect(() => {
// Check if all fields are filled and all three checkboxes are selected
const isValid =
email && password && firstName && middleName && lastName && confirmPassword;
title !== "None" && email && password && firstName && middleName && lastName && confirmPassword && termsconditions;
setIsFormValid(isValid);
}, [email, password, firstName, middleName, lastName, confirmPassword]);
}, [title, email, password, firstName, middleName, lastName, confirmPassword, termsconditions]);
const handleSubmit = (e) => {
e.preventDefault();
@ -52,9 +54,28 @@ const Register = () => {
}
};
const capitalizeFirstLetter = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
const onInputChange = (e) => {
let { name, value } = e.target;
setFormValue({ ...formValue, [name]: value });
const { name, value, type, checked } = e.target;
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 (
@ -119,6 +140,31 @@ const Register = () => {
</div>
<form onSubmit={handleSubmit}>
<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="form-floating mb-3">
<input
@ -230,8 +276,11 @@ const Register = () => {
<input
className="form-check-input"
type="checkbox"
name="iAgree"
id="iAgree"
id="termsconditions"
value={termsconditions}
name="termsconditions"
checked={termsconditions}
onChange={onInputChange}
required
/>
<label
@ -248,6 +297,8 @@ const Register = () => {
</label>
</div>
</div>
<div className="col-12">
<div className="d-grid">
<button