首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Opencart强制登录

Opencart强制登录
EN

Stack Overflow用户
提问于 2013-12-04 01:38:07
回答 4查看 3.5K关注 0票数 2

我想将客户重定向到登录页面,如果他们没有从网站上的任何页面登录。我正在尝试将访问子域的权限限制为特定的客户组,并且我的其余代码可以正常工作。

如果我在home.tpl上使用以下代码,它可以工作

代码语言:javascript
复制
 if (!$logged) { 
        $this->redirect($this->url->link('account/login', '', 'SSL'));
    }

但是如果我把它放在头中(这样它就会对每个页面做出反应),我会得到一个重定向循环,因为它会尝试将实际的登录页面重定向到它自己。

有没有一种方法可以正确地说:

代码语言:javascript
复制
if ($this->url->link != 'account/login') {
    $this->redirect($this->url->link('account/login', '', 'SSL'));
}

提前感谢您的帮助。

哑光

EN

回答 4

Stack Overflow用户

发布于 2013-12-04 09:06:48

假设你想要检查商店是否也是子域商店,你应该使用如下代码

代码语言:javascript
复制
// Check store ID against subdomain store id value
if($this->config->get('config_store_id') == 123) {

    // Check customer isn't logged in
    if(!$this->customer->isLogged()) {

        // Redirect if route isn't account/login
        if(empty($this->request->get['route']) || $this->request->get['route'] != 'account/login') {
            $this->redirect($this->url->link('account/login', '', 'SSL'));
        }
    }
}
票数 1
EN

Stack Overflow用户

发布于 2013-12-04 17:46:47

另一种可能性是创建类似preAction的维护模式。我已经使用过一次,我认为这比在视图模板中实现它要干净得多(所以它遵循MVC模式-逻辑在控制器中完成,视图只用于呈现数据和收集用户的输入)。

创建一个类catalog/controller/common/login.php

代码语言:javascript
复制
class ControllerCommonLogin extends Controller {

    public function index() {
        if($this->config->get('config_store_id') == 1) { // if desired store, continue checking

            if(!$this->customer->isLogged()) { // Check user isn't logged in
                if(empty($this->request->get['route']) || $this->request->get['route'] != 'account/login') { // Redirect if route isn't account/login
                    $this->redirect($this->url->link('account/login', '', 'SSL'));
                }
            }
        }
    }

}

然后打开index.php (前端一),找到一行:

代码语言:javascript
复制
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));

和后面的添加以下内容:

代码语言:javascript
复制
// Login needed pre-action
$controller->addPreAction(new Action('common/login'));

你应该做完了。

票数 1
EN

Stack Overflow用户

发布于 2013-12-04 02:16:36

您需要添加如下条件:

代码语言:javascript
复制
 if($this->config->get('config_store_id') == 1) { //Add your subdomain store id, if you want to limit the condition for a subdomain. 

      if( (!isset($this->request->get['route']) || $this->request->get['route'] != 'account/login' ) && (!$this->customer->isLogged()) ){
         $this->redirect($this->url->link('account/login', '', 'SSL'));
      }
 }

$this->request->get['route'] -这将为您提供当前页面路径。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20357962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档