Skip to content

Commit

Permalink
Merge pull request #7 from eschremp/main
Browse files Browse the repository at this point in the history
React files to main
  • Loading branch information
wiegmank committed Mar 19, 2024
2 parents 96b0596 + dc2be16 commit 61e1fd5
Show file tree
Hide file tree
Showing 26 changed files with 4,805 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
HELP.md

.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
Expand Down
14 changes: 11 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework:spring-web:6.1.4'
implementation 'org.springframework.boot:spring-boot-starter-validation'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'mysql:mysql-connector-java:8.0.32'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-groovy-templates'
implementation 'org.springframework.boot:spring-boot-starter-security'
//implementation 'org.springframework.boot:spring-boot-starter-groovy-templates'
implementation 'org.springframework.security:spring-security-crypto'
//implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.okta.spring:okta-spring-boot-starter:3.0.6'
//implementation 'com.okta.spring:okta-spring-boot-starter:3.0.6'
compileOnly 'org.projectlombok:lombok'
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation group: 'com.h2database', name: 'h2', version: '2.2.222'
testImplementation 'org.springframework.security:spring-security-test'
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/unit3project/demo/AuthenticationFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.unit3project.demo;

import org.springframework.web.servlet.HandlerInterceptor;

public class AuthenticationFilter implements HandlerInterceptor {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.unit3project.demo.Controllers;

import com.unit3project.demo.Models.Data.UserRepository;
import com.unit3project.demo.Models.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Optional;

@Controller
public class AuthController {

@Autowired
private UserRepository userRepository;

private static final String userSessionKey = "user";

private static void setUserInSession(HttpSession session, User user) {
session.setAttribute(userSessionKey,user.getId());
}

public User getUserFromSession(HttpSession session) {
Integer userId = (Integer) session.getAttribute(userSessionKey);

if (userId == null) {
return null;
}

Optional<User> userOpt = userRepository.findById(userId);

if(userOpt.isEmpty()) {
return null;
}

return userOpt.get();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.unit3project.demo.Controllers.api;

import com.unit3project.demo.Controllers.AuthController;
import com.unit3project.demo.Models.DTO.LogInDTO;
import com.unit3project.demo.Models.Data.UserRepository;
import com.unit3project.demo.Models.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin//(origins = "http://localhost:5173", maxAge = 3600)
@RestController
@RequestMapping("/api")
public class AuthApiController extends AuthController {



@Autowired
UserRepository userRepository;

@GetMapping("/user")
//@ResponseStatus(value= HttpStatus.OK)
public List<User> printUser(@RequestParam("username") String username, @RequestParam("password") String password) {
List<User> testList = new ArrayList<>();
LogInDTO testForm = new LogInDTO();
testForm.setUsername(username);
testForm.setPassword(password);
User testUser = new User(testForm.getUsername(), testForm.getPassword());
User testUser2 = new User("karl","654321");
testUser.setName("Eric");
testUser2.setName("Karl");
testList.add(testUser);
testList.add(testUser2);
userRepository.save(testUser);
userRepository.save((testUser2));
return testList;
}

/*@PostMapping("/user")
public @ResponseBody String setUser() {
User testUser =new User("eric", "123456");
return testUser.toString();
}*/

}
31 changes: 31 additions & 0 deletions src/main/java/com/unit3project/demo/Models/DTO/LogInDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.unit3project.demo.Models.DTO;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public class LogInDTO {

@NotBlank(message = "Username is required")
@Size(min = 3, max = 30, message = "Username must be 3-30 character long")
private String username;

@NotBlank(message = "Username is required")
@Size(min = 6, max = 30, message = "Username must be 6-30 character long")
private String password;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/unit3project/demo/Models/DTO/RegisterDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.unit3project.demo.Models.DTO;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public class RegisterDTO extends LogInDTO {

@NotBlank(message = "Username is required")
@Size(min = 6, max = 30, message = "Username must be 6-30 character long")
private String verifyPassword;

public String getVerifyPassword() {
return verifyPassword;
}

public void setVerifyPassword(String verifyPassword) {
this.verifyPassword = verifyPassword;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
import org.springframework.stereotype.Repository;

@Repository
public interface userRepository extends CrudRepository <User, Integer> {
public interface UserRepository extends CrudRepository <User, Integer> {
User findByUserName(String userName);
}
5 changes: 3 additions & 2 deletions src/main/java/com/unit3project/demo/Models/Itinerary.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.unit3project.demo.Models;

import java.time.LocalDate;

public class Itinerary {//extends Park{
public class Itinerary extends AbstractEntity{
=======

//properties, getters/setters, how many itineraries can each user have?

private LocalDate startDate;
Expand Down
49 changes: 42 additions & 7 deletions src/main/java/com/unit3project/demo/Models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,39 @@

import jakarta.persistence.Entity;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;


@Entity
public class User extends AbstractEntity{

@NotBlank
private String userName;

@Email
private String email;
@Override
public int hashCode() {
return super.hashCode();
}
//@Email
//private String email;

@NotBlank
private String pwHash;

private String hashWord;
public User() {}

public User(String userName, String password) {
super();
this.userName = userName;
this.pwHash = encoder.encode(password);
}

private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

public boolean isMatchingPassword(String password) {
return encoder.matches(password, pwHash);
}

public String getUserName() {
return userName;
Expand All @@ -21,11 +44,23 @@ public void setUserName(String userName) {
this.userName = userName;
}

public String getEmail() {
return email;
@Override
public String toString() {
return "User{" +
"id'" + getId() + '\'' +
"userName='" + userName + '\'' +
'}';
}

public void setEmail(String email) {
this.email = email;
public void setPwHash(String pwHash) {
this.pwHash = pwHash;
}

//public String getEmail() {
// return email;
//}

//public void setEmail(String email) {
// this.email = email;
//}
}
20 changes: 20 additions & 0 deletions src/main/java/com/unit3project/demo/WebApplicationConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.unit3project.demo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*@Configuration
public class WebApplicationConfig implements WebMvcConfigurer {
@Bean
public AuthenticationFilter authenticationFilter() {
return new AuthenticationFilter();
}
@Override
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(authenticationFilter());
}
}*/
20 changes: 19 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
spring.application.name=Demo
spring.datasource.url=jdbc:mysql://localhost:3306/nationalparkapp
spring.datasource.username=nationalparkapp
spring.datasource.password=115650Ejs

# Specify the DBMS
spring.jpa.database = MYSQL

# Show or not log for each sql query
spring.jpa.show-sql = false

# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect

#change the root URI for the api
spring.data.rest.base-path=/api
21 changes: 21 additions & 0 deletions src/main/resources/static/js/national-park-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions src/main/resources/static/js/national-park-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions src/main/resources/static/js/national-park-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
13 changes: 13 additions & 0 deletions src/main/resources/static/js/national-park-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>

0 comments on commit 61e1fd5

Please sign in to comment.