@@ -8,11 +8,30 @@ import { auth } from './middleware/auth'
8
8
import { clearConfigCache , getCacheConfig , getOriginConfig } from './storage/config'
9
9
import type { ChatOptions , Config , MailConfig , SiteConfig , UserInfo } from './storage/model'
10
10
import { Status } from './storage/model'
11
- import { clearChat , createChatRoom , createUser , deleteAllChatRooms , deleteChat , deleteChatRoom , existsChatRoom , getChat , getChatRooms , getChats , getUser , getUserById , insertChat , renameChatRoom , updateChat , updateConfig , updateUserInfo , verifyUser } from './storage/mongo'
11
+ import {
12
+ clearChat ,
13
+ createChatRoom ,
14
+ createUser ,
15
+ deleteAllChatRooms ,
16
+ deleteChat ,
17
+ deleteChatRoom ,
18
+ existsChatRoom ,
19
+ getChat ,
20
+ getChatRooms ,
21
+ getChats ,
22
+ getUser ,
23
+ getUserById ,
24
+ insertChat ,
25
+ renameChatRoom ,
26
+ updateChat ,
27
+ updateConfig ,
28
+ updateUserInfo ,
29
+ verifyUser ,
30
+ } from './storage/mongo'
12
31
import { limiter } from './middleware/limiter'
13
32
import { isEmail , isNotEmptyString } from './utils/is'
14
- import { sendTestMail , sendVerifyMail } from './utils/mail'
15
- import { checkUserVerify , getUserVerifyUrl , md5 } from './utils/security'
33
+ import { sendNoticeMail , sendTestMail , sendVerifyMail , sendVerifyMailAdmin } from './utils/mail'
34
+ import { checkUserVerify , checkUserVerifyAdmin , getUserVerifyUrl , getUserVerifyUrlAdmin , md5 } from './utils/security'
16
35
import { rootAuth } from './middleware/rootAuth'
17
36
18
37
dotenv . config ( )
@@ -328,6 +347,8 @@ router.post('/user-login', async (req, res) => {
328
347
|| user . password !== md5 ( password ) ) {
329
348
if ( user != null && user . status === Status . PreVerify )
330
349
throw new Error ( '请去邮箱中验证 | Please verify in the mailbox' )
350
+ if ( user != null && user . status === Status . AdminVerify )
351
+ throw new Error ( '请等待管理员开通 | Please wait for the admin to activate' )
331
352
throw new Error ( '用户不存在或密码错误 | User does not exist or incorrect password.' )
332
353
}
333
354
const config = await getCacheConfig ( )
@@ -367,8 +388,42 @@ router.post('/verify', async (req, res) => {
367
388
if ( ! token )
368
389
throw new Error ( 'Secret key is empty' )
369
390
const username = await checkUserVerify ( token )
370
- await verifyUser ( username )
371
- res . send ( { status : 'Success' , message : '验证成功 | Verify successfully' , data : null } )
391
+ const user = await getUser ( username )
392
+ if ( user != null && user . status === Status . Normal ) {
393
+ res . send ( { status : 'Fail' , message : '邮箱已存在 | The email exists' , data : null } )
394
+ return
395
+ }
396
+ const config = await getCacheConfig ( )
397
+ let message = '验证成功 | Verify successfully'
398
+ if ( config . siteConfig . registerReview ) {
399
+ await verifyUser ( username , Status . AdminVerify )
400
+ await sendVerifyMailAdmin ( process . env . ROOT_USER , username , await getUserVerifyUrlAdmin ( username ) )
401
+ message = '验证成功, 请等待管理员开通 | Verify successfully, Please wait for the admin to activate'
402
+ }
403
+ else {
404
+ await verifyUser ( username , Status . Normal )
405
+ }
406
+ res . send ( { status : 'Success' , message, data : null } )
407
+ }
408
+ catch ( error ) {
409
+ res . send ( { status : 'Fail' , message : error . message , data : null } )
410
+ }
411
+ } )
412
+
413
+ router . post ( '/verifyadmin' , async ( req , res ) => {
414
+ try {
415
+ const { token } = req . body as { token : string }
416
+ if ( ! token )
417
+ throw new Error ( 'Secret key is empty' )
418
+ const username = await checkUserVerifyAdmin ( token )
419
+ const user = await getUser ( username )
420
+ if ( user != null && user . status === Status . Normal ) {
421
+ res . send ( { status : 'Fail' , message : '邮箱已开通 | The email has been opened.' , data : null } )
422
+ return
423
+ }
424
+ await verifyUser ( username , Status . Normal )
425
+ await sendNoticeMail ( username )
426
+ res . send ( { status : 'Success' , message : '开通成功 | Activate successfully' , data : null } )
372
427
}
373
428
catch ( error ) {
374
429
res . send ( { status : 'Fail' , message : error . message , data : null } )
0 commit comments