2024-10-17 13:39:35 +08:00
|
|
|
import service from "apigo.cc/gojs/service"
|
|
|
|
import co from "apigo.cc/gojs/console"
|
|
|
|
|
|
|
|
let verifies = {
|
|
|
|
id: v => { return /^\d+$/.test(v) },
|
|
|
|
name: /^[a-zA-Z0-9_-\u4e00-\u9fa5\u3400-\u4db5\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\u1100-\u11FF\u3130-\u318F\uAC00-\uD7AF\uD82F\uD835\uD83C\uD83D\uD83E\uD83F\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872]+$/u,
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
service.register({ method: 'POST', path: '/login', verifies }, ({ args, session }) => {
|
|
|
|
session.set('id', args.id)
|
|
|
|
session.set('name', args.name)
|
|
|
|
session.setAuthLevel(1)
|
|
|
|
session.save()
|
|
|
|
return { code: 1 }
|
|
|
|
})
|
2024-10-18 17:54:37 +08:00
|
|
|
service.register({ method: 'GET', path: '/userInfo', authLevel: 1, limiters: ['ip1s'] }, ({ caller }) => {
|
|
|
|
return caller.get('user/userInfoX').object()
|
|
|
|
})
|
|
|
|
service.register({ method: 'GET', path: '/userInfoX', authLevel: 2 }, ({ session }) => {
|
2024-10-17 13:39:35 +08:00
|
|
|
return { code: 1, data: session.get('id', 'name') }
|
|
|
|
})
|
|
|
|
}
|