保存中...
@@ -70,6 +74,7 @@ export default {
publishMode: 'DIRECT',
passwordStrength: 'LOW',
aiFormatLimit: 3,
+ registerMode: 'DIRECT',
isLoadingPage: false,
isSaving: false
}
@@ -122,6 +127,12 @@ export default {
{ id: -1, name: '无限' }
])
},
+ fetchRegisterModes() {
+ return Promise.resolve([
+ { id: 'DIRECT', name: '直接注册', icon: 'fas fa-user-check' },
+ { id: 'WHITELIST', name: '白名单邀请制', icon: 'fas fa-envelope' }
+ ])
+ },
async loadAdminConfig() {
try {
const token = getToken()
@@ -133,6 +144,7 @@ export default {
this.publishMode = data.publishMode
this.passwordStrength = data.passwordStrength
this.aiFormatLimit = data.aiFormatLimit
+ this.registerMode = data.registerMode
}
} catch (e) {
// ignore
@@ -183,7 +195,7 @@ export default {
await fetch(`${API_BASE_URL}/api/admin/config`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
- body: JSON.stringify({ publishMode: this.publishMode, passwordStrength: this.passwordStrength, aiFormatLimit: this.aiFormatLimit })
+ body: JSON.stringify({ publishMode: this.publishMode, passwordStrength: this.passwordStrength, aiFormatLimit: this.aiFormatLimit, registerMode: this.registerMode })
})
}
toast.success('保存成功')
diff --git a/open-isle-cli/src/views/SignupPageView.vue b/open-isle-cli/src/views/SignupPageView.vue
index 04f0c31b2..cee7c74b5 100644
--- a/open-isle-cli/src/views/SignupPageView.vue
+++ b/open-isle-cli/src/views/SignupPageView.vue
@@ -94,6 +94,7 @@ export default {
email: '',
username: '',
password: '',
+ registerMode: 'DIRECT',
emailError: '',
usernameError: '',
passwordError: '',
@@ -103,6 +104,19 @@ export default {
isWaitingForEmailVerified: false
}
},
+ async mounted() {
+ try {
+ const res = await fetch(`${API_BASE_URL}/api/config`)
+ if (res.ok) {
+ const data = await res.json()
+ this.registerMode = data.registerMode
+ }
+ } catch {}
+ if (this.$route.query.verify) {
+ this.emailStep = 1
+ this.username = sessionStorage.getItem('signup_username') || ''
+ }
+ },
methods: {
clearErrors() {
this.emailError = ''
@@ -126,6 +140,13 @@ export default {
if (this.emailError || this.passwordError || this.usernameError) {
return
}
+ if (this.registerMode === 'WHITELIST') {
+ sessionStorage.setItem('signup_username', this.username)
+ sessionStorage.setItem('signup_email', this.email)
+ sessionStorage.setItem('signup_password', this.password)
+ this.$router.push('/signup-reason')
+ return
+ }
try {
console.log('base url: ', API_BASE_URL)
this.isWaitingForEmailSent = true
@@ -135,7 +156,7 @@ export default {
body: JSON.stringify({
username: this.username,
email: this.email,
- password: this.password,
+ password: this.password
})
})
this.isWaitingForEmailSent = false
@@ -175,9 +196,13 @@ export default {
}
},
signupWithGoogle() {
- googleSignIn(() => {
- this.$router.push('/')
- })
+ if (this.registerMode === 'WHITELIST') {
+ this.$router.push('/signup-reason?google=1')
+ } else {
+ googleSignIn(() => {
+ this.$router.push('/')
+ })
+ }
}
}
}
diff --git a/open-isle-cli/src/views/SignupReasonPageView.vue b/open-isle-cli/src/views/SignupReasonPageView.vue
new file mode 100644
index 000000000..a78a74db5
--- /dev/null
+++ b/open-isle-cli/src/views/SignupReasonPageView.vue
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
diff --git a/src/main/java/com/openisle/controller/AuthController.java b/src/main/java/com/openisle/controller/AuthController.java
index cf9483456..3aba770c9 100644
--- a/src/main/java/com/openisle/controller/AuthController.java
+++ b/src/main/java/com/openisle/controller/AuthController.java
@@ -7,7 +7,10 @@ import com.openisle.service.UserService;
import com.openisle.service.CaptchaService;
import com.openisle.service.GoogleAuthService;
import com.openisle.service.RegisterModeService;
+import com.openisle.service.NotificationService;
import com.openisle.model.RegisterMode;
+import com.openisle.model.NotificationType;
+import com.openisle.repository.UserRepository;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
@@ -26,6 +29,8 @@ public class AuthController {
private final CaptchaService captchaService;
private final GoogleAuthService googleAuthService;
private final RegisterModeService registerModeService;
+ private final NotificationService notificationService;
+ private final UserRepository userRepository;
@Value("${app.captcha.enabled:false}")
private boolean captchaEnabled;
@@ -44,6 +49,12 @@ public class AuthController {
User user = userService.register(
req.getUsername(), req.getEmail(), req.getPassword(), req.getReason(), registerModeService.getRegisterMode());
emailService.sendEmail(user.getEmail(), "Verification Code", "Your verification code is " + user.getVerificationCode());
+ if (!user.isApproved()) {
+ for (User admin : userRepository.findByRole(com.openisle.model.Role.ADMIN)) {
+ notificationService.createNotification(admin, NotificationType.REGISTER_REQUEST, null, null,
+ null, user, null, user.getRegisterReason());
+ }
+ }
return ResponseEntity.ok(Map.of("message", "Verification code sent"));
}
diff --git a/src/main/java/com/openisle/controller/NotificationController.java b/src/main/java/com/openisle/controller/NotificationController.java
index a4e1db326..2e23fe452 100644
--- a/src/main/java/com/openisle/controller/NotificationController.java
+++ b/src/main/java/com/openisle/controller/NotificationController.java
@@ -64,6 +64,7 @@ public class NotificationController {
dto.setReactionType(n.getReactionType());
}
dto.setApproved(n.getApproved());
+ dto.setContent(n.getContent());
dto.setRead(n.isRead());
dto.setCreatedAt(n.getCreatedAt());
return dto;
@@ -107,6 +108,7 @@ public class NotificationController {
private CommentDto parentComment;
private AuthorDto fromUser;
private ReactionType reactionType;
+ private String content;
private Boolean approved;
private boolean read;
private LocalDateTime createdAt;