doupi3874 2017-04-13 13:56
浏览 143

在OpenCart中登录功能

I am building a web export to OpenCart. I already have an export to Magento. the log in functie for Magento is this:

function login($usr,$pwd, $return_session = false) {

    Mage::setIsDeveloperMode(true);
    Mage::register('isSecureArea', 1);
    Mage::getSingleton('core/session', array('name' => 'adminhtml'));

    // supply username
    $user = Mage::getModel('admin/user'); // user your admin username

    if(!$user->authenticate($usr, $pwd)){
        $this->errors[] = "Username or password is incorrect.";
    }

    if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
        Mage::getSingleton('adminhtml/url')->renewSecretUrls();
    }

    $session = Mage::getSingleton('admin/session');
    $session->setIsFirstVisit(true);
    $session->setUser($user);
    $session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
    Mage::dispatchEvent('admin_session_user_login_success',array('user'=>$user));

    if (!count($this->errors)) {
        $loggedin = true;
        Mage::init();
        Mage::app("default")->setCurrentStore( Mage_Core_Model_App :: ADMIN_STORE_ID );
        $this->sess_id = $session->getEncryptedSessionId();
    } else{
        //print_r($this->errors);
        $loggedin = false;
    }
    //Returns boolean whether login data is correct or not
    if ($return_session) {
        return $session;
    }
    return $loggedin;
}

I hope there is someone who knows how to do this in OpenCart. If you don't know it, but you know which functions i need to use, then i also would like to hear it.

I hope there is someone who can help me.

Thanks

  • 写回答

2条回答 默认 最新

  • dsfw2154 2017-04-13 15:01
    关注

    There is in "system/library" a file named "account.php", this contains the login function for the accounts. To use this in controllers you can use the "$this->account" library.

    Example

    if($this->account->login('username', 'password'))
      echo 'Logged in!';'
    else
      echo 'Failed!'
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能