Magento增加前端用户会话生命周期

时间:2016-05-27 09:22:20

标签: php magento

我正在为Magento网站开发移动应用程序。在那里,我将与我为移动应用程序的Web服务构建的PHP脚本进行交互。我想让用户在移动应用程序中登录生命。怎么做?

以下是我现在使用的登录脚本。

require_once "api_config.php";

$session = Mage::getSingleton('customer/session');
$session->start();


if (isset($_POST['email']) && !empty($_POST['email']) && isset($_POST['password']) && !empty($_POST['password'] )) {

    $email = $_POST['email'];
    $password = $_POST['password'];

    try {
        if ($session->login($email, $password )) {
            $response['status'] = 'success';
            $response['data'] = array();
            $response['message'] = array('User loggedin Successfully.');
        } else {
            $response['status'] = 'error';
            $response['data'] = array();
            $response['message'] = array('User login failed.');
        }
        if ($session->getCustomer()->getIsJustConfirmed()) {
            $this->_welcomeCustomer($session->getCustomer(), true);
        }
    } catch (Mage_Core_Exception $e) {
        switch ($e->getCode()) {
            case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                $value = Mage::helper('customer')->getEmailConfirmationUrl($email);
                $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                break;
            case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                $message = $e->getMessage();
                break;
            default:
                $message = $e->getMessage();
        }
        //$session->addError($message);
        $response['status'] = 'error';
        $response['data'] = array();
        $response['message'] = array($message);
        echo $message;
        $session->setUsername($email);
    } catch (Exception $e) {
        $response['status'] = 'error';
        $response['data'] = array();
        $response['message'] = array($e);
        // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
    }
} else {
    //$session->addError('Login and password are required.');
    $response['status'] = 'error';
    $response['data'] = array();
    $response['message'] = array('Login and password are required.');
}
print_r(json_encode($response, JSON_FORCE_OBJECT));die;

0 个答案:

没有答案