Commit ae38e2e5 authored by wty's avatar wty

更新dev

parent 71c1b99d
...@@ -5,12 +5,31 @@ const configDev = require("../../config/dev.json"); ...@@ -5,12 +5,31 @@ const configDev = require("../../config/dev.json");
const request = require("request"); const request = require("request");
const SsoOauth2 = require('sso-oauth2').default const SsoOauth2 = require('sso-oauth2').default
const ssoOauth2 = new SsoOauth2(configDev.SSO) const ssoOauth2 = new SsoOauth2(configDev.SSO)
const query = require('../lib/query')
const ErrorCode = { const ErrorCode = {
USER_NOT_LOGIN: 70001 USER_NOT_LOGIN: 70001
} }
getMysql.then(Mysql => { getMysql.then(Mysql => {
router.get('/addAdmin', async (req, res) => {
const {uid} = req.query
const SQL = 'UPDATE `user` SET `admin` = 1 WHERE `uid` = ?'
try {
const addAdmin = await query(SQL, [uid])
res.send({
success: true,
result: addAdmin
})
} catch (e) {
console.error(e)
res.send({
success: false,
err: e
})
}
})
/* GET users listing. */ /* GET users listing. */
router.get('/getUser', async (req, res) => { router.get('/getUser', async (req, res) => {
const {sso_ticket} = req.cookies const {sso_ticket} = req.cookies
...@@ -36,7 +55,7 @@ getMysql.then(Mysql => { ...@@ -36,7 +55,7 @@ getMysql.then(Mysql => {
return return
} }
if (Array.isArray(result) && result.length > 0) { if (Array.isArray(result) && result.length > 0) {
console.info('用户查询:',result) console.info('用户查询:', result)
const admin = +result[0]['admin'] === 1 ? {admin: result[0]['admin']} : {} const admin = +result[0]['admin'] === 1 ? {admin: result[0]['admin']} : {}
res.send({ res.send({
success: true, success: true,
...@@ -44,9 +63,9 @@ getMysql.then(Mysql => { ...@@ -44,9 +63,9 @@ getMysql.then(Mysql => {
}) })
} else { } else {
const _SQL = 'INSERT INTO `user` (uid, uname, follow) VALUES (?,?,?)' const _SQL = 'INSERT INTO `user` (uid, uname, follow) VALUES (?,?,?)'
const _params = [ssoData['id'],ssoData['name'],JSON.stringify([])] const _params = [ssoData['id'], ssoData['name'], JSON.stringify([])]
Mysql.query(_SQL, _params, (_err, _result) => { Mysql.query(_SQL, _params, (_err, _result) => {
if (_err){ if (_err) {
console.error(_err) console.error(_err)
res.send({ res.send({
success: false, success: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment