Added account update form and e-mail verification.
This commit is contained in:
+4
-33
@@ -14,7 +14,7 @@ function curateTemplate(template) {
|
||||
};
|
||||
}
|
||||
|
||||
export function curateUser(user, reqUser) {
|
||||
export function curateUser(user, reqUser, options = {}) {
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ export function curateUser(user, reqUser) {
|
||||
role: user.role,
|
||||
abilities: [...user.role_abilities || [], ...user.abilities || []],
|
||||
createdAt: user.created_at,
|
||||
...(reqUser?.id === user.id ? privateUser : null),
|
||||
...(reqUser?.id === user.id || options.includePrivate ? privateUser : null),
|
||||
};
|
||||
|
||||
return curatedUser;
|
||||
@@ -63,7 +63,7 @@ export async function fetchUser(userId, options = {}, reqUser) {
|
||||
.groupBy('users.id', 'users_roles.role')
|
||||
.first();
|
||||
|
||||
if (!user) {
|
||||
if (!user && options.throwError !== false) {
|
||||
throw new HttpError(`User '${userId}' not found`, 404);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export async function fetchUser(userId, options = {}, reqUser) {
|
||||
return { user };
|
||||
}
|
||||
|
||||
return curateUser(user, reqUser);
|
||||
return curateUser(user, reqUser, options);
|
||||
}
|
||||
|
||||
export async function fetchUserTemplates(reqUser) {
|
||||
@@ -136,32 +136,3 @@ export async function createBan(ban, reqUser) {
|
||||
|
||||
await knex('bans').insert(curatedBan);
|
||||
}
|
||||
|
||||
const validSettingKeys = [
|
||||
'alertNotificationsEnabled',
|
||||
'alertEmailsEnabled',
|
||||
'alertEmailsFrequency',
|
||||
];
|
||||
|
||||
export async function updateSettings(settings, reqUser) {
|
||||
if (!reqUser) {
|
||||
throw new HttpError('You need to be authenticated to change your settings', 401);
|
||||
}
|
||||
|
||||
const invalidKeys = Object.keys(settings).filter((key) => !validSettingKeys.includes(key));
|
||||
|
||||
if (invalidKeys.length > 0) {
|
||||
throw new HttpError(`Invalid settings: ${invalidKeys.join()}`, 400);
|
||||
}
|
||||
|
||||
if (settings.alertEmailsFrequency && !['instant', 'daily', 'weekly', 'monthly'].includes(settings.alertEmailsFrequency)) {
|
||||
throw new HttpError('Invalid email frequency setting', 400);
|
||||
}
|
||||
|
||||
const [{ settings: updatedSettings }] = await knex('users')
|
||||
.where('id', reqUser.id)
|
||||
.update('settings', knex.raw('coalesce(settings, \'{}\'::jsonb) || ?::jsonb', [JSON.stringify(settings)]))
|
||||
.returning('settings');
|
||||
|
||||
return updatedSettings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user