mirror of
https://github.com/humhub/humhub.git
synced 2025-04-20 15:11:52 +02:00
Refactor Registration Form Options (#7477)
* Refactor Registration Form Options * Update CHANGELOG.md * Update MIGRATE-DEV.md
This commit is contained in:
parent
6a612c93f5
commit
3b6ec3d127
@ -8,6 +8,7 @@ HumHub Changelog
|
||||
- Fix #7465: Formatted Arabic numbers displays 0 instead of the number
|
||||
- Fix #7471: Fix advanced searching by space filter
|
||||
- Fix #7472: Fix missing fields when creating a new user from admin
|
||||
- Fix #7477: Refactor Registration Form Options
|
||||
|
||||
1.17.1 (March 6, 2025)
|
||||
----------------------
|
||||
|
@ -1,13 +1,14 @@
|
||||
Module Migration Guide
|
||||
======================
|
||||
|
||||
Version 1.17.1
|
||||
Version 1.17.2
|
||||
---------------
|
||||
|
||||
### Behaviour change
|
||||
|
||||
- Method signature changed - `humhub\modules\user\models\fieldtype\BaseType::getUserValue(User $user, bool $raw = true, bool $encode = true): ?string`
|
||||
|
||||
- Constructor changed - `humhub\modules\user\models\forms\Registration` and properties (`$enablePasswordForm`, `$enableMustChangePassword`, `$enableEmailField`) are now private
|
||||
|
||||
|
||||
Version 1.17
|
||||
|
@ -261,11 +261,8 @@ class UserController extends Controller
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
$registration = new Registration([], null, [
|
||||
'enableEmailField' => true,
|
||||
'enableUserApproval' => false,
|
||||
'enableMustChangePassword' => true,
|
||||
]);
|
||||
$registration = new Registration(enableEmailField: true, enablePasswordForm: true, enableMustChangePassword: true);
|
||||
$registration->enableUserApproval = true;
|
||||
|
||||
if ($registration->submitted('save') && $registration->validate() && $registration->register()) {
|
||||
return $this->redirect(['edit', 'id' => $registration->getUser()->id]);
|
||||
|
@ -92,7 +92,7 @@ class RegistrationController extends Controller
|
||||
$inviteRegistrationService->populateRegistration($registration);
|
||||
} elseif (Yii::$app->session->has('authClient')) {
|
||||
$authClient = Yii::$app->session->get('authClient');
|
||||
$this->handleAuthClientRegistration($authClient, $registration);
|
||||
$registration = $this->createRegistrationByAuthClient($authClient);
|
||||
} else {
|
||||
Yii::warning('Registration failed: No token (query) or authclient (session) found!', 'user');
|
||||
Yii::$app->session->setFlash('error', 'Registration failed.');
|
||||
@ -173,7 +173,7 @@ class RegistrationController extends Controller
|
||||
* @param Registration $registration
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function handleAuthClientRegistration(ClientInterface $authClient, Registration $registration)
|
||||
protected function createRegistrationByAuthClient(ClientInterface $authClient): Registration
|
||||
{
|
||||
$attributes = $authClient->getUserAttributes();
|
||||
|
||||
@ -181,7 +181,8 @@ class RegistrationController extends Controller
|
||||
throw new Exception("No user id given by authclient!");
|
||||
}
|
||||
|
||||
$registration->enablePasswordForm = false;
|
||||
$registration = new Registration(enablePasswordForm: false);
|
||||
|
||||
if ($authClient instanceof ApprovalBypass) {
|
||||
$registration->enableUserApproval = false;
|
||||
}
|
||||
@ -191,5 +192,7 @@ class RegistrationController extends Controller
|
||||
|
||||
$registration->getUser()->setAttributes($attributes, false);
|
||||
$registration->getProfile()->setAttributes($attributes, false);
|
||||
|
||||
return $registration;
|
||||
}
|
||||
}
|
||||
|
@ -36,17 +36,17 @@ class Registration extends HForm
|
||||
/**
|
||||
* @var bool show password creation form
|
||||
*/
|
||||
public $enablePasswordForm = true;
|
||||
private $enablePasswordForm;
|
||||
|
||||
/**
|
||||
* @var bool show checkbox to force to change password on first log in
|
||||
*/
|
||||
public $enableMustChangePassword = false;
|
||||
private $enableMustChangePassword;
|
||||
|
||||
/**
|
||||
* @var bool show e-mail field
|
||||
*/
|
||||
public $enableEmailField = false;
|
||||
private $enableEmailField;
|
||||
|
||||
/**
|
||||
* @var bool|null require user approval by admin after registration.
|
||||
@ -73,6 +73,21 @@ class Registration extends HForm
|
||||
*/
|
||||
private $_profile = null;
|
||||
|
||||
public function __construct(
|
||||
$definition = [],
|
||||
$primaryModel = null,
|
||||
array $config = [],
|
||||
bool $enableEmailField = false,
|
||||
bool $enablePasswordForm = true,
|
||||
bool $enableMustChangePassword = false
|
||||
) {
|
||||
$this->enableEmailField = $enableEmailField;
|
||||
$this->enablePasswordForm = $enablePasswordForm;
|
||||
$this->enableMustChangePassword = $enableMustChangePassword;
|
||||
|
||||
parent::__construct($definition, $primaryModel, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -102,7 +117,8 @@ class Registration extends HForm
|
||||
if ($this->enablePasswordForm) {
|
||||
$this->definition['elements']['Password'] = $this->getPasswordFormDefinition();
|
||||
}
|
||||
$this->definition['elements']['Profile'] = array_merge(['type' => 'form'], $this->getProfile()->getFormDefinition());
|
||||
$this->definition['elements']['Profile'] = array_merge(['type' => 'form'],
|
||||
$this->getProfile()->getFormDefinition());
|
||||
$this->definition['buttons'] = [
|
||||
'save' => [
|
||||
'type' => 'submit',
|
||||
@ -181,7 +197,9 @@ class Registration extends HForm
|
||||
{
|
||||
$groupModels = Group::getRegistrationGroups($this->getUser());
|
||||
|
||||
$groupFieldType = (Yii::$app->getModule('user')->settings->get('auth.showRegistrationUserGroup') && count($groupModels) > 1)
|
||||
$groupFieldType = (Yii::$app->getModule('user')->settings->get('auth.showRegistrationUserGroup') && count(
|
||||
$groupModels
|
||||
) > 1)
|
||||
? 'dropdownlist'
|
||||
: 'hidden'; // TODO: Completely hide the element instead of current <input type="hidden">
|
||||
|
||||
@ -266,7 +284,6 @@ class Registration extends HForm
|
||||
}
|
||||
|
||||
if ($this->models['User']->save()) {
|
||||
|
||||
// Save User Profile
|
||||
$this->models['Profile']->user_id = $this->models['User']->id;
|
||||
$this->models['Profile']->save();
|
||||
@ -290,7 +307,10 @@ class Registration extends HForm
|
||||
|
||||
if ($authClient !== null) {
|
||||
(new AuthClientUserService($this->models['User']))->add($authClient);
|
||||
$authClient->trigger(BaseClient::EVENT_CREATE_USER, new UserEvent(['identity' => $this->models['User']]));
|
||||
$authClient->trigger(
|
||||
BaseClient::EVENT_CREATE_USER,
|
||||
new UserEvent(['identity' => $this->models['User']])
|
||||
);
|
||||
}
|
||||
|
||||
$this->trigger(self::EVENT_AFTER_REGISTRATION, new UserEvent(['identity' => $this->models['User']]));
|
||||
|
@ -123,10 +123,7 @@ class AuthClientService
|
||||
return null;
|
||||
}
|
||||
|
||||
$registration = new Registration([], null, [
|
||||
'enablePasswordForm' => false,
|
||||
'enableEmailField' => true,
|
||||
]);
|
||||
$registration = new Registration(enablePasswordForm: false, enableEmailField: true);
|
||||
|
||||
if ($this->authClient instanceof ApprovalBypass) {
|
||||
$registration->enableUserApproval = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user