public function isLoginValid($username, $password)
 {
     $data = $this->find(Condition::equals('username', $username));
     if (null !== $data) {
         $testPassword = hash('sha256', $password . $data['salt']);
         if ($testPassword === $data['password']) {
             return true;
         }
     }
     return false;
 }
 public function isRoleAllowed($role, $permission)
 {
     $data = $this->findAll(Condition::combineAnd(Condition::equals('type', 'add_permission'), Condition::equals('name', $role)));
     if (null === $data) {
         $this->addMessage('Unable to get roles!');
         return null;
     }
     foreach ($data as $row) {
         if ($row['value'] === $permission || $row['value'] === '*') {
             return true;
         }
     }
     return false;
 }
 public function deleteAllByCustomerId($id)
 {
     return $this->delete(Condition::equals('customer_id', $id));
 }
 public function deleteAllByDeviceId($id)
 {
     return $this->delete(Condition::equals('device_id', $id));
 }
 public function findById($id)
 {
     return $this->find(Condition::equals('id', $id));
 }
 /**
  * @return mixed
  */
 private function getPermissionsOfRole($roleName)
 {
     return $this->findAll($this->permissionsOfRolesTableName, Condition::equals('role_name', $roleName));
 }
 public function findWithinRange($start, $end)
 {
     return $this->findAll(Condition::combineAnd(Condition::greaterThanOrEquals('created', $start), Condition::lessThan('created', $end)));
 }