@@ -229,9 +229,10 @@ function update_user_edit_password_section() {
229229 }
230230}
231231
232+ $ hasSingleAuthSource = 1 === count ($ authSources );
232233$ currentAuthSources = (array ) ($ userInfo ['auth_sources ' ] ?? []);
233- if (empty ($ currentAuthSources )) {
234- $ currentAuthSources = [UserAuthSource:: PLATFORM ] ;
234+ if ($ hasSingleAuthSource || empty ($ currentAuthSources )) {
235+ $ currentAuthSources = array_keys ( $ authSources ) ;
235236}
236237$ showPasswordSection = in_array (UserAuthSource::PLATFORM , $ currentAuthSources , true );
237238
@@ -243,32 +244,48 @@ function update_user_edit_password_section() {
243244 '</div> '
244245);
245246
246- $ form ->addElement (
247- 'select ' ,
248- 'auth_source ' ,
249- get_lang ('Authentication methods ' ),
250- $ authSources ,
251- [
252- 'id ' => 'auth_source ' ,
253- 'multiple ' => 'multiple ' ,
254- 'size ' => max (3 , min (count ($ authSources ), 8 )),
255- 'class ' => 'w-full rounded-lg border border-gray-25 bg-white px-3 py-2 text-body-2 text-gray-90 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary ' ,
256- ]
257- );
258- $ form ->addRule ('auth_source ' , get_lang ('Required field ' ), 'required ' );
247+ if ($ hasSingleAuthSource ) {
248+ $ singleAuthSourceLabel = (string ) reset ($ authSources );
249+ $ form ->addElement (
250+ 'static ' ,
251+ null ,
252+ get_lang ('Authentication methods ' ),
253+ htmlspecialchars ($ singleAuthSourceLabel , \ENT_QUOTES , 'UTF-8 ' )
254+ );
255+ } else {
256+ $ form ->addElement (
257+ 'select ' ,
258+ 'auth_source ' ,
259+ get_lang ('Authentication methods ' ),
260+ $ authSources ,
261+ [
262+ 'id ' => 'auth_source ' ,
263+ 'multiple ' => 'multiple ' ,
264+ 'size ' => max (3 , min (count ($ authSources ), 8 )),
265+ 'class ' => 'w-full rounded-lg border border-gray-25 bg-white px-3 py-2 text-body-2 text-gray-90 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary ' ,
266+ ]
267+ );
268+ $ form ->addRule ('auth_source ' , get_lang ('Required field ' ), 'required ' );
269+ }
259270
260271$ form ->addHtml (
261272 '<div id="user-edit-password-section" class="mt-6 rounded-xl border border-gray-25 bg-gray-5 p-4 ' .($ showPasswordSection ? '' : 'hidden ' ).'"> ' .
262273 '<h4 class="mb-3 text-body-1 font-semibold text-gray-90"> ' .get_lang ('Password ' ).'</h4> '
263274);
264275
265- $ form ->addElement ('radio ' , 'reset_password ' , null , get_lang ('Don \'t reset password ' ), 0 );
266- $ form ->addElement ('radio ' , 'reset_password ' , null , get_lang ('Automatically generate a new password ' ), 1 );
276+ $ resetPasswordOptions = [
277+ 0 => get_lang ('Don \'t reset password ' ),
278+ 1 => get_lang ('Automatically generate a new password ' ),
279+ ];
280+
281+ if ($ adminsCanSetUsersPass ) {
282+ $ resetPasswordOptions [2 ] = get_lang ('Set password manually ' );
283+ }
284+
285+ $ form ->addRadio ('reset_password ' , null , $ resetPasswordOptions );
267286
268287if ($ adminsCanSetUsersPass ) {
269- $ group = [];
270- $ group [] = $ form ->createElement ('radio ' , 'reset_password ' , null , get_lang ('Set password manually ' ), 2 );
271- $ group [] = $ form ->createElement (
288+ $ form ->addElement (
272289 'password ' ,
273290 'password ' ,
274291 null ,
@@ -279,9 +296,7 @@ function update_user_edit_password_section() {
279296 'autocomplete ' => 'new-password ' ,
280297 ]
281298 );
282-
283- $ form ->addGroup ($ group , 'password ' , null , null , false );
284- $ form ->addPasswordRule ('password ' , 'password ' );
299+ $ form ->addPasswordRule ('password ' );
285300}
286301
287302$ form ->addHtml ('</div></div> ' );
@@ -439,7 +454,9 @@ function update_user_edit_password_section() {
439454
440455// Set default values
441456$ user_data ['reset_password ' ] = 0 ;
442- $ user_data ['auth_source ' ] = $ currentAuthSources ;
457+ if (!$ hasSingleAuthSource ) {
458+ $ user_data ['auth_source ' ] = $ currentAuthSources ;
459+ }
443460
444461if (!$ hideFields ) {
445462 $ expiration_date = $ user_data ['expiration_date ' ];
@@ -492,8 +509,11 @@ function update_user_edit_password_section() {
492509 }
493510 }
494511 $ allowedAuthSources = array_map ('strval ' , array_keys ($ authSources ));
512+ $ submittedAuthSources = $ hasSingleAuthSource
513+ ? $ allowedAuthSources
514+ : array_map ('strval ' , (array ) ($ user ['auth_source ' ] ?? []));
495515 $ authSource = array_values (array_intersect (
496- array_map ( ' strval ' , ( array ) ( $ user [ ' auth_source ' ] ?? [])) ,
516+ $ submittedAuthSources ,
497517 $ allowedAuthSources
498518 ));
499519
0 commit comments