node-egg-q
v1.0.8
Published
TypeScript + Vue 3 To get type suggestions for instance variables (this is not needed for composition API), create a new file called shims-vue-recaptcha-v3.d.ts and put the following inside it:
Downloads
1
Readme
keywrds
TypeScript + Vue 3 To get type suggestions for instance variables (this is not needed for composition API), create a new file called shims-vue-recaptcha-v3.d.ts and put the following inside it:
To use this package you only need a valid site key for your domain, which you can easily get here.
$ third party
## $ //back/app/controller/user
async getuser() {
const { ctx } = this;
let { code } = ctx.query;
if (!code) {
ctx.body = {
code: 2,
mes: '缺少参数'
}
return;
}
let config = ctx.app.config.gitee;
let res = await axios.post('https://gitee.com/oauth/token', {
grant_type: 'authorization_code',
code,
client_id: config.client_id,
redirect_uri: config.redirect_uri,
client_secret: config.client_secret
});
console.log(res, '&&&&&&')
let access_token = res.data.access_token;
let user = await axios.get('https://gitee.com/api/v5/user', {
params: {
access_token
}
});
console.log(user, '&&&&&&&&')
ctx.body = {
code: 0,
token: ctx.helper.gettoken({ name: user.data.name, id: user.data.id }),
data: user.data
}
}
A simple and easy to use reCAPTCHA (v3 only) library for Vue based on reCAPTCHA-v3.
The latest version of this package supports Vue 3! See here for Vue 2 usage.
$ password encryption
app/extend/helper
const { createHmac } = require('crypto');
const jwt = require('jsonwebtoken');
module.exports = {
cryptopwd(pwd) {
const secret = '1903a';
return createHmac('sha256', secret)
.update(pwd)
.digest('hex');
},
gettoken(data) {
return jwt.sign(data, this.app.config.keys, { expiresIn: '10h' });
}
};
TypeScript + Vue 3 To get type suggestions for instance variables (this is not needed for composition API), create a new file called shims-vue-recaptcha-v3.d.ts and put the following inside it:
serviceUser
/service/user
'use strict';
const Service = require('egg').Service;
class UserService extends Service {
async getuser(name) {
return await this.app.mysql.get('ykuser', { name });
}
async registry(obj) {
return await this.app.mysql.insert('ykuser', obj);
}
async login(obj) {
return await this.app.mysql.select('ykuser', {
where: obj
});
}
}
module.exports = UserService;
$ routers
app/router
'use strict';
/**
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { router, controller, validator } = app;
//添加自定义校验规则
validator.addRule('phone', (rule, value) => {
if (!/^1[3456789]\d{9}$/.test(value)) {
return '手机号校验失败'
}
})
router.get('/', controller.home.index);
router.post('/registry', controller.user.registry);
router.post('/login',controller.user.login);
router.get('/getcaptcha',controller.user.getcaptcha);
router.get('/getuser',controller.user.getuser);
};