General jQuery based approach in frontend is working.

This commit is contained in:
2019-06-18 16:44:44 +02:00
parent a2eb141d5c
commit a30e5d76a1
7 changed files with 202 additions and 10 deletions

View File

@@ -0,0 +1,59 @@
<?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();
$this->setRedirect('index.php?option=com_clubs&view=mypage&layout=parts&type=name');
}
}