Bearbeiten des Benutzers im Backend implementiert
This commit is contained in:
108
src/admin/controllers/user.php
Normal file
108
src/admin/controllers/user.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ClubsControllerUser extends BaseController
|
||||
{
|
||||
|
||||
function new()
|
||||
{}
|
||||
|
||||
function change()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->input;
|
||||
$id = (int) $input->post->getInt('id');
|
||||
$u = ClubsUser::loadUser((int) $id);
|
||||
|
||||
// Fetch the posted data
|
||||
$user = $input->post->getCmd('user');
|
||||
$pwd = $input->post->getCmd('pwd');
|
||||
$pwdConfirm = $input->post->getCmd('pwd-confirm');
|
||||
$name = $input->post->getString('name');
|
||||
$address = $input->post->getString('address');
|
||||
$city = $input->post->getString('city');
|
||||
$mail = $input->post->getString('mail');
|
||||
$phone = $input->post->getString('phone');
|
||||
$mobile = $input->post->getString('mobile');
|
||||
|
||||
// Check the input data
|
||||
$error = false;
|
||||
|
||||
if(isset($user))
|
||||
{
|
||||
if(! $this->checkUserName(trim($user), $id))
|
||||
{
|
||||
$app->enqueueMessage('Username ' . $user . ' ist nicht gültig.', 'error');
|
||||
$error = true;
|
||||
}
|
||||
|
||||
$u->setUser($user);
|
||||
}
|
||||
|
||||
if(isset($pwd))
|
||||
{
|
||||
if(trim($pwd) != trim($pwdConfirm))
|
||||
{
|
||||
$app->enqueueMessage('Die Passwörter stimmen nicht überein.', 'error');
|
||||
$error = true;
|
||||
}
|
||||
|
||||
if(! empty(trim($pwd)))
|
||||
{
|
||||
if(! $u->checkPassword(trim($pwd)))
|
||||
{
|
||||
$app->enqueueMessage('Das Passwort ist nicht zulässig.', 'error');
|
||||
$error = true;
|
||||
}
|
||||
|
||||
$u->setPassword(trim($pwd));
|
||||
}
|
||||
}
|
||||
|
||||
// Check existence of the other fields
|
||||
$fields = array('name'=>'Bürgerlicher Name', 'address'=>'Adresse', 'city'=>"Stadt", 'mail'=>'E-Mail');
|
||||
foreach ($fields as $f => $fname)
|
||||
{
|
||||
$fvalue = $$f;
|
||||
if(! isset($fvalue) || strlen(trim($fvalue)) == 0)
|
||||
{
|
||||
$app->enqueueMessage("Das Feld $fname ist obligatorisch.", 'error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
$u->setName($name);
|
||||
$u->setAddress($address);
|
||||
$u->setCity($city);
|
||||
$u->setMail($mail);
|
||||
$u->setPhone($phone);
|
||||
$u->setMobile($mobile);
|
||||
|
||||
if($error)
|
||||
{
|
||||
$data = array();
|
||||
foreach(array('user', 'name', 'address', 'city', 'mail', 'phone', 'mobile') as $i)
|
||||
$data[$i] = $$i;
|
||||
|
||||
$urldata = urlencode(json_encode($data));
|
||||
$this->setRedirect(Route::_('index.php?option=com_clubs&view=user&id=' . $id . '&data=' . $urldata, false));
|
||||
return;
|
||||
}
|
||||
|
||||
// Do the actual work
|
||||
$u->save();
|
||||
$this->setRedirect(Route::_('index.php?option=com_clubs&view=users', false));
|
||||
}
|
||||
|
||||
private function checkUserName($username, $id = -1)
|
||||
{
|
||||
return ClubsUser::isUserNameFree($username, $id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user