Estado de inicio de sesión/salida del sitio de contenido
Login \ Logged-out detecting
Our systems are hosted on our servers and implemented in your content site.
The developer should add a script to the content site, looking for the cookie to determine the login/logout status of the user.
so how can we detect user Login?
The trading platform automatically set 2 cookies in the user browser when he logs in to our systems (regardless if he did a login the the trading platform itself or thru a widget in the content site)
these 2 cookies are named:
username
userID
username will contains the user-name that is set in the trading platform system for that user, userID contains a unique number which is the user-id in the trading platform system.
by checking for the existence of these 2 cookies we can know if the user is logged in or logged out and according to that display different relevant content in the content site.
E.G if we know a user is logged in, instead of the “log-in” button in the content site we can display the user name with a welcome back message and a relevant menu for logged in user with useful links such as link to the user-account-setting in the trading platform .
here is an example for a server side (PHP) check for a user login in a wordpress content site:
// check if user already logged in to platform
function set_platform_login(){
if(defined('TS_LOGIN')) {
return;
}
if( isset($_COOKIE['userID'], $_COOKIE['username']) ){
define('TS_LOGIN', true);
// echo('<h1>test loged in</h1>');
} else {
define('TS_LOGIN', false);
}
}
if you are using wordpress you can implement this code in your theme functions.php file and later call it with:
add_action('set_login', 'set_platform_login');
do_action('set_login');
you can also get the username from the cookie and use it later like so:
function set_platform_username($logged_in){
if(defined('TS_USER')) {
return;
}
if($logged_in){
define('TS_USER', html_entity_decode($_COOKIE['username']) );
} else {
define('TS_USER', '');
}
}
set_platform_username(TS_LOGIN);
after a user is logged in you can generate a relevant menu for logged in users.
Another option you have is to do the Login \ logged out check on the client side,
using javascript or jquery you can check for the for the 2 cookies :
function genMenu() {
var theme = 'yourtheme';
var _user = getCookie('username');
var _id = getCookie('userID');
if (_user != undefined && _id != undefined) {
// Do all relevant code for logged in users here, E.G generate a logged-in menu,
// display or hide html elements \ call other functions....
}
else {
// Do all relevant code for logged-out users here
}
}
To Logout - simple use the following link - https://bpw.yoursite.com/index/sign-out?redirectUrl=https://www.yoursite.com/