Bearbeiten des Benutzers im Backend implementiert
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class UserInvalidException extends Exception
|
||||
{}
|
||||
|
||||
class PasswordInvalidException extends Exception
|
||||
{}
|
||||
|
||||
class ClubsUser
|
||||
{
|
||||
protected $dbo;
|
||||
@@ -104,6 +109,14 @@ class ClubsUser
|
||||
*/
|
||||
public function setUser(string $user)
|
||||
{
|
||||
if($this->id === 'new')
|
||||
$valid = self::isUserNameFree($user);
|
||||
else
|
||||
$valid = self::isUserNameFree($user, $this->id);
|
||||
|
||||
if(! $valid)
|
||||
throw new UserInvalidException();
|
||||
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
@@ -112,6 +125,9 @@ class ClubsUser
|
||||
*/
|
||||
public function setPassword(string $password)
|
||||
{
|
||||
if(! $this->checkPassword($password))
|
||||
throw new PasswordInvalidException();
|
||||
|
||||
$this->hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
@@ -326,4 +342,34 @@ class ClubsUser
|
||||
$this->dbo->setQuery($q);
|
||||
$this->dbo->execute();
|
||||
}
|
||||
|
||||
public static function isUserNameFree($username, int $id = -1)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$q = $db->getQuery(true);
|
||||
$q->select('COUNT(*)')->from('#__club_users')
|
||||
->where('id <> ' . (int) $id)
|
||||
->where('user = ' . $q->q($username));
|
||||
$db->setQuery($q);
|
||||
$db->execute();
|
||||
$row = $db->loadRow();
|
||||
return $row[0] == 0;
|
||||
}
|
||||
|
||||
public function checkPassword($pwd)
|
||||
{
|
||||
if(strlen($pwd) < 6)
|
||||
return false;
|
||||
|
||||
if(preg_match_all('/[A-Z]/', $pwd) === false)
|
||||
return false;
|
||||
|
||||
if(preg_match_all('/[a-z]/', $pwd) === false)
|
||||
return false;
|
||||
|
||||
if(preg_match_all('/[0-9]/', $pwd) === false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user