diff --git a/api/app/lib/controllers/auth/index.js b/api/app/lib/controllers/auth/index.js index 1861396..eb7d901 100644 --- a/api/app/lib/controllers/auth/index.js +++ b/api/app/lib/controllers/auth/index.js @@ -19,31 +19,10 @@ async function login (ctx, next) { attributes: { exclude: ['password'] }, where: { username: params.username, - password: password, - del: false, - }, - }); - } else if (params.phone && params.code) { - const record = await models.PhoneValidateCode.findOne({ - where: { - phone: phone, - code: code - } - }); - if (!record) { - throw '验证码错误' - } else if (record.expired < new Date()) { - throw '验证码已失效' - } - userRes = await models.User.findOne({ - attributes: { exclude: ['password'] }, - where: { - phone: phone, - del: false, + password: password }, }); } - if (userRes) { if (userRes.forbidden) { throw '用户已禁用' @@ -79,56 +58,6 @@ async function login (ctx, next) { } } -async function varfiyCode (ctx) { - try { - const { models } = ctx.fs.dc; - const { pushBySms, pushByEmail } = ctx.app.fs.utils - const { phone, sig, r } = ctx.request.body - - // 伪造的请求可能由相同的sig参数组成 - const checkSigUsed = await models.PhoneValidateCode.findOne({ - where: { sig: sig } - }); - if (checkSigUsed) { - throw '参数错误!' - } - - // 验证sig正确性 - const checkSig = Hex.stringify(SHA1(phone + r)); - if (!r || !sig || sig != checkSig) { - throw '参数错误!' - } - - let varifyCode = '' - for (let i = 0; i < 6; i++) { - varifyCode += Math.floor(Math.random() * 10) - } - - // await pushBySms({ - // phone: phone, - // templateCode: 'SMS_248250074', - // templateParam: { - // code: varifyCode - // }, - // }) - - await models.PhoneValidateCode.create({ - phone: phone, - code: varifyCode, - sig: sig, - expired: moment().add(10, 'minutes').format('YYYY-MM-DD HH:mm:ss') - }) - - ctx.status = 204; - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : '获取验证码失败' - } - } -} - async function logout (ctx) { try { const models = ctx.fs.dc.models; @@ -152,6 +81,5 @@ async function logout (ctx) { module.exports = { login, - varfiyCode, logout, }; \ No newline at end of file diff --git a/api/app/lib/models/user.js b/api/app/lib/models/user.js index b209b78..0ab5935 100644 --- a/api/app/lib/models/user.js +++ b/api/app/lib/models/user.js @@ -31,54 +31,9 @@ module.exports = dc => { primaryKey: false, field: "password", autoIncrement: false - }, - displayName: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: null, - primaryKey: false, - field: "display_name", - autoIncrement: false - }, - del: { - type: DataTypes.BOOLEAN, - allowNull: true, - defaultValue: null, - comment: null, - primaryKey: false, - field: "del", - autoIncrement: false - }, - rank: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: null, - primaryKey: false, - field: "rank", - autoIncrement: false - }, - phone: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: null, - primaryKey: false, - field: "phone", - autoIncrement: false - }, - forbidden: { - type: DataTypes.BOOLEAN, - allowNull: false, - defaultValue: null, - comment: null, - primaryKey: false, - field: "forbidden", - autoIncrement: false } }, { - tableName: "user", + tableName: "t_user", comment: "", indexes: [] }); diff --git a/api/app/lib/models/user_token.js b/api/app/lib/models/user_token.js index e7d6546..3f6f8d4 100644 --- a/api/app/lib/models/user_token.js +++ b/api/app/lib/models/user_token.js @@ -33,7 +33,7 @@ module.exports = dc => { autoIncrement: false } }, { - tableName: "user_token", + tableName: "t_user_token", comment: "", indexes: [] }); diff --git a/api/app/lib/routes/auth/index.js b/api/app/lib/routes/auth/index.js index dac2a48..09fa95a 100644 --- a/api/app/lib/routes/auth/index.js +++ b/api/app/lib/routes/auth/index.js @@ -6,9 +6,6 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['POST/login'] = { content: '登录', visible: true }; router.post('/login', auth.login); - app.fs.api.logAttr['POST/validate/phone'] = { content: '发送验证码', visible: true }; - router.post('/validate/phone', auth.varfiyCode); - app.fs.api.logAttr['PUT/logout'] = { content: '登出', visible: false }; router.put('/logout', auth.logout); }; \ No newline at end of file