Display sharing link after verification

This commit is contained in:
Tankred Hase 2016-06-10 12:45:22 +02:00
parent d5bd65b4bc
commit cfb4b9bab0
3 changed files with 30 additions and 6 deletions

View File

@ -66,7 +66,7 @@ router.get('/api/v1/removeKey', function *() {
router.get('/api/v1/verifyRemove', function *() {
yield rest.verifyRemove(this);
});
router.get('/user/:email', function *() {
router.get('/user/:search', function *() {
yield rest.share(this);
});

View File

@ -59,7 +59,10 @@ class REST {
ctx.throw(400, 'Invalid request!');
}
yield this._publicKey.verify(q);
ctx.body = 'Key successfully verified!';
// create link for sharing
let link = util.url(util.origin(ctx), '/user/' + q.keyId.toUpperCase());
ctx.body = `<p>Key successfully verified!</p><p>Link to share your key: <a href="${link}" target="_blank">${link}</a></p>`;
ctx.set('Content-Type', 'text/html; charset=utf-8');
}
/**
@ -79,8 +82,15 @@ class REST {
* @param {Object} ctx The koa request/response context
*/
*share(ctx) {
let q = { email:ctx.params.email };
if (!util.isEmail(q.email)) {
let q, search = ctx.params.search;
if (util.isEmail(search)) {
q = { email:search };
} else if (util.isKeyId(search)) {
q = { keyId:search };
} else if (util.isFingerPrint(search)) {
q = { fingerprint:search };
}
if (!q) {
ctx.throw(400, 'Invalid request!');
}
ctx.body = (yield this._publicKey.get(q)).publicKeyArmored;

View File

@ -190,7 +190,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
});
});
describe('GET /user/:email (sharing link)', () => {
describe('GET /user/:search (sharing link)', () => {
beforeEach(done => {
request(app.listen())
.post('/api/v1/key')
@ -216,13 +216,27 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
.end(done);
});
it('should return 200 for correct email address', done => {
it('should return 200 for email address', done => {
request(app.listen())
.get('/user/' + primaryEmail)
.expect(200, publicKeyArmored)
.end(done);
});
it('should return 200 for key id', done => {
request(app.listen())
.get('/user/' + emailParams.keyId)
.expect(200, publicKeyArmored)
.end(done);
});
it('should return 200 for fingerprint', done => {
request(app.listen())
.get('/user/' + fingerprint)
.expect(200, publicKeyArmored)
.end(done);
});
it('should return 400 for invalid email', done => {
request(app.listen())
.get('/user/a@bco')