Peter Knight Posted January 23, 2018 Share Posted January 23, 2018 I have been around the forums on this and can't seem to find my answer. I want to create a html link that forces a user logout. I've seen $session->logout() but I'm not sure how to use it with <a href="#">Logout<a/> This seems to work (my own hack) from inspecting the admin logout link. Just not sure it's the official way <a href="/processwire/login/logout">Logout<a/> Link to comment Share on other sites More sharing options...
flydev Posted January 23, 2018 Share Posted January 23, 2018 Just logout then redirect the user : $session->logout(); $session->redirect("./"); And you could write a GET variable ?logout=1 in your link then check this var to logout the user. if($input->get->logout) { $session->logout(); $session->redirect('./'); } else { $out = "<p>You are logged in. <a href='./?logout=1'>Logout</a></p>"; } 2 Link to comment Share on other sites More sharing options...
bernhard Posted January 23, 2018 Share Posted January 23, 2018 6 hours ago, Peter Knight said: This seems to work (my own hack) from inspecting the admin logout link. Just not sure it's the official way <a href="/processwire/login/logout">Logout<a/> I would not call it a hack if you found it in the official admintheme It's totally fine. What happens is that you execute the executeLogout() method in the ProcessLogin module: https://github.com/processwire/processwire/blob/master/wire/modules/Process/ProcessLogin/ProcessLogin.module#L195-L210 This is from the admin: echo "<li><a href='{$config->urls->admin}login/logout/'><i class='fa fa-fw fa-power-off'></i> " . $this->_('Logout') . "</a></li>"; Link to comment Share on other sites More sharing options...
Robin S Posted January 24, 2018 Share Posted January 24, 2018 3 hours ago, bernhard said: I would not call it a hack if you found it in the official admintheme It's totally fine. I think @Peter Knight might be talking about logging out a front-end user, in which case you might not want to expose the admin login URL to those users. I usually create a dedicated template and page /logout/ for the purpose. 1 Link to comment Share on other sites More sharing options...
adrian Posted January 24, 2018 Share Posted January 24, 2018 17 minutes ago, Robin S said: I usually create a dedicated template and page /logout/ for the purpose Me too. 1 Link to comment Share on other sites More sharing options...
bernhard Posted January 24, 2018 Share Posted January 24, 2018 7 hours ago, Robin S said: I think @Peter Knight might be talking about logging out a front-end user, in which case you might not want to expose the admin login URL to those users. This "might" be true. But since the user is already logged in he "might" already know the admin url - where else would he have logged himself in?! But you are right, if one wants to hide the admin url for whatever reason a dedicated template or a get variable as flydev posted would be a solution. 7 hours ago, Robin S said: I usually create a dedicated template and page /logout/ for the purpose. usually? sounds like you need that often?! may i ask for which purposes? I've never needed that so I'm curious thanks Link to comment Share on other sites More sharing options...
Robin S Posted January 24, 2018 Share Posted January 24, 2018 3 minutes ago, bernhard said: But since the user is already logged in he "might" already know the admin url - where else would he have logged himself in?! Via a custom front-end login form. I think that's how most of us have been dealing with front-end logins (until the LoginRegister module came along - I haven't had the chance to use it yet). 6 minutes ago, bernhard said: usually? sounds like you need that often?! may i ask for which purposes? Well, it's not unusual. Guess it depends how many sites you build that service front-end users. 1 Link to comment Share on other sites More sharing options...
bernhard Posted January 24, 2018 Share Posted January 24, 2018 I wanted to mention custom frontend logins... don't know why I didn't. Maybe because this would have answered my own question... 4 minutes ago, Robin S said: Well, it's not unusual. Guess it depends how many sites you build that service front-end users. Ok, that count is 0 here maybe that's why it took me a little long to get your point ^^ since the pw admin is so easy I've just not had the need to build a custom login/logout/admin for my users... Last time I did it was when I was using Joomla and this was fortunately long, long time ago Link to comment Share on other sites More sharing options...
Robin S Posted January 24, 2018 Share Posted January 24, 2018 1 minute ago, bernhard said: since the pw admin is so easy I've just not had the need to build a custom login/logout/admin for my users It's not that I think the PW admin isn't easy, but there are lots of scenarios where users don't need to edit site content in any big way and seeing the PW admin would confuse them more than anything. Like where your users just have an account so they can access a private "members" area, or view "premium" content, etc. 3 Link to comment Share on other sites More sharing options...
Peter Knight Posted January 24, 2018 Author Share Posted January 24, 2018 1 minute ago, Robin S said: It's not that I think the PW admin isn't easy, but there are lots of scenarios where users don't need to edit site content in any big way and seeing the PW admin would confuse them more than anything. Like where your users just have an account so they can access a private "members" area, or view "premium" content, etc. Agree. Even for small apps I'd rather keep my clients away from the admin. BTW in my own scenario mentioned above I only have 10 staff members of my client using an App. None of them would even know how to view HTML so I'm not too worried about them seeing a logout page. 17 hours ago, flydev said: Just logout then redirect the user : $session->logout(); $session->redirect("./"); And you could write a GET variable ?logout=1 in your link then check this var to logout the user. if($input->get->logout) { $session->logout(); $session->redirect('./'); } else { $out = "<p>You are logged in. <a href='./?logout=1'>Logout</a></p>"; } So you place that in a custom logout template? I get it now. Link to comment Share on other sites More sharing options...
bernhard Posted January 24, 2018 Share Posted January 24, 2018 12 minutes ago, Robin S said: It's not that I think the PW admin isn't easy, but there are lots of scenarios where users don't need to edit site content in any big way and seeing the PW admin would confuse them more than anything. Like where your users just have an account so they can access a private "members" area, or view "premium" content, etc. Agree - I just redirected them where I needed 8 minutes ago, Peter Knight said: So you place that in a custom logout template? I get it now. If it is a custom logout template you don't even need the GET variable since all it does is logging out the user... Link to comment Share on other sites More sharing options...
Peter Knight Posted January 24, 2018 Author Share Posted January 24, 2018 Just now, bernhard said: Agree - I just redirected them where I needed If it is a custom logout template you don't even need the GET variable since all it does is logging out the user... Very simple. But it's another template. How do you feel about that Vs just hardcoding the logout into the HTML itself. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now