Created models for all database objects

This commit is contained in:
2019-05-31 14:18:34 +02:00
parent 4fa01d4cc0
commit 4ce8fd274d
14 changed files with 634 additions and 11 deletions

View File

@@ -14,6 +14,158 @@ class CommonClubsModelUser extends AbstractCommonClubsModel
{
return $this->getValues()['name'];
}
}
public function setName($name)
{
$this->setValue('name', $name);
}
public function getUsername()
{
return $this->getValues()['user'];
}
public function setUsername($user)
{
// XXX Check for validity
$this->setValue('user', $user);
}
public function getAddress()
{
return $this->getValues()['address'];
}
public function setAddress($address)
{
$this->setValue('address', $address);
}
public function getCity()
{
return $this->getValues()['city'];
}
public function setCity($city)
{
$this->setValue('city', $city);
}
public function getMail()
{
return $this->getValues()['mail'];
}
public function setMail($mail) {
$this->setValue('mail', $mail);
}
public function getPhone()
{
return $this->getValues()['phone'];
}
public function setPhone($phone)
{
$this->setValue('phone', $phone);
}
public function getMobile()
{
return $this->getValues()['mobile'];
}
public function setMobile($mobile)
{
$this->setValue('mobile', $mobile);
}
public function isPasswordValid($password)
{
$hash = $this->getValues()['password'];
if(password_verify($password, $hash))
return true;
else
return false;
}
public function checkRehashNeeded($newPassword, $check = false)
{
$hash = $this->getValues()['password'];
if(password_needs_rehash($hash, PASSWORD_DEFAULT))
{
if($check)
{
if(! $this->isPasswordValid($newPassword))
throw new Exception('Password did not match.');
}
$this->setPassword($newPassword);
return true;
}
else
return false;
}
public function setPassword($password)
{
$hash = password_hash($password, PASSWORD_DEFAULT);
$this->setValue('password', $hash);
}
public function getPositions()
{
return $this->fetchAssociatedElements(new CommonClubsModelFactoryUserassoc(), 'userid');
}
public function isPasswordSuitable($password)
{
if(strlen($password) < 8)
return false;
$pwdLower = strtolower($password);
$userLower = strtolower($this->getName());
if(strpos($pwdLower, $userLower) || strpos($userLower, $pwdLower))
return false;
if(
preg_match('/.*[a-z].*/', $password) === false ||
preg_match('/.*[A-Z].*/', $password) === false
)
return false;
return true;
}
public function isUsernameSuitable($user)
{
$factory = new CommonClubsModelFactoryUser();
$users = $factory->loadElements(null, null, function($q) use ($user){
$q->where('main.user = ' . $q->q($user));
});
if(sizeof($users) == 0)
return true;
elseif(sizeof($users) == 1)
{
if($this->getId() == $users[0]->getId())
return true;
else
return false;
}
else
throw new Exception('The database is inconsistent!');
}
protected function prepareDelete($db)
{
$q = $db->getQuery(true);
$q->delete('#__club_user_assocs')->where("userid = {$this->getId()}");
$db->setQuery($q);
$db->execute();
}
}