/** * Initialize test * * @return void */ public function init() { parent::setUp(); $this->user = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test-user-model', 'user_acl_role_id' => 1, 'active' => true)); $this->user->setPassword('test-user-model-password'); $this->user->save(); $this->user->authenticate('test-user-model', 'test-user-model-password'); $configuration = (include GC_APPLICATION_PATH . '/config/application.config.php'); $configuration['module_listener_options']['config_glob_paths'] = array('tests/config/local.php'); $this->setApplicationConfig($configuration); }
protected function createUser() { $this->user = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test-user-login', 'user_acl_role_id' => 1, 'active' => true)); $this->user->setPassword('test-user-model-password'); $this->user->save(); $this->user->authenticate('test-user-login', 'test-user-model-password'); }
/** * Test * * @return void */ public function testFakeAuthenticate() { $this->assertFalse($this->object->authenticate('test', 'wrong password')); }
/** * Test * * @return void */ public function testInvokeWithAUthenticationShouldReturnUserModel() { $this->user->authenticate('test', 'test'); $this->assertInstanceOf('Gc\\User\\Model', $this->object->__invoke()); }
/** * Login user * * @return \Zend\View\Model\ViewModel|array */ public function loginAction() { if ($this->getServiceLocator()->get('Auth')->hasIdentity()) { $redirect = $this->getRouteMatch()->getParam('redirect'); if (!empty($redirect)) { return $this->redirect()->toUrl(base64_decode($redirect)); } return $this->redirect()->toRoute('admin'); } $this->layout()->setTemplate('layouts/one-page.phtml'); $loginForm = new UserLogin(); $post = $this->getRequest()->getPost(); if ($this->getRequest()->isPost() and $loginForm->setData($post->toArray()) and $loginForm->isValid()) { $userModel = new User\Model(); $redirect = $loginForm->getValue('redirect'); if ($userModel->authenticate($post->get('login'), $post->get('password'))) { if (!empty($redirect)) { return $this->redirect()->toUrl(base64_decode($redirect)); } return $this->redirect()->toRoute('admin'); } $this->flashMessenger()->addErrorMessage('Can not connect'); return $this->redirect()->toRoute('config/user/login', array('redirect' => $redirect)); } $loginForm->get('redirect')->setValue($this->getRouteMatch()->getParam('redirect')); return array('form' => $loginForm); }