Some bug fixes
This commit is contained in:
@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}, {
|
||||
fields: {
|
||||
data: false,
|
||||
'account.profile': false
|
||||
'profile': false
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}, {
|
||||
fields: {
|
||||
data: false,
|
||||
'account.profile': false
|
||||
'profile': false
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -5,12 +5,6 @@ import User, { pack } from '../../../models/user';
|
||||
|
||||
/**
|
||||
* Show myself
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @param {any} app
|
||||
* @param {Boolean} isSecure
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
|
||||
// Serialize
|
||||
@ -22,7 +16,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
|
||||
// Update lastUsedAt
|
||||
User.update({ _id: user._id }, {
|
||||
$set: {
|
||||
'account.lastUsedAt': new Date()
|
||||
lastUsedAt: new Date()
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -28,8 +28,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.twoFactorSecret': user.twoFactorTempSecret,
|
||||
'account.twoFactorEnabled': true
|
||||
'twoFactorSecret': user.twoFactorTempSecret,
|
||||
'twoFactorEnabled': true
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -14,7 +14,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
if (passwordErr) return rej('invalid password param');
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(password, user.account.password);
|
||||
const same = await bcrypt.compare(password, user.password);
|
||||
|
||||
if (!same) {
|
||||
return rej('incorrect password');
|
||||
|
@ -11,7 +11,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
if (passwordErr) return rej('invalid password param');
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(password, user.account.password);
|
||||
const same = await bcrypt.compare(password, user.password);
|
||||
|
||||
if (!same) {
|
||||
return rej('incorrect password');
|
||||
@ -19,8 +19,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.twoFactorSecret': null,
|
||||
'account.twoFactorEnabled': false
|
||||
'twoFactorSecret': null,
|
||||
'twoFactorEnabled': false
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -22,7 +22,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
if (newPasswordErr) return rej('invalid newPassword param');
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(currentPassword, user.account.password);
|
||||
const same = await bcrypt.compare(currentPassword, user.password);
|
||||
|
||||
if (!same) {
|
||||
return rej('incorrect password');
|
||||
@ -34,7 +34,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.password': hash
|
||||
'password': hash
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -20,7 +20,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
if (passwordErr) return rej('invalid password param');
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(password, user.account.password);
|
||||
const same = await bcrypt.compare(password, user.password);
|
||||
|
||||
if (!same) {
|
||||
return rej('incorrect password');
|
||||
@ -31,7 +31,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.token': secret
|
||||
'token': secret
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -29,12 +29,12 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
||||
// Get 'location' parameter
|
||||
const [location, locationErr] = $(params.location).optional.nullable.string().pipe(isValidLocation).$;
|
||||
if (locationErr) return rej('invalid location param');
|
||||
if (location !== undefined) user.account.profile.location = location;
|
||||
if (location !== undefined) user.profile.location = location;
|
||||
|
||||
// Get 'birthday' parameter
|
||||
const [birthday, birthdayErr] = $(params.birthday).optional.nullable.string().pipe(isValidBirthday).$;
|
||||
if (birthdayErr) return rej('invalid birthday param');
|
||||
if (birthday !== undefined) user.account.profile.birthday = birthday;
|
||||
if (birthday !== undefined) user.profile.birthday = birthday;
|
||||
|
||||
// Get 'avatarId' parameter
|
||||
const [avatarId, avatarIdErr] = $(params.avatarId).optional.id().$;
|
||||
@ -49,12 +49,12 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
||||
// Get 'isBot' parameter
|
||||
const [isBot, isBotErr] = $(params.isBot).optional.boolean().$;
|
||||
if (isBotErr) return rej('invalid isBot param');
|
||||
if (isBot != null) user.account.isBot = isBot;
|
||||
if (isBot != null) user.isBot = isBot;
|
||||
|
||||
// Get 'autoWatch' parameter
|
||||
const [autoWatch, autoWatchErr] = $(params.autoWatch).optional.boolean().$;
|
||||
if (autoWatchErr) return rej('invalid autoWatch param');
|
||||
if (autoWatch != null) user.account.settings.autoWatch = autoWatch;
|
||||
if (autoWatch != null) user.settings.autoWatch = autoWatch;
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
@ -62,9 +62,9 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
||||
description: user.description,
|
||||
avatarId: user.avatarId,
|
||||
bannerId: user.bannerId,
|
||||
'account.profile': user.account.profile,
|
||||
'account.isBot': user.account.isBot,
|
||||
'account.settings': user.account.settings
|
||||
'profile': user.profile,
|
||||
'isBot': user.isBot,
|
||||
'settings': user.settings
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -22,14 +22,14 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
if (valueErr) return rej('invalid value param');
|
||||
|
||||
const x = {};
|
||||
x[`account.clientSettings.${name}`] = value;
|
||||
x[`clientSettings.${name}`] = value;
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: x
|
||||
});
|
||||
|
||||
// Serialize
|
||||
user.account.clientSettings[name] = value;
|
||||
user.clientSettings[name] = value;
|
||||
const iObj = await pack(user, user, {
|
||||
detail: true,
|
||||
includeSecrets: true
|
||||
|
@ -26,7 +26,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
if (home) {
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.clientSettings.home': home
|
||||
'clientSettings.home': home
|
||||
}
|
||||
});
|
||||
|
||||
@ -38,7 +38,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
} else {
|
||||
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
|
||||
|
||||
const _home = user.account.clientSettings.home;
|
||||
const _home = user.clientSettings.home;
|
||||
const widget = _home.find(w => w.id == id);
|
||||
|
||||
if (widget == null) return rej('widget not found');
|
||||
@ -47,7 +47,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.clientSettings.home': _home
|
||||
'clientSettings.home': _home
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -25,7 +25,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
if (home) {
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.clientSettings.mobileHome': home
|
||||
'clientSettings.mobileHome': home
|
||||
}
|
||||
});
|
||||
|
||||
@ -37,7 +37,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
} else {
|
||||
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
|
||||
|
||||
const _home = user.account.clientSettings.mobileHome || [];
|
||||
const _home = user.clientSettings.mobileHome || [];
|
||||
const widget = _home.find(w => w.id == id);
|
||||
|
||||
if (widget == null) return rej('widget not found');
|
||||
@ -46,7 +46,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.clientSettings.mobileHome': _home
|
||||
'clientSettings.mobileHome': _home
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -30,7 +30,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}, {
|
||||
fields: {
|
||||
data: false,
|
||||
'account.profile': false
|
||||
'profile': false
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -30,7 +30,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}, {
|
||||
fields: {
|
||||
data: false,
|
||||
'account.profile': false
|
||||
'profile': false
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -100,7 +100,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
});
|
||||
|
||||
// この投稿をWatchする
|
||||
if (user.account.settings.autoWatch !== false) {
|
||||
if (user.settings.autoWatch !== false) {
|
||||
watch(user._id, note);
|
||||
}
|
||||
});
|
||||
|
@ -32,7 +32,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
},
|
||||
$or: [
|
||||
{
|
||||
'account.lastUsedAt': {
|
||||
'lastUsedAt': {
|
||||
$gte: new Date(Date.now() - ms('7days'))
|
||||
}
|
||||
}, {
|
||||
|
Reference in New Issue
Block a user