64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
'use strict'
|
|
|
|
const { md5 } = require('js-md5')
|
|
const { insert, query, Types, OPTypes } = require("../../util/db");
|
|
|
|
const registerService = async function(fastify, tel, pwd) {
|
|
const queryParam = {
|
|
table: 't_user',
|
|
field: ['tel'],
|
|
where: [{
|
|
field: 'tel',
|
|
types: Types.Stirng,
|
|
value: tel
|
|
}],
|
|
operator: [],
|
|
}
|
|
let res = await query(fastify, queryParam)
|
|
console.log(res.data, res.data.length)
|
|
if (res.data !== undefined && res.data.length > 0) {
|
|
return {errno: -1, message: '当前账号已经被注册'}
|
|
}
|
|
|
|
pwd = md5(pwd)
|
|
const param = {
|
|
table: 't_user',
|
|
field: ['tel', 'pwd'],
|
|
types: [Types.Stirng, Types.Stirng],
|
|
values: [tel, pwd]
|
|
}
|
|
res = await insert(fastify, param)
|
|
return res
|
|
}
|
|
|
|
const loginService = async function(fastify, tel, pwd) {
|
|
pwd = md5(pwd)
|
|
const queryParam = {
|
|
table: 't_user',
|
|
field: ['tel'],
|
|
where: [{
|
|
field: 'tel',
|
|
types: Types.Stirng,
|
|
value: tel
|
|
}, {
|
|
field: 'pwd',
|
|
types: Types.Stirng,
|
|
value: pwd
|
|
}
|
|
],
|
|
operator: [OPTypes.And],
|
|
}
|
|
// let res = await query(fastify, queryParam)
|
|
// console.log(res.data, res.data.length)
|
|
// if (res.data !== undefined && res.data.length !== 1) {
|
|
// return {errno: -1, message: '手机号或者密码不正确'}
|
|
// }
|
|
// const token = await fastify.jwt.sign({sub: res.data.tel + res.data.pwd})
|
|
const token = await fastify.jwt.sign({sub: 'username,password'})
|
|
return {errno: 0, token: token, message: '成功'}
|
|
}
|
|
|
|
module.exports = {
|
|
registerService,
|
|
loginService
|
|
} |