Fixed first user creation when NewAccount is true

Ylian Saint-Hilaire committed Sep 27, 2019 at 10:15 UTC 12440105dc26357559597cde5797db8a12a9f230
1 file changed +8 -9
webserver.js
+8 -9
@@ -777,16 +777,15 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
777 // If the email is the username, set this here.
778 if (domain.usernameisemail) { req.body.username = req.body.email; }
779
780 + // Count the number of users in this domain
781 + var domainUserCount = 0;
782 + for (var i in obj.users) { if (obj.users[i].domain == domain.id) { domainUserCount++; } }
783 +
784 // Check if we are allowed to create new users using the login screen
781 - var domainUserCount = -1;
782 - if ((domain.newaccounts !== 1) && (domain.newaccounts !== true)) {
783 - domainUserCount = 0;
784 - for (var i in obj.users) { if (obj.users[i].domain == domain.id) { domainUserCount++; } }
785 - if (domainUserCount > 0) {
786 - parent.debug('web', 'handleCreateAccountRequest: domainUserCount > 1.');
787 - res.sendStatus(401);
788 - return;
789 - }
785 + if ((domain.newaccounts !== 1) && (domain.newaccounts !== true) && (domainUserCount > 0)) {
786 + parent.debug('web', 'handleCreateAccountRequest: domainUserCount > 1.');
787 + res.sendStatus(401);
788 + return;
789 }
790
791 // Check if this request is for an allows email domain