/** * User authentication by login form * * @return bool */ public function identify() { $filter = new DbFilter(); $where = 'email = \'' . $this->getLogin() . '\' AND "group" & ' . UsrGroup::DELETED . ' = 0 '; $filter->setWhere($where); if (!$this->findUser($filter)) { return false; } $this->delCookie(); if (!Password::check($this->getUser(), $this->getPassword())) { $this->errors |= self::ERR_WRONG_PASSWORD; return false; } $this->setCookie(['expired' => strtotime('+365 days')]); return true; }
/** * @covers Veles\DataBase\DbFilter::setOrder */ public function testSetOrder() { $order = 'order string'; $this->object->setOrder($order); $expected = "ORDER BY {$order}"; $msg = 'Wrong DbFilter::getOrder() behavior!'; $this->assertAttributeSame($expected, 'order', $this->object, $msg); }
/** * User authentication by cookies * * @return bool */ public function identify() { $filter = new DbFilter(); // Search within not deleted users $where = 'id = ' . $this->getId() . ' AND "group" & ' . UsrGroup::DELETED . ' = 0 '; $filter->setWhere($where); if (!$this->findUser($filter)) { return false; } // If hash doesn't match, delete cookies if ($this->getUser()->getCookieHash() !== $this->getPasswordHash()) { $this->delCookie(); $this->errors |= self::ERR_WRONG_PASSWORD; return false; } return true; }
/** * @covers Veles\Model\ActiveRecord::find * @dataProvider findProvider * * @param $id * @param $expected */ public function testFind($id, $expected) { $expected_news = new News(); if ($expected) { $expected_news->id = $id; $expected_news->title = "title_{$id}"; $expected_news->content = "content_{$id}"; $expected_news->author = "author_{$id}"; } $db_result = $expected ? ['id' => $id, 'title' => "title_{$id}", 'content' => "content_{$id}", 'author' => "author_{$id}"] : []; $adapter = $this->getMockBuilder('\\Veles\\DataBase\\Adapters\\PdoAdapter')->setMethods(['row'])->getMock(); $adapter->expects($this->once())->method('row')->willReturn($db_result); Db::setAdapter($adapter); $actual_news = new News(); $filter = new DbFilter(); $filter->setWhere("id = {$id}"); $actual = $actual_news->find($filter); $msg = 'ActiveRecord::find() returns wrong result!'; $this->assertSame($expected, $actual, $msg); $msg = 'Wrong ActiveRecord::find() behavior!'; $this->assertEquals($expected_news, $actual_news, $msg); }
/** * @param $filter DbFilter * * @return array */ protected function extractParams(DbFilter $filter) { return ['where' => $filter->getWhere(), 'group' => $filter->getGroup(), 'having' => $filter->getHaving(), 'order' => $filter->getOrder()]; }
public function findProvider() { $filter = new DbFilter(); $filter->setWhere('id = 1'); return [[null, "\n\t\t\tSELECT\n\t\t\t\t\"id\", \"email\", \"hash\", \"group\", \"last_login\"\n\t\t\tFROM\n\t\t\t\t\"users\""], [$filter, "\n\t\t\tSELECT\n\t\t\t\t\"id\", \"email\", \"hash\", \"group\", \"last_login\"\n\t\t\tFROM\n\t\t\t\t\"users\"\n\t\t\tWHERE id = 1"]]; }