@@ -3,11 +3,12 @@ const util = require('util')
33const { URL } = require ( 'url' )
44
55const { loadConfig } = require ( './common' )
6+ const { isValidUsername } = require ( '../../lib/common/user-utils' )
67const blacklistService = require ( '../../lib/services/blacklist-service' )
78
8- const AccountManager = require ( '../../lib/models/account-manager' )
9- const LDP = require ( '../../lib/ldp' )
10- const SolidHost = require ( '../../lib/models/solid-host' )
9+ // const AccountManager = require('../../lib/models/account-manager')
10+ // const LDP = require('../../lib/ldp')
11+ // const SolidHost = require('../../lib/models/solid-host')
1112
1213module . exports = function ( program ) {
1314 program
@@ -21,25 +22,29 @@ module.exports = function (program) {
2122 return console . error ( 'You are running a single user server, no need to check for blacklisted users' )
2223 }
2324
24- const host = SolidHost . from ( { port : config . port , serverUri : config . serverUri } )
25+ // const host = SolidHost.from({ port: config.port, serverUri: config.serverUri })
2526 const invalidUsernames = await getInvalidUsernames ( config )
26- console . log ( invalidUsernames )
2727
28- const ldp = new LDP ( config )
29- const accountManager = AccountManager . from ( {
30- // authMethod: argv.auth,
31- // emailService: app.locals.emailService,
32- // tokenService: app.locals.tokenService,
33- host,
34- // accountTemplatePath: argv.templates.account,
35- store : ldp ,
36- multiuser : config . multiuser
37- } )
38- const blacklistedUsernames = await getBlacklistedUsernames ( accountManager )
39- if ( blacklistedUsernames . length === 0 ) {
40- console . log ( 'No blacklisted username was found' )
28+ // const ldp = new LDP(config)
29+ // const accountManager = AccountManager.from({
30+ // // authMethod: argv.auth,
31+ // // emailService: app.locals.emailService,
32+ // // tokenService: app.locals.tokenService,
33+ // host,
34+ // // accountTemplatePath: argv.templates.account,
35+ // store: ldp,
36+ // multiuser: config.multiuser
37+ // })
38+ // const blacklistedUsernames = await getBlacklistedUsernames(accountManager)
39+ // if (blacklistedUsernames.length === 0) {
40+ // console.log('No blacklisted username was found')
41+ // }
42+ // console.log(`These blacklisted usernames were found:${blacklistedUsernames.map(username => `\n- ${username}`)}`)
43+
44+ if ( invalidUsernames . length === 0 ) {
45+ console . log ( 'No invalid username was found' )
4146 }
42- console . log ( `These blacklisted usernames were found:${ blacklistedUsernames . map ( username => `\n- ${ username } ` ) } ` )
47+ console . log ( `${ invalidUsernames . length } invalid usernames were found:${ invalidUsernames . map ( username => `\n- ${ username } ` ) } ` )
4348 } )
4449}
4550
@@ -50,15 +55,16 @@ async function getInvalidUsernames (config) {
5055 return files
5156 . filter ( file => isUserDirectory . test ( file ) )
5257 . map ( userDirectory => userDirectory . substr ( 0 , userDirectory . length - hostname . length - 1 ) )
58+ . filter ( username => ! isValidUsername ( username ) || ! blacklistService . validate ( username ) )
5359}
5460
55- async function getBlacklistedUsernames ( accountManager ) {
56- const blacklistedUsernames = [ ]
57- await Promise . all ( blacklistService . list . map ( async ( word ) => {
58- const accountExists = await accountManager . accountExists ( word )
59- if ( accountExists ) {
60- blacklistedUsernames . push ( word )
61- }
62- } ) )
63- return blacklistedUsernames
64- }
61+ // async function getBlacklistedUsernames (accountManager) {
62+ // const blacklistedUsernames = []
63+ // await Promise.all(blacklistService.list.map(async (word) => {
64+ // const accountExists = await accountManager.accountExists(word)
65+ // if (accountExists) {
66+ // blacklistedUsernames.push(word)
67+ // }
68+ // }))
69+ // return blacklistedUsernames
70+ // }
0 commit comments