concourse-server/app.js
// Add initial login token if no users are present on startup
Add initial login token if no users are present on startup
Add initial login token if no users are present on startup
async function initial_run_check(){
	const found_users = await UserLoginModel.countDocuments()
	if(!found_users){
		const root_user_password = (await __promisified_crypto_random_bytes(256)).toString('hex')
		const root_user_profile = new UserProfileModel({
			username: "root",
			display_name: "System",
			pronouns: {
				subject: "it",
				object: "it",
				dependent_possessive: "its",
				independent_possessive: "its",
				reflexive: "itself"
			},
			emails: [{
				address: "root@concourse.city",
				verified: true,
				primary: true
			}],
			administrator: true,
			can_create_campaigns: true,
			can_create_registration_keys: true,
			campaigns: []
		})
		await root_user_profile.save()
		const root_user_login = new UserLoginModel({
			username: "root",
			password: root_user_password,
			profile: root_user_profile._id
		})
		await root_user_login.save()
		const found_initial_key = await RegistrationKeyModel.findOne({text: process.env.REGISTRATION_INITIAL_KEY || config.registration.initial_key})
		if(found_initial_key){
			found_initial_key.creator = root_user_profile.id,
			found_initial_key.text = process.env.REGISTRATION_INITIAL_KEY || config.registration.initial_key,
			found_initial_key.uses_total = 1
			found_initial_key.uses_remaining = 1
			found_initial_key.grants_administrator = true
			found_initial_key.grants_create_campaigns = true
			found_initial_key.grants_create_registration_keys = true
			await found_initial_key.save()
			return true
		}else{
			const initial_key = new RegistrationKeyModel({
				creator: root_user_profile._id,
				text: process.env.REGISTRATION_INITIAL_KEY || config.registration.initial_key,
				uses_total: 1,
				uses_remaining: 1,
				grants_administrator: true,
				grants_create_campaigns: true,
				grants_create_registration_keys: true
			})
			await initial_key.save()
			return true
		}
	}
	return false
}
async function initial_run_check ( ) { const found_users = await UserLoginModel . countDocuments ( ) if ( ! found_users ) { const root_user_password = ( await __promisified_crypto_random_bytes ( 256 ) ) . toString ( 'hex' ) const root_user_profile = new UserProfileModel ( { username : "root" , display_name : "System" , pronouns : { subject : "it" , object : "it" , dependent_possessive : "its" , independent_possessive : "its" , reflexive : "itself" } , emails : [ { address : "root@concourse.city" , verified : true , primary : true } ] , administrator : true , can_create_campaigns : true , can_create_registration_keys : true , campaigns : [ ] } ) await root_user_profile . save ( ) const root_user_login = new UserLoginModel ( { username : "root" , password : root_user_password , profile : root_user_profile . _id } ) await root_user_login . save ( ) const found_initial_key = await RegistrationKeyModel . findOne ( { text : process . env . REGISTRATION_INITIAL_KEY || config . registration . initial_key } ) if ( found_initial_key ) { found_initial_key . creator = root_user_profile . id , found_initial_key . text = process . env . REGISTRATION_INITIAL_KEY || config . registration . initial_key , found_initial_key . uses_total = 1 found_initial_key . uses_remaining = 1 found_initial_key . grants_administrator = true found_initial_key . grants_create_campaigns = true found_initial_key . grants_create_registration_keys = true await found_initial_key . save ( ) return true } else { const initial_key = new RegistrationKeyModel ( { creator : root_user_profile . _id , text : process . env . REGISTRATION_INITIAL_KEY || config . registration . initial_key , uses_total : 1 , uses_remaining : 1 , grants_administrator : true , grants_create_campaigns : true , grants_create_registration_keys : true } ) await initial_key . save ( ) return true } } return false }
Add initial login token if no users are present on startup
Add initial login token if no users are present on startup