Magento: Login and redirect to account page from outside magento -
i using below code login , redirect account page:
<?php include('store/app/mage.php'); mage::app(); if($_post && $_post['login']['username'] && $_post['login']['password']){ $email = $_post['login']['username']; $password = $_post['login']['password']; $session = mage::getsingleton('customer/session'); try { $log = $session->login($email, $password); $session->setcustomerasloggedin($session->getcustomer()); $customer_id = $session->getcustomerid(); $send_data["success"] = true; $send_data["message"] = "login success"; $send_data["customer_id"] = $customer_id; mage::getsingleton('customer/session')->loginbyid($customer_id); mage_core_model_session_abstract_varien::start(); }catch (exception $ex) { $send_data["success"] = false; $send_data["message"] = $ex->getmessage(); } }else { $send_data["success"]=false; $send_data["message"]="enter both email , password"; } echo json_encode($send_data); ?>
and on file making ajax request, using code:
if(data.success){ window.location = "http://domain.com/store/customer/account/" }
but show user logout, though correct customer id success.
$email = strip_tags($_get["login"]); $password = strip_tags($_get["psw"]); function loginuser( $email, $password ) { umask(0); ob_start(); session_start(); mage::app('default'); mage::getsingleton("core/session", array("name" => "frontend")); $websiteid = mage::app()->getwebsite()->getid(); $store = mage::app()->getstore(); $customer = mage::getmodel("customer/customer"); $customer->website_id = $websiteid; $customer->setstore($store); try { $customer->loadbyemail($email); $session = mage::getsingleton('customer/session')->setcustomerasloggedin($customer); if($session->login($email, $password)){ return true;} else { }; }catch(exception $e){ return $e->getmessage(); } } if (loginuser($email,$password) == 1) { echo ".. user loged ".mage::getsingleton('customer/session')->getcustomer()->getname()."<br>";} else { //bad things goes here }
Comments
Post a Comment