minecraft server verify
This commit is contained in:
parent
6060e24ecf
commit
e57341dbd9
29
migrations/20171002162606_minecraft.js
Normal file
29
migrations/20171002162606_minecraft.js
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
exports.up = function (knex, Promise) {
|
||||
return Promise.all([
|
||||
knex.schema.createTable('mc_member', (table) => {
|
||||
table.increments('id').primary()
|
||||
table.integer('user_id').unsigned().notNullable()
|
||||
table.string('uuid', 36)
|
||||
table.string('name')
|
||||
|
||||
table.foreign('user_id').references('users.id').onDelete('CASCADE').onUpdate('CASCADE')
|
||||
table.timestamps()
|
||||
}),
|
||||
knex.schema.createTable('mc_verify', (table) => {
|
||||
table.increments('id').primary()
|
||||
table.integer('user_id').unsigned().notNullable()
|
||||
table.string('token')
|
||||
|
||||
table.foreign('user_id').references('users.id').onDelete('CASCADE').onUpdate('CASCADE')
|
||||
table.timestamps()
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
exports.down = function (knex, Promise) {
|
||||
return Promise.all([
|
||||
knex.schema.dropTable('mc_member'),
|
||||
knex.schema.dropTable('mc_verify')
|
||||
])
|
||||
}
|
44
server/api/minecraft.js
Normal file
44
server/api/minecraft.js
Normal file
@ -0,0 +1,44 @@
|
||||
import API from './index'
|
||||
import Model from './models'
|
||||
import crypto from 'crypto'
|
||||
|
||||
const mAPI = {
|
||||
getToken: async function (user) {
|
||||
user = await API.User.ensureObject(user)
|
||||
|
||||
let verified = await Model.MinecraftMember.query().where('user_id', user.id)
|
||||
if (verified.length) return {token: null, mcu: verified[0]}
|
||||
|
||||
let token = await Model.MinecraftToken.query().where('user_id', user.id)
|
||||
if (!token.length) {
|
||||
token = crypto.randomBytes(4).toString('hex')
|
||||
await Model.MinecraftToken.query().insert({
|
||||
token: token,
|
||||
user_id: user.id,
|
||||
created_at: new Date()
|
||||
})
|
||||
} else {
|
||||
token = token[0].token
|
||||
}
|
||||
|
||||
return {token: token, mcu: null}
|
||||
},
|
||||
verifyToken: async function (raw, name, uuid) {
|
||||
let token = await Model.MinecraftToken.query().where('token', raw)
|
||||
if (!token.length) return null
|
||||
token = token[0]
|
||||
|
||||
await Model.MinecraftMember.query().insert({
|
||||
uuid: uuid,
|
||||
name: name,
|
||||
user_id: token.user_id,
|
||||
created_at: new Date()
|
||||
})
|
||||
|
||||
await Model.MinecraftToken.query().delete().where('id', token.id)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = mAPI
|
@ -78,6 +78,18 @@ class Subscription extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
class MinecraftMember extends Model {
|
||||
static get tableName () {
|
||||
return 'mc_member'
|
||||
}
|
||||
}
|
||||
|
||||
class MinecraftToken extends Model {
|
||||
static get tableName () {
|
||||
return 'mc_verify'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
User: User,
|
||||
External: External,
|
||||
@ -91,5 +103,7 @@ module.exports = {
|
||||
Ban: Ban,
|
||||
News: News,
|
||||
Donation: Donation,
|
||||
Subscription: Subscription
|
||||
Subscription: Subscription,
|
||||
MinecraftMember: MinecraftMember,
|
||||
MinecraftToken: MinecraftToken
|
||||
}
|
||||
|
17
views/minecraft/index.pug
Normal file
17
views/minecraft/index.pug
Normal file
@ -0,0 +1,17 @@
|
||||
extends ../layout.pug
|
||||
block title
|
||||
|Icy Network - Minecraft Server
|
||||
|
||||
block body
|
||||
.wrapper
|
||||
.boxcont
|
||||
.box#totpcheck
|
||||
h1 Minecraft Server
|
||||
p Link your Icy Network account with your Minecraft account on our server
|
||||
if token
|
||||
p Run the following command on the Minecraft Server:
|
||||
code /verify #{token}
|
||||
else
|
||||
p You've already logged in as
|
||||
b= mcu.name
|
||||
|
Reference in New Issue
Block a user