Merge branch 'main' into codex/add-email-recovery-for-missing-username

This commit is contained in:
Tim
2025-07-15 14:46:22 +08:00
committed by GitHub
4 changed files with 20 additions and 10 deletions

View File

@@ -70,8 +70,12 @@ export default {
toast.success('登录成功') toast.success('登录成功')
this.$router.push('/') this.$router.push('/')
} else if (data.reason_code === 'NOT_VERIFIED') { } else if (data.reason_code === 'NOT_VERIFIED') {
toast.info('当前邮箱未验证,请先重新填写注册页面并验证') sessionStorage.setItem('signup_username', data.username)
this.$router.push('/signup') toast.info('当前邮箱未验证,已经为您重新发送验证码')
this.$router.push({ path: '/signup', query: { verify: 1, u: this.username } })
} else if (data.reason_code === 'NOT_APPROVED') {
toast.info('您的注册正在审批中, 请留意邮件')
this.$router.push('/')
} else { } else {
toast.error(data.error || '登录失败') toast.error(data.error || '登录失败')
} }

View File

@@ -105,6 +105,7 @@ export default {
} }
}, },
async mounted() { async mounted() {
this.username = this.$route.query.u || ''
try { try {
const res = await fetch(`${API_BASE_URL}/api/config`) const res = await fetch(`${API_BASE_URL}/api/config`)
if (res.ok) { if (res.ok) {
@@ -114,7 +115,6 @@ export default {
} catch {/* ignore */} } catch {/* ignore */}
if (this.$route.query.verify) { if (this.$route.query.verify) {
this.emailStep = 1 this.emailStep = 1
this.username = sessionStorage.getItem('signup_username') || ''
} }
}, },
methods: { methods: {
@@ -181,7 +181,10 @@ export default {
const res = await fetch(`${API_BASE_URL}/api/auth/verify`, { const res = await fetch(`${API_BASE_URL}/api/auth/verify`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: this.username, code: this.code }) body: JSON.stringify({
code: this.code,
username: this.username
})
}) })
this.isWaitingForEmailVerified = false this.isWaitingForEmailVerified = false
const data = await res.json() const data = await res.json()
@@ -205,7 +208,7 @@ export default {
googleSignIn(() => { googleSignIn(() => {
this.$router.push('/') this.$router.push('/')
}, () => { }, () => {
this.$router.push('/signup-reason') this.$router.push('/signup-reason?google=1')
}) })
} }
} }

View File

@@ -77,7 +77,7 @@ export default {
const data = await res.json() const data = await res.json()
if (res.ok) { if (res.ok) {
toast.success('验证码已发送,请查收邮箱') toast.success('验证码已发送,请查收邮箱')
this.$router.push('/signup?verify=1') this.$router.push({ path: '/signup', query: { verify: 1, u: sessionStorage.getItem('signup_username') } })
} else { } else {
toast.error(data.error || '发送失败') toast.error(data.error || '发送失败')
} }

View File

@@ -68,9 +68,9 @@ public class AuthController {
if (captchaEnabled && loginCaptchaEnabled && !captchaService.verify(req.getCaptcha())) { if (captchaEnabled && loginCaptchaEnabled && !captchaService.verify(req.getCaptcha())) {
return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha")); return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha"));
} }
Optional<User> userOpt = userService.findByUsername(req.getUsernameOrEmail()); Optional<User> userOpt = userService.findByUsername(req.getUsername());
if (userOpt.isEmpty()) { if (userOpt.isEmpty()) {
userOpt = userService.findByEmail(req.getUsernameOrEmail()); userOpt = userService.findByEmail(req.getUsername());
} }
if (userOpt.isEmpty() || !userService.matchesPassword(userOpt.get(), req.getPassword())) { if (userOpt.isEmpty() || !userService.matchesPassword(userOpt.get(), req.getPassword())) {
return ResponseEntity.badRequest().body(Map.of( return ResponseEntity.badRequest().body(Map.of(
@@ -79,9 +79,12 @@ public class AuthController {
} }
User user = userOpt.get(); User user = userOpt.get();
if (!user.isVerified()) { if (!user.isVerified()) {
user = userService.register(user.getUsername(), user.getEmail(), user.getPassword(), user.getRegisterReason(), registerModeService.getRegisterMode());
emailService.sendEmail(user.getEmail(), "Verification Code", "Your verification code is " + user.getVerificationCode());
return ResponseEntity.badRequest().body(Map.of( return ResponseEntity.badRequest().body(Map.of(
"error", "User not verified", "error", "User not verified",
"reason_code", "NOT_VERIFIED")); "reason_code", "NOT_VERIFIED",
"user_name", user.getUsername()));
} }
if (RegisterMode.WHITELIST.equals(registerModeService.getRegisterMode()) && !user.isApproved()) { if (RegisterMode.WHITELIST.equals(registerModeService.getRegisterMode()) && !user.isApproved()) {
return ResponseEntity.badRequest().body(Map.of( return ResponseEntity.badRequest().body(Map.of(
@@ -136,7 +139,7 @@ public class AuthController {
@Data @Data
private static class LoginRequest { private static class LoginRequest {
private String usernameOrEmail; private String username;
private String password; private String password;
private String captcha; private String captcha;
} }