Skip to content

Commit

Permalink
feat: check config flag common.allowRegistration to allow registration
Browse files Browse the repository at this point in the history
  • Loading branch information
byronigoe authored and rocwind committed Nov 23, 2021
1 parent b8b0276 commit 53ffab6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ config.development = {
tokenSecret: process.env.TOKEN_SECRET || 'INSERT_RANDOM_TOKEN_KEY',
},
common: {
// determine whether new account registrations are allowed
allowRegistration: false,
/*
* tryLoginTimes is control login error times to avoid force attack.
* if value is 0, no limit for login auth, it may not safe for account. when it's a number, it means you can
Expand Down
6 changes: 5 additions & 1 deletion routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ router.get('/register', (req, res) => {
log.debug(`register redirect:${codePushWebUrl}`);
res.redirect(`${codePushWebUrl}/register`);
} else {
res.render('auth/register', { title: 'CodePushServer', email: req.query.email || '' });
if (_.get(config, 'common.allowRegistration')) {
res.render('auth/register', { title: 'CodePushServer', email: req.query.email || '' });
} else {
res.redirect(`/auth/login`);
}
}
});

Expand Down
14 changes: 14 additions & 0 deletions test/api/auth/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,21 @@ describe('api/auth/test.js', function () {
});

describe('sign up view', function (done) {
it('should show sign in redirect view if sign up not enabled', function (done) {
_.set(config, 'common.allowRegistration', false);
request
.get('/auth/register')
.send()
.end(function (err, res) {
should.not.exist(err);
res.status.should.equal(302);
done();
});
});

it('should show sign up redirect view successful', function (done) {
_.set(config, 'common.codePushWebUrl', 'http://127.0.0.1:3001');
_.set(config, 'common.allowRegistration', true);
request
.get('/auth/register')
.send()
Expand All @@ -49,6 +62,7 @@ describe('api/auth/test.js', function () {

it('should show sign up view successful', function (done) {
_.set(config, 'common.codePushWebUrl', null);
_.set(config, 'common.allowRegistration', true);
request
.get('/auth/register')
.send()
Expand Down

0 comments on commit 53ffab6

Please sign in to comment.