1

How can i check the customer is confirmed or not before login.

this is my login function :

public function loginAction() {
    if ($this->getRequest()->isPost()) {
        $session = $this->_getSession();
        if (Mage::getSingleton ( 'customer/session' )->isLoggedIn ()) {
            $session->logout ();
        }

        $username = Mage::app ()->getRequest ()->getParam ( 'username' );
      $password = Mage::app ()->getRequest ()->getParam ( 'password' );

        try {
      if ($session->getCustomer()->getIsJustConfirmed()) {
            if (!$session->login ( $username, $password )) {
                echo json_encode(array('status' => 'error','message'=> $this->__('wrong username or password.')));
                exit;
            } else {

                echo json_encode(array('status' => 'success','message'=>$this->statusAction ()));
                exit;
            }
      }else {
        echo 'bla bla bla';
      }
        } catch ( Mage_Core_Exception $e ) {
            switch ($e->getCode ()) {
                case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED :
                    //$value = Mage::helper ( 'customer' )->getEmailConfirmationUrl ( $username );
                    $message = Mage::helper ( 'customer' )->__ ( 'This account is not confirmed.');
                    echo json_encode ( array (
                            'status' => 'error',
                            'message' =>  $this->__($message )
                    ) );
                    break;
                case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD :
                    $message = $e->getMessage ();
                    echo json_encode ( array (
                            'status' => 'error',
                            'message' => $this->__($message )
                    ) );
                    break;
                default :
                    $message = $e->getMessage ();
                    echo json_encode ( array (
                            'status' => 'error',
                            'message' => $this->__($message )
                    ) );
            }
        }
  }
}

iv'e used $session->getCustomer()->getIsJustConfirmed() but it's not working.

how can i fixe it ?

5
  • in custom script ? Aug 8, 2016 at 6:24
  • yes iv'e create a custom api for my mobile application and when logged in i want to check this customer is activated or not. Aug 8, 2016 at 6:26
  • i think in your script you need set login customer after check confirmed one if not confirmed then logout session and send your json Aug 8, 2016 at 6:35
  • @PrashantBarot sure, iv'e set login customer after check confirmed and this is my code : $session->login($username, $password); if ($session->getCustomer()->getCustomerActivated()) { echo 'confirmed'; }else { echo 'not confirmed'; } Aug 8, 2016 at 6:38
  • can you just print your session array Aug 8, 2016 at 6:47

1 Answer 1

1

It's just set login customer then check if confirmed look like this :

try {
if (!$session->login ( $username, $password )) {
    echo json_encode(array('status' => 'error','message'=> $this->__('wrong username or password.')));
    exit;
  } else {
     if ($session->getCustomer()->getCustomerActivated()) {
         echo json_encode(array('status' => 'success','message'=>$this->statusAction ()));
     }else {
         $array = array();
         $array['status']= 'error';
         $array['message']= 'Please wait for your account to be activated.';
         echo json_encode ($array);
     }
    exit;
}
} catch ( Mage_Core_Exception $e ) {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.