优化discord的检查流程
This commit is contained in:
parent
af312dc4d3
commit
66c737f0ea
@ -12,7 +12,7 @@ class DiscordController extends BaseController {
|
||||
let { code, state } = req.params
|
||||
if (code && state) {
|
||||
const stateArr = state.split('|')
|
||||
const address = stateArr[0]
|
||||
const address = stateArr[0].toLowerCase()
|
||||
const record = await AuthRecord.insertOrUpdate(
|
||||
{ address, platform: 7 },
|
||||
{ address, platform: 7, $inc: { version: 1 } },
|
||||
|
@ -21,6 +21,7 @@ class MainController extends BaseController {
|
||||
if (sign !== signCheck) {
|
||||
throw new ZError(11, 'invalid sign')
|
||||
}
|
||||
address = address.toLowerCase()
|
||||
let records = await AuthRecord.find({ address })
|
||||
let result: any = {
|
||||
discord: {},
|
||||
@ -47,11 +48,17 @@ class MainController extends BaseController {
|
||||
}
|
||||
}
|
||||
if (result.discord.id && !result.discord.verified) {
|
||||
setImmediate(async () => {
|
||||
try {
|
||||
let verified = await new DiscordSvr().checkUserRole(result.discord.id)
|
||||
if (verified) {
|
||||
distcordRecord.condition = 1
|
||||
result.discord.verified = 1
|
||||
logger.info('check role with verified: ' + verified)
|
||||
await AuthRecord.updateOne({ openId: result.discord.id, platform: 7 }, { $set: { condition: 1 } })
|
||||
}
|
||||
} catch (err) {
|
||||
logger.info('check role with err: ' + err.message || err)
|
||||
}
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class TwitterController extends BaseController {
|
||||
const { code, state } = req.params
|
||||
if (code && state) {
|
||||
const stateArr = state.split('|')
|
||||
const address = stateArr[0]
|
||||
const address = stateArr[0].toLowerCase()
|
||||
const record = await AuthRecord.insertOrUpdate(
|
||||
{ address, platform: 4 },
|
||||
{ address, platform: 4, $inc: { version: 1 } },
|
||||
|
@ -15,6 +15,7 @@ export enum PlatEnum {
|
||||
|
||||
@dbconn()
|
||||
@index({ address: 1, platform: 1 }, { unique: true })
|
||||
@index({ address: 1 }, { unique: false })
|
||||
@modelOptions({
|
||||
schemaOptions: { collection: 'auth_record', timestamps: true },
|
||||
options: { allowMixed: Severity.ALLOW },
|
||||
|
@ -15,6 +15,7 @@
|
||||
<body>
|
||||
<script>
|
||||
(function() {
|
||||
// window.opener.postMessage('I am ready');
|
||||
window.close();
|
||||
})();
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user