mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-09 12:17:29 +08:00
Merge pull request #226 from nagisa77/codex/update-username-validation-rules
Adjust username validation and signup UI
This commit is contained in:
@@ -158,8 +158,6 @@ export default {
|
|||||||
this.usernameError = ''
|
this.usernameError = ''
|
||||||
if (!this.username) {
|
if (!this.username) {
|
||||||
this.usernameError = '用户名不能为空'
|
this.usernameError = '用户名不能为空'
|
||||||
} else if (this.username.length < 6) {
|
|
||||||
this.usernameError = '用户名至少6位'
|
|
||||||
}
|
}
|
||||||
if (this.usernameError) {
|
if (this.usernameError) {
|
||||||
toast.error(this.usernameError)
|
toast.error(this.usernameError)
|
||||||
|
|||||||
@@ -33,11 +33,6 @@
|
|||||||
/>
|
/>
|
||||||
<div v-if="passwordError" class="error-message">{{ passwordError }}</div>
|
<div v-if="passwordError" class="error-message">{{ passwordError }}</div>
|
||||||
|
|
||||||
<BaseInput
|
|
||||||
icon="fas fa-user"
|
|
||||||
v-model="nickname"
|
|
||||||
placeholder="昵称 (可选)"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div v-if="!isWaitingForEmailSent" class="signup-page-button-primary" @click="sendVerification">
|
<div v-if="!isWaitingForEmailSent" class="signup-page-button-primary" @click="sendVerification">
|
||||||
<div class="signup-page-button-text">验证邮箱</div>
|
<div class="signup-page-button-text">验证邮箱</div>
|
||||||
@@ -113,7 +108,6 @@ export default {
|
|||||||
emailError: '',
|
emailError: '',
|
||||||
usernameError: '',
|
usernameError: '',
|
||||||
passwordError: '',
|
passwordError: '',
|
||||||
nickname: '',
|
|
||||||
code: '',
|
code: '',
|
||||||
isWaitingForEmailSent: false,
|
isWaitingForEmailSent: false,
|
||||||
isWaitingForEmailVerified: false
|
isWaitingForEmailVerified: false
|
||||||
@@ -149,8 +143,6 @@ export default {
|
|||||||
}
|
}
|
||||||
if (!this.username) {
|
if (!this.username) {
|
||||||
this.usernameError = '用户名不能为空'
|
this.usernameError = '用户名不能为空'
|
||||||
} else if (this.username.length < 6) {
|
|
||||||
this.usernameError = '用户名至少6位'
|
|
||||||
}
|
}
|
||||||
if (this.emailError || this.passwordError || this.usernameError) {
|
if (this.emailError || this.passwordError || this.usernameError) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ public class UsernameValidator {
|
|||||||
* @param username the username to validate
|
* @param username the username to validate
|
||||||
*/
|
*/
|
||||||
public void validate(String username) {
|
public void validate(String username) {
|
||||||
if (username == null || username.length() < 6) {
|
if (username == null || username.isEmpty()) {
|
||||||
throw new FieldException("username", "Username must be at least 6 characters long");
|
throw new FieldException("username", "Username cannot be empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.openisle.service;
|
||||||
|
|
||||||
|
import com.openisle.exception.FieldException;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class UsernameValidatorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void rejectsEmptyUsername() {
|
||||||
|
UsernameValidator validator = new UsernameValidator();
|
||||||
|
assertThrows(FieldException.class, () -> validator.validate(""));
|
||||||
|
assertThrows(FieldException.class, () -> validator.validate(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void allowsShortUsername() {
|
||||||
|
UsernameValidator validator = new UsernameValidator();
|
||||||
|
assertDoesNotThrow(() -> validator.validate("a"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user