Skip to content

Commit

Permalink
feat(app): let user generate new keys
Browse files Browse the repository at this point in the history
  • Loading branch information
geekus committed Mar 3, 2017
1 parent 564dda3 commit 4c9229c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const route = new Router();

const ApiUser = require('./model').ApiUser;
const filters = require('./filters');
const keygen = require('../../lib/keygen');

const APPS_FREE = process.env.APPS_FREE || 1;

Expand Down Expand Up @@ -37,6 +38,10 @@ route.use('/', (req, res, next) => {
return next();
});

route.post('/keygen', (req, res, next) => {
return res.json({ key: keygen() });
});

route.use('/', (req, res, next) => {
if (req.api.apps.length === 0 && /^\/app\/?$/.test(req.originalUrl)) {
return res.redirect('/app/new');
Expand Down Expand Up @@ -152,6 +157,8 @@ route.post('/:id', (req, res, next) => {
req.app.set('name', req.body.name);
req.app.set('url', req.body.url || undefined);
req.app.set('desc', req.body.desc);
req.app.set('key.dev', req.body.key_dev);
req.app.set('key.prod', req.body.key_prod);

This comment has been minimized.

Copy link
@Starefossen

Starefossen Mar 3, 2017

Member

This is not secure.

This comment has been minimized.

Copy link
@geekus

geekus Mar 6, 2017

Author Contributor

Referring to the comment below, I guess?


// Prod rate-limit change request
if (parseInt(req.body.limit_prod, 10) !== req.app.limit.prod) {
Expand Down
7 changes: 7 additions & 0 deletions static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ clipboard.on('success', function(e) {
$('.button.copy').on('click', function(e) {
e.preventDefault();
});

$('.button.keygen').on('click', function(e) {
$.post('/app/keygen', $.proxy(function(data) {
$(this).prevAll('input').first().val(data.key);
}, this));
e.preventDefault();
});
10 changes: 10 additions & 0 deletions views/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ <h4 class="ui header">
data-clipboard-text="{{ app.key.prod }}">
<i class="copy icon"></i> Kopier
</button>
<button
class="ui orange right labeled icon button keygen"
data-clipboard-text="{{ app.key.dev }}">

This comment has been minimized.

Copy link
@Starefossen

Starefossen Mar 3, 2017

Member

This should be app.key.prod

This comment has been minimized.

Copy link
@geekus

geekus Mar 6, 2017

Author Contributor

Should not be there at all. Forgot to remove when duplicating the copy-button.

<i class="refresh icon"></i> Lag ny
</button>
</div>
</div>
<div class="four wide field">
Expand All @@ -89,6 +94,11 @@ <h4 class="ui header">
data-clipboard-text="{{ app.key.dev }}">
<i class="copy icon"></i> Kopier
</button>
<button
class="ui orange right labeled icon button keygen"
data-clipboard-text="{{ app.key.dev }}">
<i class="refresh icon"></i> Lag ny
</button>
</div>
</div>
<div class="four wide field">
Expand Down

2 comments on commit 4c9229c

@Starefossen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables users to post their own keys since the new key is handled by the client code and hence not a good idea. The new key should be saved when re-generated and not be saved when posting the schema.

@geekus
Copy link
Contributor Author

@geekus geekus commented on 4c9229c Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Tried to keep it simple, but this might be too simple. I'll fix before merging.

Please sign in to comment.