You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

55 lines
1.9 KiB

// | ------------------------------------------------------------
// | @版本: version 0.1
// | @创建人: 【Nie-x7129】
// | @E-mail: x71291@outlook.com
// | @所在项目: fastify-template
// | @文件描述: index.js -
// | @创建时间: 2023-12-16 22:52
// | @更新时间: 2023-12-16 22:52
// | @修改记录:
// | -*-*-*- (时间--修改人--修改说明) -*-*-*-
// | =
// | ------------------------------------------------------------
export default function (fastify, options, done){
// @ 登录
fastify.post('/signin', {
schema: {
body: {
type: 'object',
required: [ 'username', 'userpass' ],
properties: {
username: {
type: 'string',
isLowerCase: true,
errorMessage: {
type: 'username必须为字符串',
// isEven: 'isEven'
},
},
userpass: {
type: 'string',
isTrim: true,
},
code: {
type: 'integer'
}
},
errorMessage: {
required: {
username: 'username为必填项'
}
}
}
},
}, async function(request, reply){
const {username, userpass} = request.body;
if(username != this.conf.administrator.username || userpass != this.conf.administrator.userpass){
return fastify.httpErrors.conflict('用户名或密码错误!');
}
// 生成token
const token = fastify.jwt.sign({ payload: {username: 'expressgy'}, timestamp: new Date().getZH() });
return { token };
});
done();
}