2019-06-18 16:44:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Joomla\CMS\MVC\Controller\BaseController;
|
|
|
|
use Joomla\CMS\Response\JsonResponse;
|
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
|
|
|
|
// No direct access.
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
abstract class UserException extends Exception {}
|
|
|
|
class InvalidUserDataException extends UserException {}
|
|
|
|
|
|
|
|
class ClubsControllerParts extends BaseController
|
|
|
|
{
|
|
|
|
|
|
|
|
public function edit()
|
|
|
|
{
|
|
|
|
$auth = new ClubsHelperAuth();
|
|
|
|
$user = $auth->getCurrentUser();
|
|
|
|
$app = Factory::getApplication();
|
|
|
|
$post = $app->input->post;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$ret = $this->callMethod($user, $post);
|
|
|
|
echo new JsonResponse($ret);
|
|
|
|
}
|
|
|
|
catch(UserException $e)
|
|
|
|
{
|
|
|
|
echo new JsonResponse($e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param CommonClubsModelUser $user
|
|
|
|
* @param JInput $post
|
|
|
|
*/
|
|
|
|
private function callMethod($user, $post)
|
|
|
|
{
|
|
|
|
switch($post->getCmd('partname'))
|
|
|
|
{
|
|
|
|
case 'user.name':
|
|
|
|
return $this->editUserName($user, $post);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function editUserName($user, $post)
|
|
|
|
{
|
|
|
|
$name = $post->getString('name');
|
|
|
|
if(strlen($name) < 5)
|
|
|
|
throw new InvalidUserDataException("Der Name muss mindestens 5 Zeichen lang sein.");
|
|
|
|
|
|
|
|
$user->setName($name);
|
|
|
|
$user->save();
|
2019-06-18 16:57:46 +02:00
|
|
|
return 'index.php?option=com_clubs&view=mypage&layout=parts&type=name';
|
2019-06-18 16:44:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|