Root.checkAdd (usr)
function checks if user is allowed to create a new Site

  • Parameter Obj:
    User-Object
Sourcecode in Root/securityFunctions.js:
1:   function checkAdd(usr) {
2:      // sysAdmins aren't restricted
3:      if (session.user.sysadmin)
4:         return null;
5:   
6:      switch (root.sys_limitNewSites) {
7:         case 2:
8:            if (!usr.sysadmin)
9:               throw new DenyException("siteCreateOnlyAdmins");
10:        case 1:
11:           if (!usr.trusted)
12:              throw new DenyException("siteCreateNotAllowed");
13:        default:
14:           if (root.sys_minMemberAge) {
15:              // check if user has been a registered member for long enough
16:              var regTime = Math.floor((new Date() - session.user.registered)/ONEDAY);
17:              if (regTime < root.sys_minMemberAge)
18:                 throw new DenyException("siteCreateMinMemberAge", [regTime, root.sys_minMemberAge]);
19:           } else if (root.sys_minMemberSince) {
20:              // check if user has registered before the defined timestamp
21:              if (session.user.registered > root.sys_minMemberSince)
22:                 throw new DenyException("siteCreateMinMemberSince", formatTimestamp(root.sys_minMemberSince));
23:           }
24:           if (usr.sites.count()) {
25:              // check if user has to wait some more time before creating a new Site
26:              var lastCreation = Math.floor((new Date() - usr.sites.get(0).createtime)/ONEDAY);
27:              if (lastCreation < root.sys_waitAfterNewSite)
28:                 throw new DenyException("siteCreateWait", [root.sys_waitAfterNewSite, root.sys_waitAfterNewSite - lastCreation]);
29:           }
30:     }
31:     return;
32:  }