@@ -39,7 +39,6 @@ function IdentityProvider (options) {
3939 this . buildURI = options . buildURI || defaultBuildURI
4040 this . suffixAcl = options . suffixAcl
4141 this . defaultContainers = options . defaultContainers || defaultContainers
42- this . overwrite = options . overwrite
4342 this . inbox = options . inbox
4443 this . settings = options . settings
4544}
@@ -113,7 +112,7 @@ IdentityProvider.prototype.create = function (options, cert, callback) {
113112 var subdomain = options . host . split ( ':' ) [ 0 ]
114113 self . store . exists ( subdomain , '/' , function ( err ) {
115114 // if page exists, cannot create account
116- if ( ! self . overwrite && ( ! err || err . status !== 404 ) ) {
115+ if ( ! options . firstUser && ( ! err || err . status !== 404 ) ) {
117116 debug ( 'Cannot create ' + subdomain + ', it already exists' )
118117 var error = new Error ( 'Account already exists' )
119118 error . status = 406
@@ -511,6 +510,7 @@ IdentityProvider.prototype.post = function (req, res, next) {
511510 var self = this
512511 var options = req . body
513512 options . host = req . get ( 'host' )
513+ options . firstUser = res . locals . firstUser
514514 var agent = self . agent ( options )
515515 var spkac = null
516516 var cert = null
@@ -558,14 +558,15 @@ IdentityProvider.prototype.post = function (req, res, next) {
558558}
559559
560560// Middleware (or Router) to serve the IdentityProvider
561- IdentityProvider . prototype . middleware = function ( corsSettings ) {
561+ IdentityProvider . prototype . middleware = function ( corsSettings , firstUser ) {
562562 var router = express . Router ( '/' )
563563 var parser = bodyParser . urlencoded ( { extended : false } )
564564
565565 if ( corsSettings ) {
566566 router . use ( corsSettings )
567567 }
568- router . post ( '/new' , parser , this . post . bind ( this ) )
568+
569+ router . post ( '/new' , parser , setFirstUser ( firstUser ) , this . post . bind ( this ) )
569570 router . post ( '/cert' , parser , this . newCert . bind ( this ) )
570571 router . all ( '/*' , function ( req , res ) {
571572 var host = uriAbs ( req )
@@ -576,3 +577,10 @@ IdentityProvider.prototype.middleware = function (corsSettings) {
576577
577578 return router
578579}
580+
581+ function setFirstUser ( isFirstUser ) {
582+ return function ( req , res , next ) {
583+ res . locals . firstUser = isFirstUser
584+ next ( )
585+ }
586+ }
0 commit comments