public function edit()
    {
        $this->defaultData();
        $userService = $this->getServiceLocator()->get(tao_models_classes_UserService::class);
        $user = $this->getUserResource();

        $types = $user->getTypes();
        $myFormContainer = new tao_actions_form_Users(reset($types), $user);
        $myForm = $myFormContainer->getForm();

        if ($myForm->isSubmited()) {
            if ($myForm->isValid()) {
                $values = $myForm->getValues();
                if (!empty($values['password2']) && !empty($values['password3'])) {
                    $plainPassword =  $values['password2'];
                    $values[GenerisRdf::PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($values['password2']);
                }

                unset($values['password2']);
                unset($values['password3']);

                if (!preg_match("/[A-Z]{2,4}$/", trim($values[GenerisRdf::PROPERTY_USER_UILG]))) {
                    unset($values[GenerisRdf::PROPERTY_USER_UILG]);
                }
                if (!preg_match("/[A-Z]{2,4}$/", trim($values[GenerisRdf::PROPERTY_USER_DEFLG]))) {
                    unset($values[GenerisRdf::PROPERTY_USER_DEFLG]);
                }

                $userService->checkCurrentUserAccess($values[GenerisRdf::PROPERTY_USER_ROLES]);

                // leave roles which are not in the allowed list for current user
                $oldRoles = $userService->getUserRoles($user);
                $allowedRoles = $userService->getPermittedRoles($userService->getCurrentUser(), $oldRoles, false);
                $staticRoles = array_diff($oldRoles, $allowedRoles);
                $values[GenerisRdf::PROPERTY_USER_ROLES] = array_merge($values[GenerisRdf::PROPERTY_USER_ROLES], $staticRoles);

                $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($user);

                if ($binder->bind($values)) {
                    $data = [];
                    if (isset($plainPassword)){
                        $data = ['hashForKey' => UserHashForEncryption::hash($plainPassword)];
                    }
                    $this->getEventManager()->trigger(new UserUpdatedEvent(
                        $user,
                        array_merge($values, $data))
                    );
                    $this->setData('message', __('User saved'));
                }
            }
        }

        $this->setData('formTitle', __('Edit a user'));
        $this->setData('myForm', $myForm->render());
        $this->setView('user/form.tpl');
    }
public function edit()
    {
        $this->defaultData();
        $userService = $this->getServiceLocator()->get(tao_models_classes_UserService::class);
        $user = $this->getUserResource();

        $types = $user->getTypes();
        $myFormContainer = new tao_actions_form_Users(reset($types), $user);
        $myForm = $myFormContainer->getForm();

        if ($myForm->isSubmited()) {
            if ($myForm->isValid()) {
                $values = $myForm->getValues();
                if (!empty($values['password2']) && !empty($values['password3'])) {
                    $plainPassword =  $values['password2'];
                    $values[GenerisRdf::PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($values['password2']);
                }

                unset($values['password2']);
                unset($values['password3']);

                if (!preg_match("/[A-Z]{2,4}$/", trim($values[GenerisRdf::PROPERTY_USER_UILG]))) {
                    unset($values[GenerisRdf::PROPERTY_USER_UILG]);
                }
                if (!preg_match("/[A-Z]{2,4}$/", trim($values[GenerisRdf::PROPERTY_USER_DEFLG]))) {
                    unset($values[GenerisRdf::PROPERTY_USER_DEFLG]);
                }

                $userService->checkCurrentUserAccess($values[GenerisRdf::PROPERTY_USER_ROLES]);

                // leave roles which are not in the allowed list for current user
                $oldRoles = $userService->getUserRoles($user);
                $allowedRoles = $userService->getPermittedRoles($userService->getCurrentUser(), $oldRoles, false);
                $staticRoles = array_diff($oldRoles, $allowedRoles);
                $values[GenerisRdf::PROPERTY_USER_ROLES] = array_merge($values[GenerisRdf::PROPERTY_USER_ROLES], $staticRoles);

                $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($user);

                if ($binder->bind($values)) {
                    $data = [];
                    if (isset($plainPassword)){
                        $data = ['hashForKey' => UserHashForEncryption::hash($plainPassword)];
                    }
                    $this->getEventManager()->trigger(new UserUpdatedEvent(
                        $user,
                        array_merge($values, $data))
                    );
                    $this->setData('message', __('User saved'));
                }
            }
        }

        $this->setData('formTitle', __('Edit a user'));
        $this->setData('myForm', $myForm->render());
        $this->setView('user/form.tpl');
    }
public function edit ( ) { $ this -> defaultData ( ) ; $ userService = $ this -> getServiceLocator ( ) -> get ( tao_models_classes_UserService :: class ) ; $ user = $ this -> getUserResource ( ) ; $ types = $ user -> getTypes ( ) ; $ myFormContainer = new tao_actions_form_Users ( reset ( $ types ) , $ user ) ; $ myForm = $ myFormContainer -> getForm ( ) ; if ( $ myForm -> isSubmited ( ) ) { if ( $ myForm -> isValid ( ) ) { $ values = $ myForm -> getValues ( ) ; if ( ! empty ( $ values [ 'password2' ] ) && ! empty ( $ values [ 'password3' ] ) ) { $ plainPassword = $ values [ 'password2' ] ; $ values [ GenerisRdf :: PROPERTY_USER_PASSWORD ] = core_kernel_users_Service :: getPasswordHash ( ) -> encrypt ( $ values [ 'password2' ] ) ; } unset ( $ values [ 'password2' ] ) ; unset ( $ values [ 'password3' ] ) ; if ( ! preg_match ( "/[A-Z]{2,4}$/" , trim ( $ values [ GenerisRdf :: PROPERTY_USER_UILG ] ) ) ) { unset ( $ values [ GenerisRdf :: PROPERTY_USER_UILG ] ) ; } if ( ! preg_match ( "/[A-Z]{2,4}$/" , trim ( $ values [ GenerisRdf :: PROPERTY_USER_DEFLG ] ) ) ) { unset ( $ values [ GenerisRdf :: PROPERTY_USER_DEFLG ] ) ; } $ userService -> checkCurrentUserAccess ( $ values [ GenerisRdf :: PROPERTY_USER_ROLES ] ) ; // leave roles which are not in the allowed list for current user $ oldRoles = $ userService -> getUserRoles ( $ user ) ; $ allowedRoles = $ userService -> getPermittedRoles ( $ userService -> getCurrentUser ( ) , $ oldRoles , false ) ; $ staticRoles = array_diff ( $ oldRoles , $ allowedRoles ) ; $ values [ GenerisRdf :: PROPERTY_USER_ROLES ] = array_merge ( $ values [ GenerisRdf :: PROPERTY_USER_ROLES ] , $ staticRoles ) ; $ binder = new tao_models_classes_dataBinding_GenerisFormDataBinder ( $ user ) ; if ( $ binder -> bind ( $ values ) ) { $ data = [ ] ; if ( isset ( $ plainPassword ) ) { $ data = [ 'hashForKey' => UserHashForEncryption :: hash ( $ plainPassword ) ] ; } $ this -> getEventManager ( ) -> trigger ( new UserUpdatedEvent ( $ user , array_merge ( $ values , $ data ) ) ) ; $ this -> setData ( 'message' , __ ( 'User saved' ) ) ; } } } $ this -> setData ( 'formTitle' , __ ( 'Edit a user' ) ) ; $ this -> setData ( 'myForm' , $ myForm -> render ( ) ) ; $ this -> setView ( 'user/form.tpl' ) ; }
Form to edit a user
User login must be set in parameter
@return void
@throws Exception
@throws \oat\generis\model\user\PasswordConstraintsException
@throws common_exception_Error
@throws tao_models_classes_dataBinding_GenerisFormDataBindingException
Form to edit a user User login must be set in parameter