@@ -7,11 +7,31 @@ import { auth } from './middleware/auth'
7
7
import { clearConfigCache , getCacheConfig , getOriginConfig } from './storage/config'
8
8
import type { ChatOptions , Config , MailConfig , SiteConfig , UserInfo } from './storage/model'
9
9
import { Status } from './storage/model'
10
- import { clearChat , createChatRoom , createUser , deleteAllChatRooms , deleteChat , deleteChatRoom , existsChatRoom , getChat , getChatRooms , getChats , getUser , getUserById , insertChat , renameChatRoom , updateChat , updateConfig , updateUserInfo , verifyUser } from './storage/mongo'
10
+ import {
11
+ clearChat ,
12
+ createChatRoom ,
13
+ createUser ,
14
+ deleteAllChatRooms ,
15
+ deleteChat ,
16
+ deleteChatRoom ,
17
+ existsChatRoom ,
18
+ getChat ,
19
+ getChatRooms ,
20
+ getChats ,
21
+ getUser ,
22
+ getUserById ,
23
+ insertChat ,
24
+ renameChatRoom ,
25
+ updateChat ,
26
+ updateConfig ,
27
+ updateUserInfo ,
28
+ verifyUser ,
29
+ verifyUserAdmin ,
30
+ } from './storage/mongo'
11
31
import { limiter } from './middleware/limiter'
12
32
import { isNotEmptyString } from './utils/is'
13
- import { sendTestMail , sendVerifyMail } from './utils/mail'
14
- 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'
15
35
import { rootAuth } from './middleware/rootAuth'
16
36
17
37
const app = express ( )
@@ -321,6 +341,8 @@ router.post('/user-login', async (req, res) => {
321
341
|| user . password !== md5 ( password ) ) {
322
342
if ( user != null && user . status === Status . PreVerify )
323
343
throw new Error ( '请去邮箱中验证 | Please verify in the mailbox' )
344
+ if ( user != null && user . status === Status . AdminVerify )
345
+ throw new Error ( '请等待管理员开通 | Please wait for the admin to activate' )
324
346
throw new Error ( '用户不存在或密码错误 | User does not exist or incorrect password.' )
325
347
}
326
348
const config = await getCacheConfig ( )
@@ -360,8 +382,34 @@ router.post('/verify', async (req, res) => {
360
382
if ( ! token )
361
383
throw new Error ( 'Secret key is empty' )
362
384
const username = await checkUserVerify ( token )
385
+ const user = await getUser ( username )
386
+ if ( user != null && user . status === Status . Normal ) {
387
+ res . send ( { status : 'Fail' , message : '邮箱已存在 | The email exists' , data : null } )
388
+ return
389
+ }
363
390
await verifyUser ( username )
364
- res . send ( { status : 'Success' , message : '验证成功 | Verify successfully' , data : null } )
391
+ await sendVerifyMailAdmin ( username , await getUserVerifyUrlAdmin ( username ) )
392
+ res . send ( { status : 'Success' , message : '验证成功, 请等待管理员开通 | Verify successfully, Please wait for the admin to activate' , data : null } )
393
+ }
394
+ catch ( error ) {
395
+ res . send ( { status : 'Fail' , message : error . message , data : null } )
396
+ }
397
+ } )
398
+
399
+ router . post ( '/verifyadmin' , async ( req , res ) => {
400
+ try {
401
+ const { token } = req . body as { token : string }
402
+ if ( ! token )
403
+ throw new Error ( 'Secret key is empty' )
404
+ const username = await checkUserVerifyAdmin ( token )
405
+ const user = await getUser ( username )
406
+ if ( user != null && user . status === Status . Normal ) {
407
+ res . send ( { status : 'Fail' , message : '邮箱已存在 | The email exists' , data : null } )
408
+ return
409
+ }
410
+ await verifyUserAdmin ( username )
411
+ await sendNoticeMail ( username )
412
+ res . send ( { status : 'Success' , message : '开通成功 | Activate successfully' , data : null } )
365
413
}
366
414
catch ( error ) {
367
415
res . send ( { status : 'Fail' , message : error . message , data : null } )
0 commit comments