Skip to content

Commit

Permalink
Merge branch 'main' into SCRUM-44
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsbalazs committed Jul 5, 2024
2 parents 64ab062 + 6e1bfda commit 2edbe7f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
71 changes: 61 additions & 10 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RouterProvider,
Link,
} from "react-router-dom";
import React, {useState} from "react";

function Login() {

Expand All @@ -19,27 +20,77 @@ function Login() {
<input type='password'></input>
<button type='submit'>Login</button>
</form>
<Link to='/'>Main</Link>
<Link to='/register'>Register</Link>
<Link className={"links"} to='/'>Main</Link>
<Link className={"links"} to='/register'>Register</Link>

</>
)
}

function Register() {
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");

const handleSubmit = (e: React.FormEvent<HTMLFormElement>)=> {
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<HTMLInputElement>) => {
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 (
<>
<h1>Register</h1>
<form>
<form onSubmit={handleSubmit}>
<label>First Name:</label>
<input type='text' name={"firstName"} value={firstName} onChange={saveFormData}></input>
<label>Last Name:</label>
<input type='text' name={"lastName"} value={lastName} onChange={saveFormData}></input>
<label>Email:</label>
<input type='email'></input>
<input type='email' name={"email"} value={email} onChange={saveFormData}></input>
<label>Password:</label>
<input type='password'></input>
<input type='password' name={"password"} value={password} onChange={saveFormData}></input>
<button type='submit'>Register</button>
</form>
<Link to='/login'>Login</Link>
<Link to='/'>Main</Link>

<Link className={"links"} to='/login'>Login</Link>
<Link className={"links"} to='/'>Main</Link>
</>
)
}
Expand All @@ -50,8 +101,8 @@ function Main() {
<>
<h1>Home</h1>
<p>Welcome to Gilmore Devs Pet Clinic!</p>
<Link to='/login'>Login</Link>
<Link to='/register'>Register</Link>
<Link className={"links"} to='/login'>Login</Link>
<Link className={"links"} to='/register'>Register</Link>
</>
)
}
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}

0 comments on commit 2edbe7f

Please sign in to comment.