mirror of
https://github.com/Leahnaya/UBFunkeysServer.git
synced 2026-09-07 00:05:12 -05:00
Created Service/Repository/Entity for Users and Cribs
- In preparation for the save/load crib on the Galaxy Server - In preparation for the register user on the ArkOne Server - Also added a PasswordEncoder for encrypting passwords when saved to the DB
This commit is contained in:
@@ -18,6 +18,9 @@ public class ArkOneController implements TcpHandler {
|
||||
String xmlData = new String(data);
|
||||
System.out.println("[ArkOne] New Request: " + xmlData);
|
||||
|
||||
//TODO: USE THAT FOR PASSWORD ENCRYPTION FOR STORING IN THE DB
|
||||
//TODO: SEE THIS ARTICLE FOR ENCODING: https://www.baeldung.com/spring-security-registration-password-encoding-bcrypt
|
||||
|
||||
try {
|
||||
connection.send(xmlData.toUpperCase().getBytes());
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -77,6 +77,7 @@ public class GalaxyServer {
|
||||
} catch (Exception e) {
|
||||
// File doesn't exist error caught here
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
// Set the error code
|
||||
errorCode = HttpServletResponse.SC_NOT_FOUND;
|
||||
@@ -161,7 +162,7 @@ public class GalaxyServer {
|
||||
// Send successful
|
||||
response = "<postcard result=\"0\" reason=\"Postcard Sent!\" cost=\"5\" />";
|
||||
} else {
|
||||
response = "<postcard result=\"1\" reason=\"Unable to send postcard at this time!\" cost=\"0\" />";
|
||||
response = "<postcard result=\"1\" reason=\"Unable to send postcard at this time!\" cost=\"5\" />";
|
||||
}
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.icedberries.UBFunkeysServer;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = {"com.icedberries", "javagrinko.spring"})
|
||||
public class UBFunkeysServerApplication {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.icedberries.UBFunkeysServer.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@Configuration
|
||||
public class Password {
|
||||
|
||||
private static final Integer STRENGTH = 15;
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder encoder() {
|
||||
return new BCryptPasswordEncoder(STRENGTH, new SecureRandom());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.icedberries.UBFunkeysServer.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "Cribs")
|
||||
public class Crib {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String cribName;
|
||||
|
||||
private String username;
|
||||
|
||||
private String profileData;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.icedberries.UBFunkeysServer.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "Users")
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Integer UUID;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private String securityQuestion;
|
||||
|
||||
private String securityAnswer;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.icedberries.UBFunkeysServer.repository;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Crib;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CribRepository extends CrudRepository<Crib, Integer> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.icedberries.UBFunkeysServer.repository;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.User;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||
|
||||
Boolean existsByUUID(Integer uuid);
|
||||
|
||||
@Query("select user from User user where user.UUID = :uuid")
|
||||
Optional<User> findByUUID(@Param("uuid") Integer uuid);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.icedberries.UBFunkeysServer.service;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Crib;
|
||||
|
||||
public interface CribService {
|
||||
|
||||
Integer count();
|
||||
|
||||
void save(Crib crib);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.icedberries.UBFunkeysServer.service;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.User;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
Optional<User> findByUUID(Integer uuid);
|
||||
|
||||
Boolean existsByUUID(Integer uuid);
|
||||
|
||||
void save(User user);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.icedberries.UBFunkeysServer.service.impl;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Crib;
|
||||
import com.icedberries.UBFunkeysServer.repository.CribRepository;
|
||||
import com.icedberries.UBFunkeysServer.service.CribService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CribServiceImpl implements CribService {
|
||||
|
||||
public final CribRepository cribRepository;
|
||||
|
||||
@Override
|
||||
public Integer count() {
|
||||
return Math.toIntExact(cribRepository.count());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Crib crib) {
|
||||
cribRepository.save(crib);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.icedberries.UBFunkeysServer.service.impl;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.User;
|
||||
import com.icedberries.UBFunkeysServer.repository.UserRepository;
|
||||
import com.icedberries.UBFunkeysServer.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
public final UserRepository userRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<User> findByUUID(Integer uuid) {
|
||||
return userRepository.findByUUID(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean existsByUUID(Integer uuid) {
|
||||
return userRepository.existsByUUID(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(User user) {
|
||||
userRepository.save(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user