The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Logout Redirect: to a link of your choice!

View previous topic View next topic Go down

Logout Redirect: to a link of your choice!

Post by JScript on 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
avatar
JScript
Forumember

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

http://jscript.forumeiros.com/

Back to top Go down

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

Post by Ange Tuteur on 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
avatar
Ange Tuteur
Forumaster

Male Posts : 13179
Reputation : 2884
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

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

Post by JScript on 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: http://help.forumotion.com/t141384-logout-redirect-to-a-link-of-your-choice#962688

JS
avatar
JScript
Forumember

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

http://jscript.forumeiros.com/

Back to top Go down

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

Post by Niko on 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
avatar
Niko
Hyperactive

Male Posts : 2298
Reputation : 98
Language : English, French, Italian, Spanish, Latin

Back to top Go down

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

Post by JScript on 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: http://help.forumotion.com/t141384-logout-redirect-to-a-link-of-your-choice#962688

JS
avatar
JScript
Forumember

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

http://jscript.forumeiros.com/

Back to top Go down

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

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

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


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

avatar
SLGray
Administrator
Administrator

Male Posts : 41162
Reputation : 2813
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


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