[M] Reformat code.

This commit is contained in:
VergeDX
2021-01-23 22:24:12 +08:00
parent 59740a3b5d
commit e924334ae5
3 changed files with 17 additions and 20 deletions
-1
View File
@@ -9,4 +9,3 @@ rm -f ./build/libs/*
gradle bootJar gradle bootJar
scp ./build/libs/clock_api.jar $HOST:/app/depl/clock-api scp ./build/libs/clock_api.jar $HOST:/app/depl/clock-api
ssh $HOST "systemctl restart 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 org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.function.Function; 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 * https://www.baeldung.com/spring-rest-http-headers
* This method should be synchronized to avoid race condition. * This method should be synchronized to avoid race condition.
* Also, this method should not be private, or else cannot use userRepository. * Also, this method should not be private, or else cannot use userRepository.
* * <p>
* TODO: 2021/1/22 Need a better design! * TODO: 2021/1/22 Need a better design!
* Controller Return error code list as List<String>, or return uuid as String. * 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()); 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. * Check username & password.
* - User doesn't exist -> http 404 * - User doesn't exist -> http 404
* - Password doesn't match -> http 401 * - Password doesn't match -> http 401
* - All match -> Execute operation and return the resulting String. * - All match -> Execute operation and return the resulting String.
* *
* @param username Unique username * @param username Unique username
* @param password Password initial hash * @param password Password initial hash
* @param operation Callback on success * @param operation Callback on success
* @return Callback result or the error response * @return Callback result or the error response
*/ */
@@ -11,7 +11,6 @@ import javax.persistence.Id;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
@Data @Data
@Entity(name = "users") @Entity(name = "users")