lintry

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

...@@ -27,7 +27,7 @@ const Authenticator = function (secret, options) { ...@@ -27,7 +27,7 @@ const Authenticator = function (secret, options) {
27 * 验证token有效性 27 * 验证token有效性
28 * @param token 28 * @param token
29 */ 29 */
30 - this.verify = function(token) { 30 + this.verify = function (token) {
31 return speakeasy.totp.verify(_.merge({}, TOTP_OPTIONS, {token: token})); 31 return speakeasy.totp.verify(_.merge({}, TOTP_OPTIONS, {token: token}));
32 }; 32 };
33 33
...@@ -36,7 +36,7 @@ const Authenticator = function (secret, options) { ...@@ -36,7 +36,7 @@ const Authenticator = function (secret, options) {
36 * @param token 36 * @param token
37 * @param window 37 * @param window
38 */ 38 */
39 - this.verifyDelta = function(token, window) { 39 + this.verifyDelta = function (token, window) {
40 return speakeasy.totp.verifyDelta(_.merge({}, TOTP_OPTIONS, {token: token, window: window})); 40 return speakeasy.totp.verifyDelta(_.merge({}, TOTP_OPTIONS, {token: token, window: window}));
41 }; 41 };
42 42
...@@ -54,10 +54,14 @@ const Authenticator = function (secret, options) { ...@@ -54,10 +54,14 @@ const Authenticator = function (secret, options) {
54 * 生成svg的QR图片内容 54 * 生成svg的QR图片内容
55 * @param label 55 * @param label
56 * @param issuer 56 * @param issuer
57 - * @return {*} 57 + * @return {{content: *, url: string}}
58 */ 58 */
59 - this.getQR = function(label, issuer) { 59 + this.getQR = function (label, issuer) {
60 - return qr.imageSync(this.getOtpAuthURL(label, issuer), { type: 'svg' }); 60 + let url = this.getOtpAuthURL(label, issuer);
61 + return {
62 + content: qr.imageSync(url, { type: 'svg' }),
63 + url: url
64 + };
61 }; 65 };
62 66
63 /** 67 /**
......
...@@ -41,11 +41,12 @@ fs.ensureDir(img_path, function (err, added_root) { ...@@ -41,11 +41,12 @@ fs.ensureDir(img_path, function (err, added_root) {
41 } 41 }
42 added_root && console.log(chalk.green(img_path + ' is created')); 42 added_root && console.log(chalk.green(img_path + ' is created'));
43 43
44 + let qr = authenticator.getQR('totp@gitlab.kmlab.com', '通行密钥');
44 let fd = fs.openSync(qr, 'w'); 45 let fd = fs.openSync(qr, 'w');
45 - fs.writeSync(fd, authenticator.getQR('totp@gitlab.kmlab.com', '通行密钥')); 46 + fs.writeSync(fd, qr.content);
46 fs.closeSync(fd); 47 fs.closeSync(fd);
47 48
48 - console.log(chalk.green('密钥字符串'), chalk.yellow(authenticator.getOtpAuthURL('totp@gitlab.kmlab.com', '通行密钥'))) 49 + console.log(chalk.green('密钥字符串'), chalk.yellow(qr.url))
49 }); 50 });
50 51
51 console.log('QR SVG output is', img_path, qr); 52 console.log('QR SVG output is', img_path, qr);
...\ No newline at end of file ...\ No newline at end of file
......