lintry

二维码生成时返回图片内容和url

......@@ -27,7 +27,7 @@ const Authenticator = function (secret, options) {
* 验证token有效性
* @param token
*/
this.verify = function(token) {
this.verify = function (token) {
return speakeasy.totp.verify(_.merge({}, TOTP_OPTIONS, {token: token}));
};
......@@ -36,7 +36,7 @@ const Authenticator = function (secret, options) {
* @param token
* @param window
*/
this.verifyDelta = function(token, window) {
this.verifyDelta = function (token, window) {
return speakeasy.totp.verifyDelta(_.merge({}, TOTP_OPTIONS, {token: token, window: window}));
};
......@@ -54,10 +54,14 @@ const Authenticator = function (secret, options) {
* 生成svg的QR图片内容
* @param label
* @param issuer
* @return {*}
* @return {{content: *, url: string}}
*/
this.getQR = function(label, issuer) {
return qr.imageSync(this.getOtpAuthURL(label, issuer), { type: 'svg' });
this.getQR = function (label, issuer) {
let url = this.getOtpAuthURL(label, issuer);
return {
content: qr.imageSync(url, { type: 'svg' }),
url: url
};
};
/**
......
......@@ -41,11 +41,12 @@ fs.ensureDir(img_path, function (err, added_root) {
}
added_root && console.log(chalk.green(img_path + ' is created'));
let qr = authenticator.getQR('totp@gitlab.kmlab.com', '通行密钥');
let fd = fs.openSync(qr, 'w');
fs.writeSync(fd, authenticator.getQR('totp@gitlab.kmlab.com', '通行密钥'));
fs.writeSync(fd, qr.content);
fs.closeSync(fd);
console.log(chalk.green('密钥字符串'), chalk.yellow(authenticator.getOtpAuthURL('totp@gitlab.kmlab.com', '通行密钥')))
console.log(chalk.green('密钥字符串'), chalk.yellow(qr.url))
});
console.log('QR SVG output is', img_path, qr);
\ No newline at end of file
......