@doron-alkalay @yisrael-wix @giri-zano @lmeyer @russian-dima @jim75924 Good morning, I have a question, on my page there is a menu in which by means of a button links to a login this login works perfectly which directs to another page, my question is the following, that page which directs the login is not linked to the menu therefore to access said page it is necessary to go through the login again which becomes somewhat tedious, what I am looking for is to make a kind of timer in the login of a period of 5 minutes which allows me to navigate through the site pages including the page which links the login without the need to log in periodically, could you help me
I already have seen your post some days ago → normaly i do read every single post in the Velo-Forum.
Why (personal me) did not give any response on it?
Because i did not really understand the issue.
How ever. Please navigate to my profile and take a look onto the Last of my posts, which are disscussing about LOGIN-SYSTEM (especially Timer-Intervall).
There you perhaps will also find some ideas how to solve your problem.
My problem is, in the menu section it is linked to the login and this to another page what I am looking for is to press the menu that directs me to the login but without logging in, if not that it directly directs me to the page for a certain time that respects me the login
I already checked the Timer-Intervall publications but it is not clear to me in which part of my code I should put what is indicated, could you help me with that please
What i do not understand is → why it is not possible in your setup to navigate to another page, when a user is not logged in?
if you can navigate through all the pages of the site, on all pages there is a horizontal menu, a button from that menu leads to the login page (page “X”) that the login leads to another page (page " And “which cannot be accessed from horizontal menu without going through login) what I’m looking for is … somehow navigate the pages, including login, but send me to page” Y "without the need for the user to log in again to be directed to page “Y”, in short I want the login that the user made previously to be respected for a specific time.
Help me please
I am at home in about 20min.
In the meanwhile try to explain more.
Show all elements on a screenshot which are involved.
Show also your wished end-result.
I also don’t understand the problem without more information. Screenshots of your site would help to visualize.
How do your users sign up? Please share the code.
How do your users login? Please share the code.
To me it sounds like you link to a login page , rather than setting certain pages to be “member only”, which would automatically prompt the login and keep a user logged in.
Did you set your custom signup and login pages using the instructions found in the links below?
https://support.wix.com/en/article/velo-tutorial-creating-a-custom-registration-form-with-code
This post also provides a very clear roadmap on how to set things up properly.
https://www.wix.com/velo/forum/coding-with-velo/custom-login-1
I have a small login previously created by code connected to a dataset, this is my horizontal menu that directs the login through the button (page “X”)
Once the correct data has been entered at the beginning of the session, it is passed to another page which is not linked to the menu as can be seen and which is accessed only through the login.(page “Y”)
You can navigate through the other pages of the site through the menu, but if you want to return to page “Y”, you must go through page “X” again, which is the login. What I am looking for is that once the user logs in to go to page “Y” when browsing the other pages and wanting to return to page “Y” he does not have to spend all the time on page “X”, this I look for it in a certain way for a certain time as a kind of login expiration that after a while (5 minutes) they have to go through page “X” again to see page “Y”
If you explain me better with the captures
When i take a look onto the given screenshot i see just some kind of chaos.
And i also do not recognize → where is your real login-process?
https://www.wix.com/velo/reference/wix-users/login
Let us first make clear your login-setup.
- You are using your own Login-System ?
- You do not use the wix-login ?
- You have your own DATABASE for your login-functionality → " logingers "?
- You never have installed the wix-members-app?
- Why you want to go this way?
- Using PASSWORD on frontend? → Sure that you want to go this very risky and unsecure way?
Before you continue to run into wrong direction (as i would say you do it right now), please make some thoughts about security risks and which disatvantages you would have if you would continue to create your own login-system.
Your DISATVANTAGES would be:
-you never will have a real log-in connect to the wix-platform.
-either you will be able to interact with the wix-crm, completely…
-nor you want be able to work with the PMD (PrivateMembersDatabase).
-when you later want to use some wix-stuff like → BADGES or ROLES, you simply won’t be able to do that.
-and there will be a lot of other apps and tools, you won’t be able to connect with your own login.
At least you have to register + login to Wix-CRM to use all functionalities by CODE.
How to improve your Login-System?
-
Your first step would be to create the Login-Design (Form) → Already done by you…
-
Creating the code for login (real login to wix, not just a check-result out of your own DB).
import wixUsers from 'wix-users';
let email = $w("#email").value;
let password = $w("#password").value;
wixUsers.login(email, password)
.then(()=> {console.log("User is logged in");})
.catch((err)=> {console.log(err);});
Of course you can use your own DB aswell → but your DB should be additionaly → you still can store all needed DATA in your own DB, collected either during the registration process or during login.
If you want to make it even more secure, than you will do your LOGIN-PROCESS on the → BACKEND!
https://www.wix.com/velo/reference/wix-users-backend/login
import wixUsersBackend from 'wix-users-backend';
export function myBackendFunction(email, password) {
return wixUsersBackend.login(email, password)
.then( (sessionToken) => {
return {sessionToken, "approved": true};
}).catch((error)=> {return {"approved": false, "reason": error};});
}
By the way → How do look like your registration process???
Please show your code in a good formated CODE-BLOCK (like shown by my examples).
Registration-process from BACKEND…
https://www.wix.com/velo/reference/wix-users-backend/register
from Frontend…
https://www.wix.com/velo/reference/wix-users/register
You have a not very well thought out concept, so try to improve it right from the beginning.
You also do not have to install the Wix-Members-App as i can remember.
You can use Wix-CRM, where all your registered CONTACTS can be found after registration-process (not proved, but as i can remember it is working like that).
If i am wrong → then install the Wix-Members-App, which will also install the PMD (public+private) → you will find inside your DATABASE-MANAGER.
To check if a USER is already logged in to give this current logged-in user more opertunities and options → you can check it → using this one…
https://www.wix.com/velo/reference/wix-users/currentuser
So now you know, who is logged in.
To take some actions after LOGIN-PROCESS you can use this one…
import wixUsers from 'wix-users';
wixUsers.onLogin( (user) => {
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role; // "Member"
} );
And alwaays think about SECURITY (backend or frontend)?
Should i continue or stop???
Perhaps you also read this first, before continuing…
@russian-dima well i tried to do it like this as i dont require a registration just a login as user data will be stored manually in a dataset it is true now with what it tells me i didnt include some security. Could you tell me what the code would look like taking the security you mentioned, my dataset, and the items for login please?
what fragments would be added to my code above
could you help me with this please
If you want still to go your own way, by using your own DATABASE (logingers), i would you suggest to do the following.
1) Secure your DATABASE first when you start to publish your project.
2) Especially secure your PASSWORD-FIELD inside your DB → by setting it’s TYPE to → PASSWORD in the setup-options.
3) Since you do not need any registration-process, you automaticaly won’t have any contacts (or you create them manualy).
4) That also means, that now your code make more sence. You do not have any registration process → so you also do not need to log-in anywhere, because you are using your own separated custom-login-system.
5) So your SETUP is more simple than i thought! All you have is a DATABASE with 2-DB-FIELDS inside (email+password).
6) You have logicaly a FORM with 2-form-inputs → PW+eMail connected to a DATASET and DATASET connected to DB(logingers).
- Now your code seems to be more understandable…
8) What i do not understand → are the connections to your DATASET, although you do not use them! Instead you are using → Wix-Data-Query!
PLEASE PROVIDE FULL CODE → NOT shown in a PIC → USE a CODE-BLOCK!
Flow:
1) Click on Button-1 → starts the check-Function to check for existing entries in your → logingers -DATABASE.
2) If something found in DB → navigation to → eventos
3) Else —> open Lightbox with some error-message
How do look like your → eventos-page ???
Is that your eventos-page…
Till here, everything right?
import wixWindow from 'wix-window';
import wixData from "wix-data"
import wixLocation from "wix-location"
$w.onReady(() => {
$w("#button1").onClick(async () => {
let email = $w("#email").value
let contrasena = $w("#contrasena").value
await checkLogin(email, contrasena)
})
})
async function checkLogin(email, contrasena) {
const query = await wixData
.query("logingers")
.eq("title", email)
.eq("contrasena", contrasena)
.find()
if (query.items.length > 0) {
wixLocation.to("/eventos")
} else {
//$w( "#text8" ).show()
wixWindow.openLightbox('loginwarn');
//console.error("Email/Contrasena wrong!")
}
}
This is my code
In fact, that is my event page, which is reached after login.
Could you tell me how to achieve this step?
- Click on Button-1 → starts the check-Function to check for existing entries in your → logingers-DATABASE.
in my database in the password field there is no type “password”, I show
in my input if I have data type “password”
That I modify my code to be able to achieve that the session recognizes me and that when pressing the button events of my menu it sends me directly to my page of events without going through the login ?
In your case all you have to do is to use the wix-storage (session or local).
I wanted to suggest you this solution already right from the beginning, but since your DESCRIPTION was VERY VERY BADLY UNDERSTANDABLE, i hesitated.
How ever! When you do your login-process …
async function checkLogin(email, contrasena) {
const query = await wixData
.query("logingers")
.eq("title", email)
.eq("contrasena", contrasena)
.find()
if (query.items.length > 0) {
wixLocation.to("/eventos")
} else {
//$w( "#text8" ).show()
wixWindow.openLightbox('loginwarn');
//console.error("Email/Contrasena wrong!")
}
}
And if your login is successful → save VALUE inside wix session (be informed → security risks again), so you can get your data out of the wix-storage back again when you need it.
For example you set a flag → “ONLINE” into wix-storage.
Something like this one… just some quick example-code…
$w.onReady(() => {
$w("#button1").onClick(async () => {
let onlineState = wixStorage.session.getItem("onlineState");
if(onlineState === "true") {
wixLocation.to("/eventos")
}
else {
let email = $w("#email").value
let contrasena = $w("#contrasena").value
await checkLogin(email, contrasena, onlineState)
}
})
})
async function checkLogin(email, contrasena) {
const query = await wixData
.query("logingers")
.eq("title", email)
.eq("contrasena", contrasena)
.find()
if (query.items.length > 0) {
let onlineState = wixStorage.session.setItem("onlineState", "true")
wixLocation.to("/eventos")
} else {
//$w( "#text8" ).show()
wixWindow.openLightbox('loginwarn');
//console.error("Email/Contrasena wrong!")
}
}
- your thoughts about the 5min of onlineTimeExpiration and it could work.
I already corrected the above, it only marks error in this, how do I solve it?
Apparently, according to me, I already corrected the error, it indicated that I only received 2 parameters, not 3, was what I did correct? If so, it does not work, it still does not recognize the session, it will be because the login page is linked to the menu button? , but this allows me to show the login, what can I do?
Sorry, yesterday i was overloaded and tired. Programming at 4:00am is surely not the best idea .
import wixStorage from 'wix-storage';
import wixLocation from 'wix-location';
import wixData from 'wix-data';
var onlineState
$w.onReady(() => {
setInterval(logOut, (5*1000*60)); // --> LOGOUT every 5min
$w("#button1").onClick(async () => {
//getting online-status...
onlineState = wixStorage.session.getItem("onlineState");
if(onlineState === "true") {
wixLocation.to("/eventos")
}
else {
let email = $w("#email").value
let contrasena = $w("#contrasena").value
await checkLogin(email, contrasena)
}
})
})
function logOut() {onlineState === "false";
//setting online-status...
wixStorage.session.setItem("onlineState", "false");
}
async function checkLogin(email, contrasena) {
wixData.query("logingers")
.eq("title", email)
.eq("contrasena", contrasena)
.find()
.then((res)=>{
if (res.items.length > 0) {//setting online-status...
wixStorage.session.setItem("onlineState", "true");
wixLocation.to("/eventos")
} else {
wixWindow.openLightbox('loginwarn');
console.error("Email/Contrasena wrong!")
}
});
}
So give it a second try…(i did not test it, but should do the job).
So this is just an simple example. You should continue to work on it and improve it a lot.
-improving security
-improving functionality
-improving flexibility
and so on…
Now you have also a Timer, which will set your ONLINE-state to OFFLINE after every 5min.
You log-in → you will always redirect automatically to → EVENTOS during that time of 5min, from your current login page → no manually login needed.
When ONLINE-TIME is expired, you will have to log-in again and renew/refill the ONLINE-TIME again for automatic redirection.
So the rest of your issue you will have to solve by your own.
Use the shown technique, to expand your own functionalities.
Good luck with your project! And don’t forget to like it, if you really liked it
@russian-dima Good morning, I already tried the code that indicates me and it still does not respect the start of the session, apparently it does not mark any error, but even when I start the session it directs me to the events page I continue browsing the site I return through the menu to see the Events page and it still shows me the login so that I can log in again
how can we do that