本文介绍了Opencart Force登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果客户未从网站上的任何页面登录,我想将他们重定向到登录页面.我试图将对子域的访问限制为特定的客户群,而我的其余代码也可以正常工作.

I would like to redirect a customer to the login page if they are not logged in from any page on the site. I am trying to limit access to a subdomain to a specific customer group and the rest of my code works.

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

If I use the following code on home.tpl it works

 if (!$logged) {
        $this->redirect($this->url->link('account/login', '', 'SSL'));
    }

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

but if I put it in the header (so it will react for every page), I get a redirect loop because it will try to redirect the actual login page to itself.

有没有办法正确地说:

if ($this->url->link != 'account/login') {
    $this->redirect($this->url->link('account/login', '', 'SSL'));
}

预先感谢您的帮助.

马特

推荐答案

另一种可能性是创建 preAction -例如像维护模式.我已经使用过一次,并且我认为这比在视图 template 中实现它更干净的解决方案(因此它遵循MVC模式-逻辑在控制器中完成,视图仅用于呈现数据并收集用户输入).

The other possibility is to create a preAction - e.g. like maintenance mode. I have used this once and I think this is much cleaner solution than implementing it in the view template (so it follows the MVC pattern - logic is done in controller, view is only for presenting the data and gathering input from user).

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

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(前端一)并找到行:

Then open up index.php (frontend one) and find line:

// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));

之后添加此内容:

// Login needed pre-action
$controller->addPreAction(new Action('common/login'));

您应该完成.

这篇关于Opencart Force登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 06:51