Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating Reem's feature #29

Merged
merged 15 commits into from
Sep 17, 2024
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ NodeBB by itself contains a "common core" of basic functionality, while addition

### [Try it now](//try.nodebb.org) | [Documentation](//docs.nodebb.org)

<<<<<<< HEAD

### Team Members
+ Abdallah Almana aalmana@andrew.cmu.edu
+ Abdulwahab Al-Rumaihi arumaihi@andrew.cmu.edu
+ Hiba Hamad hhamad@andrew.cmu.edu
+ Najoud Al-Talib ntalib@andrew.cmu.edu
+ Reem Kensouh rkensouh@andrew.cmu.edu

=======
>>>>>>> individual-fork/f24

## Screenshots

NodeBB's theming engine is highly flexible and does not restrict your design choices. Check out some themed installs in these screenshots below:
Expand Down
80 changes: 52 additions & 28 deletions src/meta/configs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';

const nconf = require('nconf');
Expand All @@ -18,41 +17,67 @@ Meta.config = {};
// called after data is loaded from db
function deserialize(config) {
const deserialized = {};

Object.keys(config).forEach((key) => {
const defaultType = typeof defaults[key];
const type = typeof config[key];
const number = parseFloat(config[key]);

if (defaultType === 'string' && type === 'number') {
deserialized[key] = String(config[key]);
} else if (defaultType === 'number' && type === 'string') {
if (!isNaN(number) && isFinite(config[key])) {
deserialized[key] = number;
} else {
deserialized[key] = defaults[key];
}
} else if (config[key] === 'true') {
deserialized[key] = true;
} else if (config[key] === 'false') {
deserialized[key] = false;
} else if (config[key] === null) {
deserialized[key] = defaults[key];
} else if (defaultType === 'undefined' && !isNaN(number) && isFinite(config[key])) {
deserialized[key] = number;
} else if (Array.isArray(defaults[key]) && !Array.isArray(config[key])) {
try {
deserialized[key] = JSON.parse(config[key] || '[]');
} catch (err) {
winston.error(err.stack);
deserialized[key] = defaults[key];
}
} else {
deserialized[key] = config[key];
}
deserialized[key] = handleTypeConversion(defaultType, type, config[key], number, key);
});

return deserialized;
}

// Function to handle type conversion during deserialization
function handleTypeConversion(defaultType, type, value, number, key) {
if (defaultType === 'string' && type === 'number') {
return String(value);
}

if (defaultType === 'number' && type === 'string') {
return handleNumberConversion(number, value, key);
}

if (value === 'true') {
return true;
}

if (value === 'false') {
return false;
}

if (value === null) {
return defaults[key];
}

if (defaultType === 'undefined' && !isNaN(number) && isFinite(value)) {
return number;
}

if (Array.isArray(defaults[key]) && !Array.isArray(value)) {
return handleArrayConversion(value, key);
}

return value;
}

function handleNumberConversion(number, value, key) {
if (!isNaN(number) && isFinite(value)) {
return number;
}
return defaults[key];
}

function handleArrayConversion(value, key) {
try {
return JSON.parse(value || '[]');
} catch (err) {
winston.error(err.stack);
return defaults[key];
}
}

// called before data is saved to db
function serialize(config) {
const serialized = {};
Expand Down Expand Up @@ -213,7 +238,6 @@ async function getLogoSize(data) {
size = await image.size(path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png'));
} catch (err) {
if (err.code === 'ENOENT') {
// For whatever reason the x50 logo wasn't generated, gracefully error out
winston.warn('[logo] The email-safe logo doesn\'t seem to have been created, please re-upload your site logo.');
size = {
height: 0,
Expand Down
1 change: 1 addition & 0 deletions src/user/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ module.exports = function (User) {
return userData.uid;
}


async function storePassword(uid, password) {
if (!password) {
return;
Expand Down