Browse Source

add user upper limit check

Seiya Tashiro 7 years ago
parent
commit
a21111df2f
2 changed files with 16 additions and 0 deletions
  1. 12 0
      src/server/models/user.js
  2. 4 0
      src/server/routes/login.js

+ 12 - 0
src/server/models/user.js

@@ -707,6 +707,13 @@ module.exports = function(crowi) {
     const User = this
       , newUser = new User();
 
+    // check user upper limit
+    const isUserUpperLimitError = await User.isUserUpperLimitError();
+    if (isUserUpperLimitError) {
+      const err = new UserUpperLimitException();
+      callback(err);
+    }
+
     // check email duplication because email must be unique
     const count = await this.count({ email });
     if (count > 0) {
@@ -779,6 +786,11 @@ module.exports = function(crowi) {
     return username;
   };
 
+  class UserUpperLimitException {
+    constructor() {
+      this.name = this.constructor.name;
+    }
+  }
 
   userSchema.statics.STATUS_REGISTERED  = STATUS_REGISTERED;
   userSchema.statics.STATUS_ACTIVE      = STATUS_ACTIVE;

+ 4 - 0
src/server/routes/login.js

@@ -188,6 +188,10 @@ module.exports = function(crowi, app) {
 
         User.createUserByEmailAndPassword(name, username, email, password, lang, function(err, userData) {
           if (err) {
+            if (err.name === 'UserUpperLimitException') {
+              req.flash('registerWarningMessage', 'Can not register more than the maximum number of users.');
+              return res.redirect('/register');
+            }
             req.flash('registerWarningMessage', 'Failed to register.');
             return res.redirect('/register');
           }