1
0
mirror of https://github.com/typemill/typemill.git synced 2025-01-29 11:09:05 +01:00

v2.9 fix userforms and dispatch them to plugins

This commit is contained in:
trendschau 2024-09-01 20:03:19 +02:00
parent 756f90dd47
commit e86595c25d
4 changed files with 16 additions and 36 deletions

View File

@ -3,3 +3,4 @@
127.0.0.1;2024-04-21 19:24:11;login: invalid data
127.0.0.1;2024-04-22 14:38:20;loginlink: loginlink for user member is not activated.
127.0.0.1;2024-04-23 11:16:24;loginlink: invalid data
127.0.0.1;2024-09-01 13:59:35;login: invalid data

View File

@ -8,7 +8,6 @@ use Typemill\Models\Validation;
use Typemill\Models\User;
use Typemill\Static\Translations;
use Typemill\Static\Session;
use Typemill\Events\OnUserfieldsLoaded;
class ControllerApiSystemUsers extends Controller
{
@ -157,6 +156,7 @@ class ControllerApiSystemUsers extends Controller
# make sure you set a user with password when you update, otherwise it will delete the password completely
$user = new User();
$user->setUserWithPassword($username);
$userrole = $user->getValue('userrole');
# password validation
$pwerrors = [];
@ -222,20 +222,15 @@ class ControllerApiSystemUsers extends Controller
return $response->withHeader('Content-Type', 'application/json')->withStatus(400);
}
# check if loginlink is activated
# check if loginlink is activated, only admins, for other user userrole is removed
$loginlink = false;
if(isset($userdata['userrole']) && $userdata['userrole'] == 'guest' && isset($this->settings['loginlink']) && $this->settings['loginlink'])
if($isAdmin === true && isset($userdata['userrole']) && $userdata['userrole'] == 'guest' && isset($this->settings['loginlink']) && $this->settings['loginlink'])
{
$loginlink = true;
}
# we have to validate again because of additional dynamic fields
$formdefinitions = $user->getUserFields($this->c->get('acl'), $request->getAttribute('c_userrole'), NULL, $loginlink);
$customfields = $this->c->get('dispatcher')->dispatch(new OnUserfieldsLoaded($formdefinitions), 'onUserfieldsLoaded')->getData();
if($customfields)
{
$formdefinitions = $customfields;
}
$formdefinitions = $user->getUserFields($this->c->get('acl'), $this->c->get('dispatcher'), $userrole, $request->getAttribute('c_userrole'), $loginlink);
$validatedOutput = $validate->recursiveValidation($formdefinitions, $userdata);
if(!empty($validate->errors))
{
@ -282,12 +277,7 @@ class ControllerApiSystemUsers extends Controller
}
$user = new User();
$userform = $user->getUserFields($this->c->get('acl'), $userrole,$inspectorrole = $request->getAttribute('c_userrole'));
$customfields = $this->c->get('dispatcher')->dispatch(new OnUserfieldsLoaded($userfields), 'onUserfieldsLoaded')->getData();
if($customfields)
{
$userform = $customfields;
}
$userform = $user->getUserFields($this->c->get('acl'), $this->c->get('dispatcher'), $userrole, $inspectorrole = $request->getAttribute('c_userrole'), $loginlink = NULL);
# fix the standard form
$userform['password']['label'] = 'Password';
@ -335,12 +325,7 @@ class ControllerApiSystemUsers extends Controller
# additional validation for extra fields and image handling
$user = new User();
$formdefinitions = $user->getUserFields($this->c->get('acl'), $userdata['userrole'],$inspectorrole = $request->getAttribute('c_userrole'));
$customfields = $this->c->get('dispatcher')->dispatch(new OnUserfieldsLoaded($formdefinitions), 'onUserfieldsLoaded')->getData();
if($customfields)
{
$formdefinitions = $customfields;
}
$formdefinitions = $user->getUserFields($this->c->get('acl'), $this->c->get('dispatcher'), $userdata['userrole'],$inspectorrole = $request->getAttribute('c_userrole'), $userlink = NULL);
unset($formdefinitions['username']['readonly']);
$validatedOutput = $validate->recursiveValidation($formdefinitions, $userdata);
if(!empty($validate->errors))

View File

@ -9,7 +9,6 @@ use Typemill\Models\Extension;
use Typemill\Models\User;
use Typemill\Models\License;
use Typemill\Models\Settings;
use Typemill\Events\OnUserfieldsLoaded;
class ControllerWebSystem extends Controller
{
@ -270,12 +269,7 @@ class ControllerWebSystem extends Controller
$user->setUser($username);
$userdata = $user->getUserData();
$userfields = $user->getUserFields($this->c->get('acl'), $userdata['userrole']);
$customfields = $this->c->get('dispatcher')->dispatch(new OnUserfieldsLoaded($userfields), 'onUserfieldsLoaded')->getData();
if($customfields)
{
$userfields = $customfields;
}
$userfields = $user->getUserFields($this->c->get('acl'), $this->c->get('dispatcher'),$userdata['userrole'], $inspector = NULL, $loginlink = NULL);
return $this->c->get('view')->render($response, 'system/account.twig', [
'settings' => $this->settings,
@ -370,12 +364,7 @@ class ControllerWebSystem extends Controller
{
$loginlink = true;
}
$userfields = $user->getUserFields($this->c->get('acl'), $userdata['userrole'], $inspector, $loginlink);
$customfields = $this->c->get('dispatcher')->dispatch(new OnUserfieldsLoaded($userfields), 'onUserfieldsLoaded')->getData();
if($customfields)
{
$userfields = $customfields;
}
$userfields = $user->getUserFields($this->c->get('acl'), $this->c->get('dispatcher'), $userdata['userrole'], $inspector, $loginlink);
return $this->c->get('view')->render($response, 'system/user.twig', [
'settings' => $this->settings,

View File

@ -4,6 +4,7 @@ namespace Typemill\Models;
use Typemill\Models\StorageWrapper;
use Typemill\Static\Translations;
use Typemill\Events\OnUserfieldsLoaded;
class User
{
@ -169,7 +170,7 @@ class User
return false;
}
public function getUserFields($acl, $userrole, $inspectorrole = NULL, $loginlink = NULL)
public function getUserFields($acl, $dispatcher, $userrole, $inspectorrole = NULL, $loginlink = NULL)
{
$storage = new StorageWrapper('\Typemill\Models\Storage');
$userfields = $storage->getYaml('systemSettings', '', 'user.yaml');
@ -189,7 +190,11 @@ class User
}
# dispatch fields;
#$fields = $this->c->dispatcher->dispatch('onUserfieldsLoaded', new OnUserfieldsLoaded($fields))->getData();
$customfields = $dispatcher->dispatch(new OnUserfieldsLoaded(['userrole' => $userrole, 'inspectorrole' => $inspectorrole, 'userfields' => $userfields]), 'onUserfieldsLoaded')->getData();
if($customfields && isset($customfields['userfields']) && is_array($customfields['userfields']))
{
$userfields = $customfields['userfields'];
}
# only roles who can edit content need profile image and description
if($acl->isAllowed($userrole, 'mycontent', 'create'))