I have created a form for registration which is working fine,
I am using default login form to make user login to access a particular page,
When the user enter username and password he is directed to a particular page(Download page).
All this are working fine.
Now I want to have a LOGOUT link in my page(download page),When a user click on logout he should be directed to home page.
Please help me creating a logout link which redirect to home page.
Thank you in advance
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
- Page 11(current)
- 2
- Next 10 entries
I have tried using login widgets but when I click on logout there its redirect to the same page adn also have tried with /secure/logout. that also does not redirect to homepage
With Director::redirect() you can redirect someone to another page. I would then test if someone is logged in and if not use a redirect. That is where I would start...
Can you please explain me in detail how to use it,I simple need to open homepage when my user click on logout
I am just guessing.
Here is more info on redirect: http://doc.silverstripe.org/doku.php?id=director
Here for member: http://doc.silverstripe.org/doku.php?id=member
My guess is you shout be able to do something with this info...
if( $member = Member::currentUser() ) {
// Work with $member
} else {
// Do non-member stuff
}
Or you create your own logout function, but I have at this moment no idea where to start.
A simple Logout method
// mysite/code/Page.php -> Page_Controller
function logout() {
Security::logout(false);
Director::redirect("home/");
}
Then you can have a link like <a href="home/logout">Logout</a> in your template. That function logs the member out then redirects them to the 'home' url.
thank you Willr the function is working and is redirecting user to the home page when someone click on logout but the session is not logged out,the session is still logged in in other page as i have used $LoginForm in my homepage ,so when a user click on logout the form should be visible in homepage but that is not happening..instead of form it is showing as user logged in
Hi,
I tried this in Silverstripe 2.4 - you need to add to Page_Controller
public static $allowed_actions = array (
'logout'
);
public function logout() {
Director::redirect("home/");
Security::logout(true);
}
I also changed the order: Director::redirect first, then the logout. This seems to work better. My main problem was that when a logged in user was on a special page like the own user profile of the forum and the user would log out from that page this would give a fatal error. Redirect to home and logout then is safer.
Cheers!
Anatol
- Page 11(current)
- 2
- Next 10 entries