/** * @covers sAdmin::sCheckUser */ public function testsCheckUser() { $customer = $this->createDummyCustomer(); // Basic failing case $this->assertFalse($this->module->sCheckUser()); // Test successful login $this->front->Request()->setPost(array('email' => $customer->getEmail(), 'password' => 'fooobar')); $result = $this->module->sLogin(); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertNull($result['sErrorFlag']); $this->assertNull($result['sErrorMessages']); // Test that user is correctly logged in $this->assertTrue($this->module->sCheckUser()); // Force timeout Shopware()->Db()->update('s_user', array('lastlogin' => '2000-01-01 00:00:00'), 'id = ' . $customer->getId()); $this->assertFalse($this->module->sCheckUser()); $this->assertEquals($customer->getGroup()->getKey(), $this->session->offsetGet('sUserGroup')); $this->assertInternalType('array', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('groupkey', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('description', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('tax', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('taxinput', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('mode', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('discount', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('minimumorder', $this->session->offsetGet('sUserGroupData')); $this->assertArrayHasKey('minimumordersurcharge', $this->session->offsetGet('sUserGroupData')); $this->deleteDummyCustomer($customer); }
/** * Shows the reset password form and triggers password reset on submit */ public function resetPasswordAction() { $hash = $this->Request()->getParam('hash', null); $newPassword = $this->Request()->getParam('password', null); $passwordConfirmation = $this->Request()->getParam('passwordConfirmation', null); $this->View()->assign('hash', $hash); if (!$this->Request()->isPost()) { return; } list($errors, $errorMessages) = $this->validatePasswordResetForm($hash, $newPassword, $passwordConfirmation); $customerModel = null; if (empty($errors)) { try { $customerModel = $this->resetPassword($hash, $newPassword); } catch (\Exception $e) { $errorMessages[] = $e->getMessage(); } } if (!empty($errorMessages)) { $this->View()->assign('sErrorFlag', $errors); $this->View()->assign('sErrorMessages', $errorMessages); return; } // Perform a login for the user and redirect him to his account $this->admin->sSYSTEM->_POST['email'] = $customerModel->getEmail(); $this->admin->sLogin(); $target = $this->Request()->getParam('sTarget', 'account'); $this->redirect(array('controller' => $target, 'action' => 'index', 'success' => 'resetPassword')); }
/** * Login account by ajax request */ public function ajaxLoginAction() { Enlight()->Plugins()->Controller()->Json()->setPadding(); // Fix same origin miss match $response = $this->Response(); $shop = Shopware()->Shop(); if ($shop->getSecure()) { $response->setHeader( 'Access-Control-Allow-Origin', 'http://' . $shop->getHost() ); $response->setHeader( 'Access-Control-Allow-Methods', 'POST, GET' ); $response->setHeader( 'Access-Control-Allow-Credentials', 'true' ); } if($this->admin->sCheckUser()) { return $this->View()->setTemplate(); } if(!$this->Request()->getParam('accountmode')) { return; } if (empty(Shopware()->Session()->sRegister)) { Shopware()->Session()->sRegister = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); } $this->admin->sSYSTEM->_POST = array(); $this->admin->sSYSTEM->_POST['email'] = $this->Request()->getParam('email'); $this->admin->sSYSTEM->_POST['password'] = $this->Request()->getParam('password'); if($this->Request()->getParam('accountmode')==0 || $this->Request()->getParam('accountmode')==1) { Shopware()->Session()->sRegister['auth']['email'] = $this->admin->sSYSTEM->_POST['email']; Shopware()->Session()->sRegister['auth']['accountmode'] = (int) $this->Request()->getParam('accountmode'); $this->View()->setTemplate(); } else { $checkData = $this->admin->sLogin(); if (empty($checkData['sErrorMessages'])) { $this->refreshBasket(); $this->View()->setTemplate(); } else { $this->View()->sFormData = $this->Request()->getParams(); $this->View()->sErrorFlag = $checkData['sErrorFlag']; $this->View()->sErrorMessages = $checkData['sErrorMessages']; } } }