Skip to content

Commit 1f61709

Browse files
authored
[yggdrasil-connect] respond player name with correct capitalization during authentication (#242)
1 parent f4a1b22 commit 1f61709

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

plugins/yggdrasil-connect/src/Controllers/AuthController.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ public function authenticate(Request $request): JsonResponse
4646
$resp['user'] = ['id' => User::getUserUuid($user), 'properties' => []];
4747
}
4848

49-
if (!filter_var($identification, FILTER_VALIDATE_EMAIL)) {
50-
// 如果是角色名登录,就直接绑定角色
51-
$resp['selectedProfile'] = [
52-
'id' => Profile::getUuidFromName($identification),
53-
'name' => $identification,
54-
];
55-
$resp['availableProfiles'] = [$resp['selectedProfile']];
56-
} elseif (count($availableProfiles) === 1) {
49+
if (count($availableProfiles) === 1) {
5750
// 当用户只有一个角色时自动帮他选择
5851
$resp['selectedProfile'] = $availableProfiles[0];
5952
$resp['availableProfiles'] = [$availableProfiles[0]];
53+
} elseif (!filter_var($identification, FILTER_VALIDATE_EMAIL)) {
54+
// 如果是角色名登录,就直接绑定角色
55+
foreach ($availableProfiles as $profile) {
56+
if (strcasecmp($profile['name'], $identification) === 0) {
57+
$resp['selectedProfile'] = $profile;
58+
$resp['availableProfiles'] = [$profile];
59+
break;
60+
}
61+
}
6062
} else {
6163
$resp['availableProfiles'] = $availableProfiles;
6264
}

0 commit comments

Comments
 (0)