unreal engine 5.1 update, level load fixed
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
exports.users = require('./users');
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
//
|
||||
// Usage: npm run store_password -- --username <USERNAME> --password <PASSWORD>
|
||||
// or from ./modules/authentication/db dir: node store_password.js --username <USERNAME> --password <PASSWORD>
|
||||
//
|
||||
// --usersFile is an optional parameter that can be used to specify a different location for the users database file
|
||||
// use this if running the command from a different working dir. The default location is './users.json'
|
||||
// e.g. If running from the SignallingWebServer dir use: --usersFile ./modules/authentication/db/users.json
|
||||
|
||||
const argv = require('yargs').argv;
|
||||
const fs = require('fs');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
var username, password;
|
||||
var usersFile = './users.json'
|
||||
|
||||
const STORE_PLAINTEXT_PASSWORD = false;
|
||||
|
||||
try {
|
||||
if(typeof argv.username != 'undefined'){
|
||||
username = argv.username.toString();
|
||||
}
|
||||
|
||||
if(typeof argv.password != 'undefined'){
|
||||
password = argv.password;
|
||||
}
|
||||
|
||||
if(typeof argv.usersFile != 'undefined'){
|
||||
usersFile = argv.usersFile;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
if(username && password){
|
||||
let existingAccounts = [];
|
||||
if (fs.existsSync(usersFile)) {
|
||||
console.log(`File '${usersFile}' exists, reading file`)
|
||||
var content = fs.readFileSync(usersFile, 'utf8');
|
||||
try{
|
||||
existingAccounts = JSON.parse(content);
|
||||
}
|
||||
catch(e){
|
||||
console.error(`Existing file '${usersFile}', has invalid JSON: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
var existingUser = existingAccounts.find( u => u.username == username)
|
||||
if(existingUser){
|
||||
console.log(`User '${username}', already exists, updating password`)
|
||||
existingUser.passwordHash = generatePasswordHash(password)
|
||||
if(STORE_PLAINTEXT_PASSWORD)
|
||||
existingUser.password = password;
|
||||
else if (existingUser.password)
|
||||
delete existingUser.password;
|
||||
|
||||
} else {
|
||||
console.log(`Adding new user '${username}'`)
|
||||
let newUser = {
|
||||
id: existingAccounts.length + 1,
|
||||
username: username,
|
||||
passwordHash: generatePasswordHash(password)
|
||||
}
|
||||
if(STORE_PLAINTEXT_PASSWORD)
|
||||
newUser.password = password;
|
||||
|
||||
existingAccounts.push(newUser);
|
||||
}
|
||||
|
||||
console.log(`Writing updated users to '${usersFile}'`);
|
||||
var newContent = JSON.stringify(existingAccounts);
|
||||
fs.writeFileSync(usersFile, newContent);
|
||||
} else {
|
||||
console.log(`Please pass in both username (${username}) and password (${password}) please`);
|
||||
}
|
||||
|
||||
function generatePasswordHash(pass){
|
||||
return bcrypt.hashSync(pass, 12)
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Read in users from file
|
||||
let records = [];
|
||||
let usersFile = path.join(__dirname, './users.json');
|
||||
if (fs.existsSync(usersFile)) {
|
||||
console.log(`Reading users from '${usersFile}'`)
|
||||
var content = fs.readFileSync(usersFile, 'utf8');
|
||||
try {
|
||||
records = JSON.parse(content);
|
||||
} catch(e) {
|
||||
console.log(`ERROR: Failed to parse users from file '${usersFile}'`)
|
||||
}
|
||||
}
|
||||
|
||||
exports.findById = function(id, cb) {
|
||||
var idx = id - 1;
|
||||
if (records[idx]) {
|
||||
cb(null, records[idx]);
|
||||
} else {
|
||||
cb(new Error('User ' + id + ' does not exist'));
|
||||
}
|
||||
}
|
||||
|
||||
exports.findByUsername = function(username, cb) {
|
||||
for (var i = 0, len = records.length; i < len; i++) {
|
||||
var record = records[i];
|
||||
if (record.username === username) {
|
||||
return cb(null, record);
|
||||
}
|
||||
}
|
||||
return cb(null, null);
|
||||
}
|
||||
Reference in New Issue
Block a user