登录完成
This commit is contained in:
20
server/app/controller/auth.js
Normal file
20
server/app/controller/auth.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const Controller = require("egg").Controller
|
||||
|
||||
const table = "sys_user";
|
||||
|
||||
class Auth extends Controller {
|
||||
async token() {
|
||||
const {ctx: {query}, ctx, app} = this
|
||||
ctx.validate({phone: "string", password: "password"}, query)
|
||||
const {phone, password} = query
|
||||
const user = await app.mysql.get(table, {phone, password})
|
||||
if (!user?.id) {
|
||||
return this.ctx.body = {code: 1, msg: "用户名或密码不正确"}
|
||||
}
|
||||
const token = app.jwt.sign({id: user?.id}, app.config.jwt.secret)
|
||||
this.ctx.body = {code: 0, data: "bearer " + token}
|
||||
this.ctx.status = 200
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Auth
|
||||
Reference in New Issue
Block a user