diff --git a/backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java b/backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java index ebefd0d5..1aec730c 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java @@ -1,34 +1,37 @@ package com.greenfoxacademy.backend.config; -import static org.springframework.security.config.Customizer.withDefaults; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; + /** * To give security permission to all endpoints. */ @Configuration -@EnableWebSecurity(debug = true) +@EnableWebSecurity +@EnableMethodSecurity(securedEnabled = true) public class SecurityConfig { /** * To give security permission to all endpoints. */ @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - // @formatter:off - http - .authorizeHttpRequests((authorize) -> authorize + public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { + return httpSecurity + .csrf(AbstractHttpConfigurer::disable) + .cors(AbstractHttpConfigurer::disable) + .authorizeHttpRequests(auth -> auth .anyRequest().permitAll() ) - .httpBasic(withDefaults()) - .formLogin(withDefaults()); - // @formatter:on - return http.build(); + .sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .build(); } -} \ No newline at end of file +} + diff --git a/backend/src/main/java/com/greenfoxacademy/backend/controller/UserController.java b/backend/src/main/java/com/greenfoxacademy/backend/controller/UserController.java index c376cfb2..5ad4e226 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/controller/UserController.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/controller/UserController.java @@ -4,6 +4,7 @@ import com.greenfoxacademy.backend.services.UserService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -13,9 +14,11 @@ */ @RestController @RequiredArgsConstructor +@CrossOrigin(origins = "http://localhost:8080") public class UserController { private final UserService userService; + @CrossOrigin(origins = "http://localhost:5173") @PostMapping("/register") public ResponseEntity registerUser(@RequestBody RegisterUserDto registerUserDto) { if (!userService.emailValidation(registerUserDto.getEmail())) { diff --git a/backend/src/main/java/com/greenfoxacademy/backend/services/UserServiceImpl.java b/backend/src/main/java/com/greenfoxacademy/backend/services/UserServiceImpl.java index e62e17ab..bcf1afcd 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/services/UserServiceImpl.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/services/UserServiceImpl.java @@ -18,7 +18,7 @@ public class UserServiceImpl implements UserService { private final PasswordEncoder passwordEncoder; private final UserRepository userRepository; - private ModelMapper modelMapper; + private final ModelMapper modelMapper; @Override public void register(RegisterUserDto userDto) { diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c7fc4d71..f1fb2380 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -6,6 +6,7 @@ import { RouterProvider, Link, } from "react-router-dom"; +import React, {useState} from "react"; function Login() { @@ -19,27 +20,77 @@ function Login() { - Main - Register + Main + Register ) } function Register() { + const [firstName, setFirstName] = useState(""); + const [lastName, setLastName] = useState(""); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + + const handleSubmit = (e: React.FormEvent)=> { + e.preventDefault() + console.log('firstName:',firstName); + console.log('lastName:',lastName); + console.log('email:',email); + console.log('password:',password); + fetch('http://localhost:8080/register', { + mode: 'cors', + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + firstName: firstName, + lastName: lastName, + email: email, + password: password, + }) + }) + } + + const saveFormData = (e: React.ChangeEvent) => { + const { name, value } = e.target; + switch (name) { + case 'firstName': + setFirstName(value); + break; + case 'lastName': + setLastName(value); + break; + case 'email': + setEmail(value); + break; + case 'password': + setPassword(value); + break; + default: + break; + } + } + + return ( <>

Register

-
+ + + + + - + - +
- Login - Main - + Login + Main ) } @@ -50,8 +101,8 @@ function Main() { <>

Home

Welcome to Gilmore Devs Pet Clinic!

- Login - Register + Login + Register ) } diff --git a/frontend/src/index.css b/frontend/src/index.css index 6119ad9a..0614196e 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -66,3 +66,41 @@ button:focus-visible { background-color: #f9f9f9; } } + +form { + display: flex; + flex-direction: column; + width: 300px; +} + +label, input, button { + margin-bottom: 10px; /* Adds space between form elements */ +} + +input, button { + padding: 8px; + border-radius: 4px; +} + +input { + border: 1px solid #ccc; +} + +button { + background-color: #007BFF; + color: white; + cursor: pointer; + border: none; + margin-top: 20px; +} + +button:hover { + background-color: #0056b3; +} + +.links { + display: block; /* Makes each link take up a full line */ + margin-bottom: 10px; /* Adds space between the links */ + color: #007BFF; /* Set the color of the links */ + text-decoration: none; /* Removes the underline from links */ +}