Skip to content

Commit

Permalink
Merge pull request #83 from geteduroam/feaure/GETEDUROAM-66
Browse files Browse the repository at this point in the history
GETEDUROAM-66: Enforce realm in username / password dialog
  • Loading branch information
dzolnai authored Apr 25, 2024
2 parents 3e8ecbb + b8ae061 commit 35993c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ fun UsernamePasswordDialog(
var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var passwordVisible by rememberSaveable { mutableStateOf(false) }
var usernameError by remember { mutableStateOf<String?>(null) }

val keyboardController = LocalSoftwareKeyboardController.current
val requiredSuffixError = requiredSuffix?.let { stringResource(id = R.string.username_password_error_required_suffix, it) }
Column {
Surface(
shape = MaterialTheme.shapes.medium
Expand Down Expand Up @@ -91,6 +94,15 @@ fun UsernamePasswordDialog(
onValueChange = {
username = it
},
supportingText = {
usernameError?.let { nonNullError ->
Text(
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
text = nonNullError,
color = MaterialTheme.colorScheme.error
)
}
},
textStyle = LocalTextStyle.current.copy(textDirection = TextDirection.Ltr),
maxLines = 1,
singleLine = true,
Expand Down Expand Up @@ -165,7 +177,12 @@ fun UsernamePasswordDialog(
Spacer(modifier = Modifier.size(8.dp))
Button(
onClick = {
logIn(username, password)
if (!requiredSuffix.isNullOrEmpty() && !username.endsWith(requiredSuffix, ignoreCase = false)) {
usernameError = requiredSuffixError
} else {
usernameError = null
logIn(username, password)
}
},
enabled = username.isNotBlank() && password.isNotBlank()
) {
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<string name="username_password_label_password">Password</string>
<string name="username_password_button_cancel">Cancel</string>
<string name="username_password_button_log_in">Log in</string>
<string name="username_password_error_required_suffix">Username should end with: %s</string>

<string name="username_password_placeholder_username_example_suffix">example.com</string>
<string name="username_password_placeholder_username_before_suffix">username</string>
Expand Down

0 comments on commit 35993c0

Please sign in to comment.