Page 1 of 1
Members only area (information page)
Posted: Sun May 27, 2012 5:19 pm
by growlbox
Hi guys,
I was wondering if there's a way that i could make some information pages restricted to members only?
Re: Members only area (information page)
Posted: Sun May 27, 2012 6:28 pm
by Avvici
Easy to do. Just set up an isLogged check on the page you want it and it will redirect anyone to login if they try and view it. Thing is, the information pages are displayed from an array so you would have to use a conditional before hand.
v1.5.2.1+
So lets see open catalog/controller/information/information.php and find this:
Code: Select all
if (isset($this->request->get['information_id'])) {
$information_id = $this->request->get['information_id'];
} else {
$information_id = 0;
}
Just under it add this:
Code: Select all
if($information_id == 1){
if (!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' . $information_id);
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
}
This checks for an information ID of 1. If they are not logged it will make them login, then redirect them to the information page they were trying to view. To find the info id's just turn your SEO url off and navigate to the info page you want. Look at the browser bar to see the ID in the URL. Tested and works
Re: Members only area (information page)
Posted: Wed May 30, 2012 2:31 am
by growlbox
Avvici, I would like to thank you for your help. I did not expect any response. I will use your code and see if it works.
Re: Members only area (information page)
Posted: Tue May 07, 2013 1:50 pm
by discostu
Hi there, I'm wondering how I can redirect the user to the account/login page with an error message that appears
"you must be logged in to view that page"
Cheers, Stu
Re: Members only area (information page)
Posted: Tue May 07, 2013 7:58 pm
by Avvici
Easy to do as well. You need only to set the error session and it will display on the login page once they get to it. For example:
Code: Select all
if($information_id == 1){
if (!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' . $information_id);
$this->session->data['error'] = "You must login!";
$this->redirect($this->url->link('account/login', '', 'SSL'));
}
}
And now open up account/login.php and add this code the public function index()
Code: Select all
if (isset($this->session->data['error'])) {
$this->data['warning'] = $this->session->data['error'];
unset($this->session->data['error']);
} else {
$this->data['warning'] = '';
}