0

once we click on login "button" , we are hiding the pop up , but we want to hide only if the login is successfull. [ if customer enter valid email id & password ]

controllers

protected function _createProduct($type, $doSave = true, $originalProduct, $newImagePath = "")
    {

        Mage::register('isSecureArea',true);    
        $session = Mage::getSingleton('customer/session');

        $result = array(
            'success' => false
        );

        $login ="";
        $productId ="";
        if ($this->getRequest()->isPost()) {
            $login     = $this->getRequest()->getPost('login');
            $productId = $this->getRequest()->getPost('product_id');
        }
            // echo $login['product_id'];die;
            // if (!empty($login['username']) && !empty($login['password'])) {
                try {
                    if(isset($login) && (is_array($login) && !empty($login)) || ($login!="")){
                        $session->login($login['username'], $login['password']);
                        $result['redirect'] = $this->_getRefererUrl() ? $this->_getRefererUrl() : Mage::getUrl('customer/account', array(
                            '_secure' => true
                        ));
                        $result['success']  = true;
                        $customerId         = Mage::getSingleton('customer/session')->getCustomerId();
                    }
                    else{
                        $customerId = "";
                    }

                    $product->setName($originalProduct->getName());


                    $customerId = Mage::getSingleton('customer/session')->getCustomerId();
                    $product->setCreatedByCustomerId($customerId);

                    if ($doSave)
                        $product->save();
                    // To save inside my_designs

                    return $product;                   

                }
                catch (Mage_Core_Exception $e) {
                    switch ($e->getCode()) {
                        case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                            $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', Mage::helper('customer')->getEmailConfirmationUrl($login['username']));
                            break;
                        case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                            $message = $e->getMessage();
                            break;
                        default:
                            $message = $e->getMessage();
                    }
                    $result['error'] = $message;
                    $session->setUsername($login['username']);

                }
                catch (Exception $e) {
                    $result = "ERROR :".$e->getMesage();
                    /
                }
            // } else {
            //     $result['error'] = Mage::helper('customer')->__('Login and password are required.');
            // }
        // }

        Mage::unregister('isSecureArea');
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

        // code for guest end
    }

Login Form

<form action="<?php echo $this->getUrl('example/amasty/createSimpleProductAndRedirect.....>

<label>Email Address</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" />
<label>password</label>
<input type="password" name="login[password]"  id="pass" />

<button onclick="hideWindow()" id="send2"><?php echo $this->__('Login') ?></button>
1

You should try to edit the function hideWindow() in your javascript files to check if the login is succesfull.

And I presume that your login function is called by ajax? If so, return a value back to the login modal that the user is logged in or not and then check on this value if the modal should be closed or not.

<form action="<?php echo $this->getUrl('example/amasty/createSimpleProductAndRedirect.....>

<label>Email Address</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" />
<label>password</label>
<input type="password" name="login[password]"  id="pass" />

<button onclick="hideWindow()" id="send2"><?php echo $this->__('Login') ?></button>
</form>
<input type=hidden id=loggedin value={true/false} />

As listed above: <input type=hidden id=loggedin value={true/false} /> the value attribute should contain the returned value of the ajax function.

if you're using jquery

function hideWindow() {
    var isLoggedin = jQuery('#loggedin').val();
    if (isLoggedin) {
       ....
    }
}
  • now, its not hiding the pop up for wrong email / password, but even its not hiding if we enter correct email and password also.... – user52996 May 2 '17 at 9:26
  • i have this code : function hideWindow() { var isLoggedin = jQuery('#loggedin').value(); if (isLoggedin) { document.getElementById('something').style.display = 'none'; document.getElementById('ajaxlogin-mask').style.display = 'none'; } } – user52996 May 2 '17 at 9:27
  • I've made a code error it should be: .val() instead of .value(). Also did you return the value to the new added input field? which should be either true or false? – Myron May 2 '17 at 9:32
  • i got {"ok":false} under network tab – user52996 May 2 '17 at 9:39
  • @vickeycolors you are running more then once the function hideWindow() on your site. This is probably conflicting with each other. also i edited my answer. – Myron May 2 '17 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy