When site members click logout they are taken back to the homepage.

I'd like to redirect the user back to the login page but with a "You're logged out" type of message.

Is something like this possible yet?

up vote 7 down vote accepted

It is not possible yet, but a quick plugin would make this possible. It would just be a controller with a logout action. You'd be able to call the action as a url with:

/actions/[PluginHandle]/[ControllerName]/[ActionName]

Then you can logout the user the same way Craft does in their controller and edit the redirect as you see fit. Something like this:

craft()->userSession->logout(false);
$this->redirect('?status=logout');

This would log them out and then send them to the homepage with a query attached to the end.

  • I've setup a simple plugin. My Controller is called DelaneyMethod_MembersControllor with an action called actionLogout. In my form I have this: delaneymethod/members/logout but I get "Page Not Found, Unable to resolve the request "delaneymethod/members/logout". – Sean Delaney Jun 19 '14 at 8:32
  • I also see you have suggested /actions/[PluginHandle]/[ControllerName]/[ActionName] and not /[PluginHandle]/[ControllerName]/[ActionName] as action URL ? – Sean Delaney Jun 19 '14 at 8:35
  • Hey Sean, Craft's controllers are triggered when the first URL segment is ‘actions’ (by default) . You can generate a URL using the actionUrl function, i.e. {{ actionUrl('delaneyMethod/members/logout') }} – Stuart Whitehead Jun 19 '14 at 9:55
  • Yes, I know but I'm submitted a form in this case... and I have an action field. – Sean Delaney Jun 19 '14 at 9:58
  • I've got it working. I was calling "delaneymethod/members/logout" not "delaneyMethod/members/logout". Simple things that the eye doesn't catch... Thanks. – Sean Delaney Jun 19 '14 at 10:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.