Display sharing link after verification
This commit is contained in:
parent
d5bd65b4bc
commit
cfb4b9bab0
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user