Commit 256fb90 1 parent 6b23770 commit 256fb90 Copy full SHA for 256fb90
File tree 3 files changed +48
-10
lines changed
main/kotlin/baby/mumu/basis/kotlin/tools
test/java/baby/mumu/basis/tools
mumu-services/mumu-authentication/authentication-infrastructure/src/main/java/baby/mumu/authentication/infrastructure/account/gatewayimpl
3 files changed +48
-10
lines changed Original file line number Diff line number Diff line change 16
16
package baby.mumu.basis.kotlin.tools
17
17
18
18
import baby.mumu.basis.dto.BaseDataTransferObject
19
- import baby.mumu.basis.exception.MuMuException
20
- import baby.mumu.basis.response.ResponseCode
21
19
import org.apiguardian.api.API
22
20
import java.time.LocalDateTime
23
21
import java.time.OffsetDateTime
@@ -173,13 +171,12 @@ object TimeUtils {
173
171
*/
174
172
@API(status = API .Status .INTERNAL , since = " 2.7.0" )
175
173
@JvmStatic
176
- fun validateTimezone (timezone : String ) {
177
- if (timezone.isNotBlank()) {
178
- try {
179
- ZoneId .of(timezone)
180
- } catch (e: Exception ) {
181
- throw MuMuException (ResponseCode .TIME_ZONE_IS_NOT_AVAILABLE , e)
182
- }
174
+ fun isValidTimeZone (timezone : String ): Boolean {
175
+ try {
176
+ ZoneId .of(timezone)
177
+ return true
178
+ } catch (_: Exception ) {
179
+ return false
183
180
}
184
181
}
185
182
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2024-2025, the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package baby .mumu .basis .tools ;
17
+
18
+ import baby .mumu .basis .kotlin .tools .TimeUtils ;
19
+ import org .junit .jupiter .api .Assertions ;
20
+ import org .junit .jupiter .api .Test ;
21
+
22
+ /**
23
+ * 日期工具类测试
24
+ *
25
+ * @author <a href="mailto:[email protected] ">kaiyu.shan</a>
26
+ * @since 2.7.0
27
+ */
28
+ public class TimeUtilsTest {
29
+
30
+ @ Test
31
+ public void isValidTimeZone () {
32
+ boolean test = TimeUtils .isValidTimeZone ("test" );
33
+ Assertions .assertFalse (test );
34
+ boolean test1 = TimeUtils .isValidTimeZone ("Asia/Shanghai" );
35
+ Assertions .assertTrue (test1 );
36
+ }
37
+ }
Original file line number Diff line number Diff line change @@ -140,7 +140,11 @@ public void register(Account account) {
140
140
account .getUsername (), account .getEmail ())
141
141
&& !accountArchivedRepository .existsByIdOrUsernameOrEmail (account .getId (),
142
142
account .getUsername (), account .getEmail ())).ifPresentOrElse (accountPO -> {
143
- TimeUtils .validateTimezone (accountPO .getTimezone ());
143
+ // 验证时区是否为有效时区类型
144
+ if (StringUtils .isNotBlank (accountPO .getTimezone ()) && !TimeUtils .isValidTimeZone (
145
+ accountPO .getTimezone ())) {
146
+ throw new MuMuException (ResponseCode .TIME_ZONE_IS_NOT_AVAILABLE );
147
+ }
144
148
accountPO .setPassword (passwordEncoder .encode (accountPO .getPassword ()));
145
149
accountRepository .persist (accountPO );
146
150
account .setId (accountPO .getId ());
You can’t perform that action at this time.
0 commit comments