-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from secretin/rescue_codes
Add rescue codes support in case of TOTP lost
- Loading branch information
Showing
8 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Router } from 'express'; | ||
import url from 'url'; | ||
|
||
import Console from '../console'; | ||
import Utils from '../utils'; | ||
|
||
export default ({ couchdb }) => { | ||
const route = Router(); | ||
route.get('/:name', (req, res) => { | ||
let rescueCodes; | ||
Utils.checkSignature({ | ||
couchdb, | ||
name: req.params.name, | ||
sig: req.query.sig, | ||
data: `${req.baseUrl}${url.parse(req.url).pathname}`, | ||
}) | ||
.then((rawUser) => { | ||
const user = rawUser.data; | ||
|
||
if (user.pass.totp) { | ||
/* Retrocompatibility */ | ||
if (typeof user.rescueCodes === 'undefined') { | ||
const doc = { | ||
_id: rawUser.id, | ||
_rev: rawUser.rev, | ||
user: { | ||
[req.params.name]: rawUser.data, | ||
}, | ||
}; | ||
rescueCodes = Utils.generateRescueCodes(); | ||
doc.user[req.params.name].rescueCodes = rescueCodes; | ||
return couchdb.update(couchdb.databaseName, doc); | ||
} | ||
/* End retrocompatibility */ | ||
rescueCodes = user.rescueCodes; | ||
} else { | ||
rescueCodes = []; | ||
} | ||
return Promise.resolve(); | ||
}) | ||
.then(() => { | ||
res.json(rescueCodes); | ||
}) | ||
.catch((error) => { | ||
Console.error(res, error); | ||
}); | ||
}); | ||
|
||
return route; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters