This commit is contained in:
Andris Reinman 2017-06-12 11:30:28 +03:00
parent d412363554
commit 12834af006
2 changed files with 11 additions and 6 deletions

View file

@ -314,7 +314,7 @@ class UserHandler {
});
}
setup2fa(username, callback) {
setup2fa(username, issuer, callback) {
return this.database.collection('users').findOne({
username
}, {
@ -340,7 +340,7 @@ class UserHandler {
let otpauth_url = speakeasy.otpauthURL({
secret: base32.decode(entry.seed),
label: username,
issuer: 'Wild Duck'
issuer
});
return QRCode.toDataURL(otpauth_url, (err, data_url) => {
if (err) {
@ -353,8 +353,7 @@ class UserHandler {
let secret = speakeasy.generateSecret({
length: 20,
name: username,
issuer: 'Wild Duck'
name: username
});
return this.database.collection('users').findOneAndUpdate({
@ -374,7 +373,13 @@ class UserHandler {
return callback(new Error('Could not update user, check if 2FA is not already enabled'));
}
QRCode.toDataURL(secret.otpauth_url, (err, data_url) => {
let otpauth_url = speakeasy.otpauthURL({
secret: secret.ascii,
label: username,
issuer
});
QRCode.toDataURL(otpauth_url, (err, data_url) => {
if (err) {
log.error('DB', 'QRFAIL username=%s error=%s', username, err.message);
return callback(new Error('Failed to generate QR code'));

View file

@ -1,6 +1,6 @@
{
"name": "wildduck",
"version": "1.0.49",
"version": "1.0.50",
"description": "IMAP server built with Node.js and MongoDB",
"main": "server.js",
"scripts": {