[M] Reformat code.
This commit is contained in:
@@ -9,4 +9,3 @@ rm -f ./build/libs/*
|
||||
gradle bootJar
|
||||
scp ./build/libs/clock_api.jar $HOST:/app/depl/clock-api
|
||||
ssh $HOST "systemctl restart clock-api"
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -30,12 +29,25 @@ public class UserController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a user to the database.
|
||||
* Create salted hash for user's password
|
||||
* Format: "$username + $password".toLowerMd5();
|
||||
*
|
||||
* @param username Unique username used as a salt
|
||||
* @param password Password initial hash
|
||||
* @return Salted hash
|
||||
*/
|
||||
private static String userToSaltedMd5(String username, String password) {
|
||||
String beforeMd5 = String.format("%s + %s", username, password);
|
||||
return DigestUtils.md5DigestAsHex(beforeMd5.getBytes()).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a user to the database.
|
||||
* <p>
|
||||
* https://www.baeldung.com/spring-rest-http-headers
|
||||
* This method should be synchronized to avoid race condition.
|
||||
* Also, this method should not be private, or else cannot use userRepository.
|
||||
*
|
||||
* <p>
|
||||
* TODO: 2021/1/22 Need a better design!
|
||||
* Controller Return error code list as List<String>, or return uuid as String.
|
||||
*
|
||||
@@ -68,27 +80,14 @@ public class UserController {
|
||||
return ResponseEntity.ok(user.getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create salted hash for user's password
|
||||
* Format: "$username + $password".toLowerMd5();
|
||||
*
|
||||
* @param username Unique username used as a salt
|
||||
* @param password Password initial hash
|
||||
* @return Salted hash
|
||||
*/
|
||||
private static String userToSaltedMd5(String username, String password) {
|
||||
String beforeMd5 = String.format("%s + %s", username, password);
|
||||
return DigestUtils.md5DigestAsHex(beforeMd5.getBytes()).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check username & password.
|
||||
* - User doesn't exist -> http 404
|
||||
* - Password doesn't match -> http 401
|
||||
* - All match -> Execute operation and return the resulting String.
|
||||
*
|
||||
* @param username Unique username
|
||||
* @param password Password initial hash
|
||||
* @param username Unique username
|
||||
* @param password Password initial hash
|
||||
* @param operation Callback on success
|
||||
* @return Callback result or the error response
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,6 @@ import javax.persistence.Id;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Entity(name = "users")
|
||||
|
||||
Reference in New Issue
Block a user