The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Logout Redirect: to a link of your choice!

4 posters

Go down

Logout Redirect: to a link of your choice! Empty Logout Redirect: to a link of your choice!

Post by JScript June 18th 2015, 5:00 pm

Hello everybody!

What if we can redirect the logout to a specific link determined by us?
It's easy, see the code below!

In your ACP: Modules -> HTML&JAVASCRIPT -> JavaScript codes management -> [Create a new JavaScript]
Title *: <- Whatever you want
Placement : <- In all the pages
Javascript Code * : <- Select, copy and paste the code below in this field:
Code:

/***
 * Application: LogoutRedirect.js
 * Description: Logout redirect to a link of your choice!
 * Version: 0.02282015-jq1.9.1
 *         RC1 (Release candidate 1!) - ébé
 * Author: JScript - 2015/02/28
 * Copyright (c) 2015 JScript <jscriptbrasil at live dot com>
 * This work is free. You can redistribute it and/or modify it
 * under the terms of the WTFPL, Version 2
 */
var LogoutRedirect = '/portal' ; // <- Change the link for what you want!

if (localStorage.getItem("logout")) {
   localStorage.removeItem("logout");
   location.href = LogoutRedirect;
};
jQuery(function() {
   if (!_userdata.session_logged_in) {
      return false;
   }
   var _ToolBar = setInterval(function() {
      if (document.getElementById('fa_welcome') !== null) {
         clearInterval(_ToolBar);
         jQuery('a[href$="logout=1"]').attr('href', jQuery('#logout').attr('href'));

         jQuery('a[href*="logout=1"]').click(function(event) {
            localStorage.setItem("logout", 1);
         });
      }
   }, 1000);
});

I await your feedback,

JS
JScript
JScript
Forumember

Male Posts : 741
Reputation : 175
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Logout Redirect: to a link of your choice! Empty Re: Logout Redirect: to a link of your choice!

Post by Ange Tuteur June 18th 2015, 7:54 pm

It's not a bad Idea. I was wondering, wouldn't it be better to just use cookies instead of localStorage ? This way older browsers that don't support the Storage API can also make use of this plugin.

I also noticed that LogoutRedirect had a global scope when you can simply wrap it in an anonymous function to keep it local, unless there was a reason it needed to be global ? Lastly would be the polling for the toolbar; I found that initiating a second document ready event applies what you need as soon as the toolbar ( and sceditor ) are ready.

This would be my suggestion to improving it :
Code:
// use an anonymous function so our variables have a local scope
(function() {
  // startup variables
  var redirection = '/t1-', // redirect link
      logout, // logout link
      menu, // toolbar menulist
      setState = function() { my_setcookie('faLogout', 'true') }; // set the cookie state
 
  // if the cookie isn't empty, redirection will occur
  if (my_getcookie('faLogout')) {
    my_setcookie('faLogout', ''); // empty the cookie
    window.location.href = redirection; // redirect the user
  }
 
  // execution for when the document is ready
  $(function() {
    if (!_userdata.session_logged_in) return; // return if the user is logged out
   
    logout = document.getElementById('logout'); // get and set the logout button
    logout.onclick = setState; // set the cookie on click
   
    // ecxecution for when the toolbar is ready
    $(function() {
      menu = document.getElementById('fa_menulist'); // get and set the menulist
     
      // if the menu isn't null, the following will be executed
      if (menu) {
        menu = menu.lastChild.firstChild; // change the menu to the logout option
        menu.href = logout.href; // change the href so the tid and key can initiate an instant logout
        menu.onclick = setState; // set the cookie on click
      }
    });
  });
})();

I like this overall Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Logout Redirect: to a link of your choice! Empty Re: Logout Redirect: to a link of your choice!

Post by JScript June 18th 2015, 8:10 pm

@Ange Tuteur
Yes, a great improvement, very good!!!

That's what we need: Discuss and make improvements in the codes!!!

So far the best change: https://help.forumotion.com/t141384-logout-redirect-to-a-link-of-your-choice#962688

JS
JScript
JScript
Forumember

Male Posts : 741
Reputation : 175
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Logout Redirect: to a link of your choice! Empty Re: Logout Redirect: to a link of your choice!

Post by Niko June 18th 2015, 8:54 pm

Hello @JScript

nice resource I must tell Wink

just a little "suggestion".. it could be useful to have this redirect even on login Very Happy
maybe an admin wants its member to be redirected to an html page after the login

what do you think? Hide
Niko
Niko
Helper
Helper

Male Posts : 3097
Reputation : 244
Language : English, Italian, French
Location : Italy

https://www.fmcodes.net/

Back to top Go down

Logout Redirect: to a link of your choice! Empty Re: Logout Redirect: to a link of your choice!

Post by JScript June 18th 2015, 8:56 pm

@Niko
A great idea, that would be the reverse of the actual code or we can merge all?


So far the best change: https://help.forumotion.com/t141384-logout-redirect-to-a-link-of-your-choice#962688

JS
JScript
JScript
Forumember

Male Posts : 741
Reputation : 175
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Logout Redirect: to a link of your choice! Empty Re: Logout Redirect: to a link of your choice!

Post by SLGray February 23rd 2017, 8:05 am

This will no longer be supported by JScript: https://help.forumotion.com/t151137-in-memory-of-jscript-joao-carlos.


Logout Redirect: to a link of your choice! Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51452
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum