mirror of
https://github.com/wekan/wekan.git
synced 2026-01-30 21:25:17 +01:00
Migrate accounts-lockout server files to async for Meteor 3.0
- lockedUsers.js: async getLockedUsers, unlockUser, unlockAllUsers - lockoutSettings.js: async reloadAccountsLockout with findOneAsync - accounts-lockout-config.js: async startup with findOneAsync - models/lockoutSettings.js: upsert → upsertAsync
This commit is contained in:
parent
65ce948bb0
commit
b431600d32
4 changed files with 29 additions and 29 deletions
|
|
@ -1,21 +1,21 @@
|
|||
import { AccountsLockout } from 'meteor/wekan-accounts-lockout';
|
||||
import LockoutSettings from '/models/lockoutSettings';
|
||||
|
||||
Meteor.startup(() => {
|
||||
Meteor.startup(async () => {
|
||||
// Wait for the database to be ready
|
||||
Meteor.setTimeout(() => {
|
||||
Meteor.setTimeout(async () => {
|
||||
try {
|
||||
// Get configurations from database
|
||||
const knownUsersConfig = {
|
||||
failuresBeforeLockout: LockoutSettings.findOne('known-failuresBeforeLockout')?.value || 3,
|
||||
lockoutPeriod: LockoutSettings.findOne('known-lockoutPeriod')?.value || 60,
|
||||
failureWindow: LockoutSettings.findOne('known-failureWindow')?.value || 15
|
||||
failuresBeforeLockout: (await LockoutSettings.findOneAsync('known-failuresBeforeLockout'))?.value || 3,
|
||||
lockoutPeriod: (await LockoutSettings.findOneAsync('known-lockoutPeriod'))?.value || 60,
|
||||
failureWindow: (await LockoutSettings.findOneAsync('known-failureWindow'))?.value || 15
|
||||
};
|
||||
|
||||
const unknownUsersConfig = {
|
||||
failuresBeforeLockout: LockoutSettings.findOne('unknown-failuresBeforeLockout')?.value || 3,
|
||||
lockoutPeriod: LockoutSettings.findOne('unknown-lockoutPeriod')?.value || 60,
|
||||
failureWindow: LockoutSettings.findOne('unknown-failureWindow')?.value || 15
|
||||
failuresBeforeLockout: (await LockoutSettings.findOneAsync('unknown-failuresBeforeLockout'))?.value || 3,
|
||||
lockoutPeriod: (await LockoutSettings.findOneAsync('unknown-lockoutPeriod'))?.value || 60,
|
||||
failureWindow: (await LockoutSettings.findOneAsync('unknown-failureWindow'))?.value || 15
|
||||
};
|
||||
|
||||
// Initialize the AccountsLockout with configuration
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { ReactiveCache } from '/imports/reactiveCache';
|
|||
|
||||
// Method to find locked users and release them if needed
|
||||
Meteor.methods({
|
||||
getLockedUsers() {
|
||||
async getLockedUsers() {
|
||||
// Check if user has admin rights
|
||||
const userId = Meteor.userId();
|
||||
if (!userId) {
|
||||
|
|
@ -17,7 +17,7 @@ Meteor.methods({
|
|||
const currentTime = Number(new Date());
|
||||
|
||||
// Find users that are locked (known users)
|
||||
const lockedUsers = Meteor.users.find(
|
||||
const lockedUsers = await Meteor.users.find(
|
||||
{
|
||||
'services.accounts-lockout.unlockTime': {
|
||||
$gt: currentTime,
|
||||
|
|
@ -32,7 +32,7 @@ Meteor.methods({
|
|||
'services.accounts-lockout.failedAttempts': 1
|
||||
}
|
||||
}
|
||||
).fetch();
|
||||
).fetchAsync();
|
||||
|
||||
// Format the results for the UI
|
||||
return lockedUsers.map(user => {
|
||||
|
|
@ -50,7 +50,7 @@ Meteor.methods({
|
|||
});
|
||||
},
|
||||
|
||||
unlockUser(userId) {
|
||||
async unlockUser(userId) {
|
||||
// Check if user has admin rights
|
||||
const adminId = Meteor.userId();
|
||||
if (!adminId) {
|
||||
|
|
@ -62,13 +62,13 @@ Meteor.methods({
|
|||
}
|
||||
|
||||
// Make sure the user to unlock exists
|
||||
const userToUnlock = Meteor.users.findOne(userId);
|
||||
const userToUnlock = await Meteor.users.findOneAsync(userId);
|
||||
if (!userToUnlock) {
|
||||
throw new Meteor.Error('error-user-not-found', 'User not found');
|
||||
}
|
||||
|
||||
// Unlock the user
|
||||
Meteor.users.update(
|
||||
await Meteor.users.updateAsync(
|
||||
{ _id: userId },
|
||||
{
|
||||
$unset: {
|
||||
|
|
@ -80,7 +80,7 @@ Meteor.methods({
|
|||
return true;
|
||||
},
|
||||
|
||||
unlockAllUsers() {
|
||||
async unlockAllUsers() {
|
||||
// Check if user has admin rights
|
||||
const adminId = Meteor.userId();
|
||||
if (!adminId) {
|
||||
|
|
@ -92,7 +92,7 @@ Meteor.methods({
|
|||
}
|
||||
|
||||
// Unlock all users
|
||||
Meteor.users.update(
|
||||
await Meteor.users.updateAsync(
|
||||
{ 'services.accounts-lockout.unlockTime': { $exists: true } },
|
||||
{
|
||||
$unset: {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { ReactiveCache } from '/imports/reactiveCache';
|
|||
import LockoutSettings from '/models/lockoutSettings';
|
||||
|
||||
Meteor.methods({
|
||||
reloadAccountsLockout() {
|
||||
async reloadAccountsLockout() {
|
||||
// Check if user has admin rights
|
||||
const userId = Meteor.userId();
|
||||
if (!userId) {
|
||||
|
|
@ -17,15 +17,15 @@ Meteor.methods({
|
|||
try {
|
||||
// Get configurations from database
|
||||
const knownUsersConfig = {
|
||||
failuresBeforeLockout: LockoutSettings.findOne('known-failuresBeforeLockout')?.value || 3,
|
||||
lockoutPeriod: LockoutSettings.findOne('known-lockoutPeriod')?.value || 60,
|
||||
failureWindow: LockoutSettings.findOne('known-failureWindow')?.value || 15
|
||||
failuresBeforeLockout: (await LockoutSettings.findOneAsync('known-failuresBeforeLockout'))?.value || 3,
|
||||
lockoutPeriod: (await LockoutSettings.findOneAsync('known-lockoutPeriod'))?.value || 60,
|
||||
failureWindow: (await LockoutSettings.findOneAsync('known-failureWindow'))?.value || 15
|
||||
};
|
||||
|
||||
const unknownUsersConfig = {
|
||||
failuresBeforeLockout: LockoutSettings.findOne('unknown-failuresBeforeLockout')?.value || 3,
|
||||
lockoutPeriod: LockoutSettings.findOne('unknown-lockoutPeriod')?.value || 60,
|
||||
failureWindow: LockoutSettings.findOne('unknown-failureWindow')?.value || 15
|
||||
failuresBeforeLockout: (await LockoutSettings.findOneAsync('unknown-failuresBeforeLockout'))?.value || 3,
|
||||
lockoutPeriod: (await LockoutSettings.findOneAsync('unknown-lockoutPeriod'))?.value || 60,
|
||||
failureWindow: (await LockoutSettings.findOneAsync('unknown-failureWindow'))?.value || 15
|
||||
};
|
||||
|
||||
// Initialize the AccountsLockout with configuration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue