Talking about this:
Create a DB for your Warning and Ban-System.
-warnings
-bans
-user-ID
-expiration-date of ban
Generate a function in your login, which will check for example for setted bans and their expiration-date for every single user.
If an an active ban exist for the user who tries to log-in, the login automaticaly denies the login.
Perhaps you also take a look here, and read LMayer suggestion, could also be helpful in your case.
Thx! I’ll try it
Hi there …
As @russian-dima suggested, you need a DB to store your members data, I suggest these fields:
-
name : ( Text ) Store the member’s name in this field.
-
owner : ( Reference Field ) A reference field to the built-in members database.
-
bans : ( Array ) an array of objects of the bans.
-
warnings : ( Array ) an array of objects of the warnings.
On the page or lightbox you use to let your members login, shift your login code to the backend, and when users attempts to login, check against the warnings DB, and redirect them to the appropriate page/lightbox if necessary, or login them in if everything is fine.
Backend: login.jsw
import { login } from 'wix-users-backend';
import wixData from 'wix-data';
export async function login(email, password) => {
try {
const login_res = await login(email, password).then((x) => {
return { type: 'success', token: x }
}).catch(() => {
return { type: 'error', message: 'Your email or password are incorrect' }
})
if (login_res.type === 'success') {
return checkMember(email).then((status) => {
if (status.clean) {
return { ok: true, token: login_res.token }
} else {
return { ok: false, type: status.type, time: status.remaining }
}
})
} else {
throw new Error(login_res.message)
}
} catch(message) {
return Promise.reject({ type: 'error', message });
}
}
// Get the member by its email address
async function getMemberByEmail(email) {
try {
// get the member
const member = await wixData.query('Members/PrivateMembersData')
.eq('loginEmail', email)
.find({suppressAuth: true})
.then((x) => { return x.items[0] });
if (member) {
return Promise.resolve(member);
} else {
throw new Error('Unable to find the member');
}
} catch(message) {
return Promise.reject({ type: 'error', message });
}
}
// Check the membership status of a member via its email
function checkStatus(member_id) {
return wixData.query('Details').eq('owner', member_id).find({suppressAuth: true}).then(x => {
if (x.length > 0) {
const member = x.items[0];
if (member.bans && member.bans.length > 0) {
// Sort the items in this array by their creation date
// .... Sort here.
/* Filter the array to only return the items where the
ban is less than 3 days old, check how long remains
and resolve this promise with a "clean: false" and
and remaining is the time difference between the current
time and the creation time */
const bans = []; // New array for the active bans
if (bans.length > 0) {
return Promise.resolve({
clean: false,
type: 'ban',
remaining: <time left>
})
}
}
if (member.warnings && member.warnings.length > 0) {
// Do the same as the above, make the necessary changes.
}
}
// return a default ok response;
return { clean: true }
})
}
// A function to do what the above two functions do
async function checkMember(email) {
try {
const member = await getMemberByEmail(email);
return checkStatus(member._id);
} catch (err) {
return Promise.reject(err);
}
}
On your login page:
import { login } from 'backend/login.jsw';
import { applySessionToken } from 'wix-users';
// Inside the event of the login event's trigger;
$w('#loginBtn').onClick(() => {
cosnt email = $w('#email').value.toLowerCase();
const pass = $w('#password').value;
return login(email, pass).then((result) => {
if (result.ok) {
// if everything is okay, login the user in
applySessionToken(result.token);
} else {
/* If the code reaches this stage, that means a ban or warning
has been set on this account, now you decide what you want
to do */
const type = result.type; // Either "ban" or "warning".
const remaining = result.remaining; // the number of milliseconds left;
}
})
});
Hope this long answer helps.
Ahmad
Interesting! I should take a look on it. Perhaps i will need this soon, too
@w11
Are you using an APP ?
Is this DATABASE created by you, or automaticaly by an installed APP ?
@russian-dima I’m using Wix.com and it’s manual. I’m on chrome and took this from my mobile device. I added it myself.
@w11
As me and Ahmad already mentioned, in this created (by your own) DB, you will store every single STATE of all your MEMBERS/USERS.
Suggested DB-Fields by me:
-warnings
-bans
-user-ID
-expiration-date of ban
Suggested DB-Fields by Ahmad:
-
name : ( Text ) Store the member’s name in this field.
-
owner : ( Reference Field ) A reference field to the built-in members database.
-
bans: ( Array ) an array of objects of the bans.
-
warnings: ( Array ) an array of objects of the warnings.
First create your DB, perhaps later you will recognise what the DB is for.
Store some values manualy into DB and try to imagine how it could work.
There are many ways how to setup your DB. Make the best choice for you.
Then read again Ahmads good and detailed described post again. Try to reconstruct all suggested steps → STEP by STEP!
@w11 I explained why we need this collection.
@russian-dima looking forward to see what you’ve built when you’re done
@ahmadnasriya I think he meant what is it for. Like “site content”, “members data”, etc,
@everythingcode954885 it should be a private data, it’s only meant to be accessed on the server, neither users should have access to it nor its data should be returned to the frontend anyway.