Android log-in: the server filled in, changed behind a button

4934a5d · gmorell · 2026-12-03 18:14

28 files +337 -53
Message
{commit_body(@commit)}

Files changed

modified android/README.md
+2 −2
@@ -91,7 +91,7 @@ the PKCE verifier kept in the app.
91 91
92 92 The App Links host is `appLinksHost` in `app/build.gradle.kts`
93 93 (`vigil.neiam.org`). It is also the server a fresh install signs in to;
94 −Help → Change server picks another.
94 +Change, next to the server in the OIDC and Username sheets, picks another.
95 95
96 96 In each organization a token can do only what your role there allows, so
97 97 the app shows what you'd see on the web. The QR carries a bearer token in
@@ -131,7 +131,7 @@ Or open this directory in Android Studio and press Run.
131 131 code names `localhost`, which the phone can't reach. Make the token with
132 132 **Mobile app** ticked as usual, then on the phone open **Scan** and,
133 133 under **Or paste it**, give the address above with the token. For the
134 − other ways in, **Help → Change server** to the same address.
134 + other ways in, **Change** next to the server (OIDC or Username sheet) to the same address.
135 135
136 136 Debug builds allow plain `http://`; release builds don't. The app upgrades
137 137 `http://` to `https://` for real domain names (a proxy that doesn't send
modified android/app/src/main/java/org/neiam/vigil/app/auth/login/HelpScreen.kt
+6 −31
@@ -42,10 +42,8 @@ fun HelpScreen(
42 42 qrLocation: String,
43 43 server: String,
44 44 methods: AuthMethods?,
45 − onChangeServer: (String) -> Unit,
46 45 onClose: () -> Unit,
47 46 ) {
48 − var editing by remember { mutableStateOf(false) }
49 47
50 48 Scaffold(
51 49 topBar = {
@@ -95,41 +93,18 @@ fun HelpScreen(
95 93 methods?.username?.reason?.let { Para("Right now: $it") }
96 94
97 95 Section("Server")
98 − Para(server)
99 − TextButton(onClick = { editing = true }) { Text("Change server") }
96 + Para(ServerChoice.host(server))
97 + Para(
98 + "This app signs in to the server above. To use another one, open " +
99 + "${methods?.oidcLabel ?: "the single sign-on sheet"} or Username and tap Change " +
100 + "next to the server; Reset to default goes back to this app's usual one.",
101 + )
100 102 Para(
101 103 "Signing out, or revoking this phone under connected devices on the website, " +
102 104 "removes its access.",
103 105 )
104 106 }
105 107 }
106 −
107 − if (editing) {
108 − var value by remember { mutableStateOf(server) }
109 − AlertDialog(
110 − onDismissRequest = { editing = false },
111 − title = { Text("Server") },
112 − text = {
113 − OutlinedTextField(
114 − value = value,
115 − onValueChange = { value = it },
116 − singleLine = true,
117 − label = { Text("Address") },
118 − keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),
119 − modifier = Modifier.fillMaxWidth(),
120 − )
121 − },
122 − confirmButton = {
123 − TextButton(
124 − onClick = {
125 − if (value.isNotBlank()) onChangeServer(value)
126 − editing = false
127 − },
128 − ) { Text("Use") }
129 − },
130 − dismissButton = { TextButton(onClick = { editing = false }) { Text("Cancel") } },
131 − )
132 − }
133 108 }
134 109
135 110 @Composable
modified android/app/src/main/java/org/neiam/vigil/app/auth/login/LoginFlows.kt
+25 −3
@@ -18,7 +18,14 @@ class LoginFlows(
18 18 val prefs: LoginPrefs,
19 19 val api: LoginApi = LoginApi(),
20 20 ) {
21 − val server: String get() = prefs.server(host.defaultServer)
21 + private val _server = MutableStateFlow(prefs.server(host.defaultServer))
22 +
23 + /** The server in use, shared by the page, the OIDC and the Username sheets. */
24 + val serverState: StateFlow<String> = _server.asStateFlow()
25 + val server: String get() = _server.value
26 +
27 + /** The build's default server (its production host). */
28 + val defaultServer: String get() = LoginPrefs.normalizeServer(host.defaultServer)
22 29
23 30 private val _requestedSheet = MutableStateFlow<LoginSheet?>(null)
24 31
@@ -29,7 +36,22 @@ class LoginFlows(
29 36 _requestedSheet.value = sheet
30 37 }
31 38
32 − fun setServer(server: String) = prefs.setServer(server)
39 + fun setServer(server: String) {
40 + prefs.setServer(server)
41 + _server.value = LoginPrefs.normalizeServer(server)
42 + }
43 +
44 + /**
45 + * The user's edit of the server: applied when it is a server address,
46 + * otherwise the server in use stays and the error says why.
47 + */
48 + fun changeServer(input: String): ServerChoice.Edit =
49 + ServerChoice.edit(server, input).also { if (it.error == null) setServer(it.server) }
50 +
51 + fun resetServer() {
52 + prefs.clearServer()
53 + _server.value = defaultServer
54 + }
33 55
34 56 private var pendingPair: Pair<String, String>? = null
35 57
@@ -50,7 +72,7 @@ class LoginFlows(
50 72 /** Stores the token like Scan does, and remembers the server it belongs to. */
51 73 fun keep(server: String, result: SignedIn) {
52 74 host.save(server, result.token)
53 − prefs.setServer(server)
75 + setServer(server)
54 76 result.email?.let { prefs.lastEmail = it }
55 77 }
56 78
modified android/app/src/main/java/org/neiam/vigil/app/auth/login/LoginHost.kt
+54 −1
@@ -61,12 +61,18 @@ fun deviceName(): String {
61 61 class LoginPrefs(context: Context) {
62 62 private val prefs = context.getSharedPreferences("login_prefs", Context.MODE_PRIVATE)
63 63
64 − fun server(default: String): String = prefs.getString(KEY_SERVER, null) ?: default
64 + /** The last server used, else the build's default (`ServerChoice.initial`). */
65 + fun server(default: String): String = ServerChoice.initial(prefs.getString(KEY_SERVER, null), default)
65 66
66 67 fun setServer(server: String) {
67 68 prefs.edit().putString(KEY_SERVER, normalizeServer(server)).apply()
68 69 }
69 70
71 + /** Back to the build's default: forget the chosen server. */
72 + fun clearServer() {
73 + prefs.edit().remove(KEY_SERVER).apply()
74 + }
75 +
70 76 var lastEmail: String?
71 77 get() = prefs.getString(KEY_EMAIL, null)
72 78 set(v) = prefs.edit().putString(KEY_EMAIL, v).apply()
@@ -109,3 +115,50 @@ class LoginPrefs(context: Context) {
109 115 normalizeServer(a).lowercase() == normalizeServer(b).lowercase()
110 116 }
111 117 }
118 +
119 +/**
120 + * Which server the log-in page talks to. The build's default (its
121 + * production host, `BuildConfig.DEFAULT_SERVER`) unless the user picked
122 + * another, which is remembered; an edit that isn't a server address keeps
123 + * the one in use and says why.
124 + */
125 +object ServerChoice {
126 + data class Edit(val server: String, val error: String?)
127 +
128 + const val INVALID = "That isn't a server address. Enter one like app.example.org."
129 +
130 + /** The saved server if it is still a valid one, else the default. */
131 + fun initial(saved: String?, default: String): String =
132 + saved?.let(::parse) ?: LoginPrefs.normalizeServer(default)
133 +
134 + /**
135 + * `app.example.org`, `https://app.example.org/` or `http://10.0.2.2:4000`
136 + * → `https://app.example.org` (no trailing slash); null for anything that
137 + * isn't a bare http(s) server address (no path, query, user or spaces).
138 + */
139 + fun parse(raw: String): String? {
140 + val t = raw.trim()
141 + if (t.isEmpty() || t.any { it.isWhitespace() }) return null
142 + val normalized = LoginPrefs.normalizeServer(t)
143 + val uri = runCatching { java.net.URI(normalized) }.getOrNull() ?: return null
144 + val scheme = uri.scheme?.lowercase()
145 + if (scheme != "https" && scheme != "http") return null
146 + val host = uri.host ?: return null
147 + if (host.isBlank() || !host.contains('.') && host != "localhost") return null
148 + if (uri.rawUserInfo != null || uri.rawQuery != null || uri.rawFragment != null) return null
149 + if (!uri.rawPath.isNullOrEmpty() && uri.rawPath != "/") return null
150 + val port = if (uri.port > 0) ":${uri.port}" else ""
151 + return "$scheme://${host.lowercase()}$port"
152 + }
153 +
154 + /** The result of the user's edit: the new server, or the current one and an error. */
155 + fun edit(current: String, input: String): Edit =
156 + parse(input)?.let { Edit(it, null) } ?: Edit(current, INVALID)
157 +
158 + fun isDefault(current: String, default: String): Boolean =
159 + LoginPrefs.sameServer(current, default)
160 +
161 + /** `https://app.example.org` → `app.example.org`, for showing. */
162 + fun host(server: String): String =
163 + server.substringAfter("://").trimEnd('/')
164 +}
modified android/app/src/main/java/org/neiam/vigil/app/auth/login/LoginScreen.kt
+46 −13
@@ -27,7 +27,9 @@ import androidx.compose.material3.ModalBottomSheet
27 27 import androidx.compose.material3.Surface
28 28 import androidx.compose.material3.Text
29 29 import androidx.compose.material3.TextButton
30 +import androidx.compose.material3.SheetValue
30 31 import androidx.compose.material3.rememberModalBottomSheetState
32 +import androidx.compose.runtime.rememberUpdatedState
31 33 import androidx.compose.runtime.Composable
32 34 import androidx.compose.runtime.LaunchedEffect
33 35 import androidx.compose.runtime.collectAsState
@@ -68,7 +70,9 @@ fun LoginScreen(
68 70 ) {
69 71 var showHelp by rememberSaveable { mutableStateOf(false) }
70 72 var sheet by rememberSaveable { mutableStateOf<LoginSheet?>(null) }
71 − var server by remember { mutableStateOf(flows.server) }
73 + var editingServer by rememberSaveable { mutableStateOf(false) }
74 + // The last server used, else the build's default: methods load at once.
75 + val server by flows.serverState.collectAsState()
72 76 var reload by remember { mutableIntStateOf(0) }
73 77 var methods by remember { mutableStateOf<AuthMethods?>(null) }
74 78 var loadError by remember { mutableStateOf<String?>(null) }
@@ -104,10 +108,6 @@ fun LoginScreen(
104 108 qrLocation = flows.host.qrLocation,
105 109 server = server,
106 110 methods = methods,
107 − onChangeServer = {
108 − flows.setServer(it)
109 − server = flows.server
110 − },
111 111 onClose = { showHelp = false },
112 112 )
113 113 return
@@ -124,6 +124,9 @@ fun LoginScreen(
124 124 val compactHeight = maxHeight < 420.dp
125 125 val narrowHeader = maxWidth * HEADER_WEIGHT < 200.dp
126 126
127 + // Unreachable server: OIDC and Username still open, since their
128 + // sheets are where the server is changed.
129 + val reachable = loadError == null
127 130 val buttons: @Composable (Modifier) -> Unit = { mod ->
128 131 MethodButton(
129 132 title = "Scan",
@@ -138,7 +141,7 @@ fun LoginScreen(
138 141 title = "OIDC",
139 142 description = m.oidcLabel,
140 143 icon = Icons.Default.Key,
141 − method = m.oidc,
144 + method = if (reachable) m.oidc else AuthMethods.Method(true),
142 145 compact = compactHeight,
143 146 modifier = mod,
144 147 onClick = { sheet = LoginSheet.Oidc },
@@ -151,7 +154,7 @@ fun LoginScreen(
151 154 else -> "Email me a sign-in link"
152 155 },
153 156 icon = Icons.Default.Person,
154 − method = m.username,
157 + method = if (reachable) m.username else AuthMethods.Method(true),
155 158 compact = compactHeight,
156 159 modifier = mod,
157 160 onClick = { sheet = LoginSheet.Username },
@@ -193,11 +196,29 @@ fun LoginScreen(
193 196 }
194 197
195 198 sheet?.let { which ->
196 − LoginSheetHost(onDismiss = { sheet = null }) {
199 + LoginSheetHost(
200 + onDismiss = { sheet = null; editingServer = false },
201 + // Back (or a swipe) while the server is being edited closes the
202 + // editor first, not the sheet.
203 + beforeHide = {
204 + if (editingServer) {
205 + editingServer = false
206 + false
207 + } else {
208 + true
209 + }
210 + },
211 + ) {
197 212 when (which) {
198 213 LoginSheet.Scan -> ScanSheet(flows, onSignedIn = { sheet = null; onSignedIn() })
199 − LoginSheet.Oidc -> OidcSheet(flows, m, onDone = { sheet = null })
200 − LoginSheet.Username -> UsernameSheet(flows, m, onSignedIn = { sheet = null; onSignedIn() })
214 + LoginSheet.Oidc -> OidcSheet(
215 + flows, m, editingServer, { editingServer = it },
216 + onDone = { sheet = null },
217 + )
218 + LoginSheet.Username -> UsernameSheet(
219 + flows, m, editingServer, { editingServer = it },
220 + onSignedIn = { sheet = null; onSignedIn() },
221 + )
201 222 }
202 223 }
203 224 }
@@ -297,11 +318,23 @@ private fun MethodButton(
297 318 }
298 319 }
299 320
300 −/** A sheet that back and swipe-down close, back to the log-in page. */
321 +/**
322 + * A sheet that back and swipe-down close, back to the log-in page.
323 + * `beforeHide` may refuse (and do something else instead, e.g. close an
324 + * editor); Material 3 asks it before back, a swipe or a scrim tap hides.
325 + */
301 326 @OptIn(ExperimentalMaterial3Api::class)
302 327 @Composable
303 −private fun LoginSheetHost(onDismiss: () -> Unit, content: @Composable () -> Unit) {
304 − val state = rememberModalBottomSheetState(skipPartiallyExpanded = true)
328 +private fun LoginSheetHost(
329 + onDismiss: () -> Unit,
330 + beforeHide: () -> Boolean,
331 + content: @Composable () -> Unit,
332 +) {
333 + val currentBeforeHide by rememberUpdatedState(beforeHide)
334 + val state = rememberModalBottomSheetState(
335 + skipPartiallyExpanded = true,
336 + confirmValueChange = { it != SheetValue.Hidden || currentBeforeHide() },
337 + )
305 338 ModalBottomSheet(onDismissRequest = onDismiss, sheetState = state) {
306 339 content()
307 340 }
modified android/app/src/main/java/org/neiam/vigil/app/auth/login/Sheets.kt
+123 −2
@@ -6,6 +6,9 @@ import androidx.activity.compose.rememberLauncherForActivityResult
6 6 import androidx.activity.result.contract.ActivityResultContracts
7 7 import androidx.compose.foundation.layout.Arrangement
8 8 import androidx.compose.foundation.layout.Column
9 +import androidx.compose.foundation.layout.Row
10 +import androidx.compose.foundation.layout.FlowRow
11 +import androidx.compose.foundation.layout.ExperimentalLayoutApi
9 12 import androidx.compose.foundation.layout.Spacer
10 13 import androidx.compose.foundation.layout.fillMaxWidth
11 14 import androidx.compose.foundation.layout.height
@@ -23,6 +26,15 @@ import androidx.compose.material3.MaterialTheme
23 26 import androidx.compose.material3.OutlinedButton
24 27 import androidx.compose.material3.OutlinedTextField
25 28 import androidx.compose.material3.Text
29 +import androidx.compose.material3.TextButton
30 +import androidx.compose.runtime.collectAsState
31 +import androidx.compose.runtime.LaunchedEffect
32 +import androidx.compose.ui.Alignment
33 +import androidx.compose.ui.focus.FocusRequester
34 +import androidx.compose.ui.focus.focusRequester
35 +import androidx.compose.ui.semantics.contentDescription
36 +import androidx.compose.ui.text.TextRange
37 +import androidx.compose.ui.text.input.TextFieldValue
26 38 import androidx.compose.runtime.Composable
27 39 import androidx.compose.runtime.getValue
28 40 import androidx.compose.runtime.mutableStateOf
@@ -79,6 +91,97 @@ private fun Status(text: String?, error: Boolean) {
79 91
80 92 private val buttonHeight = Modifier.fillMaxWidth().sizeIn(minHeight = 48.dp)
81 93
94 +/**
95 + * The server the OIDC and Username sheets sign in to: shown as text (the
96 + * host large), with Change. Change opens an editor already filled in with
97 + * the server in use (not a hint), Use applies it, Reset to default goes back
98 + * to the build's server. An address that isn't one keeps the server in use
99 + * and says why. `editing` is the log-in page's, so back closes the editor
100 + * before the sheet.
101 + */
102 +@OptIn(ExperimentalLayoutApi::class)
103 +@Composable
104 +fun ServerRow(flows: LoginFlows, editing: Boolean, onEditingChange: (Boolean) -> Unit) {
105 + val server by flows.serverState.collectAsState()
106 + val isDefault = ServerChoice.isDefault(server, flows.defaultServer)
107 + var error by remember { mutableStateOf<String?>(null) }
108 +
109 + if (!editing) {
110 + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
111 + Column(
112 + Modifier.weight(1f).semantics(mergeDescendants = true) {
113 + contentDescription = "Server: ${ServerChoice.host(server)}"
114 + },
115 + ) {
116 + Text(
117 + "Server",
118 + style = MaterialTheme.typography.labelMedium,
119 + color = MaterialTheme.colorScheme.onSurfaceVariant,
120 + )
121 + Text(ServerChoice.host(server), style = MaterialTheme.typography.titleMedium)
122 + if (!isDefault) {
123 + Text(
124 + "Not this app's usual server",
125 + style = MaterialTheme.typography.bodySmall,
126 + color = MaterialTheme.colorScheme.onSurfaceVariant,
127 + )
128 + }
129 + }
130 + TextButton(
131 + onClick = { error = null; onEditingChange(true) },
132 + modifier = Modifier.sizeIn(minHeight = 48.dp),
133 + ) { Text("Change") }
134 + }
135 + return
136 + }
137 +
138 + // Filled in with the server in use, cursor at the end, ready to edit.
139 + var value by remember {
140 + mutableStateOf(TextFieldValue(server, selection = TextRange(server.length)))
141 + }
142 + val focus = remember { FocusRequester() }
143 + LaunchedEffect(Unit) { focus.requestFocus() }
144 +
145 + fun use() {
146 + val result = flows.changeServer(value.text)
147 + error = result.error
148 + if (result.error == null) onEditingChange(false)
149 + }
150 +
151 + OutlinedTextField(
152 + value = value,
153 + onValueChange = { value = it; error = null },
154 + label = { Text("Server") },
155 + singleLine = true,
156 + isError = error != null,
157 + supportingText = error?.let { { Text(it) } },
158 + keyboardOptions = KeyboardOptions(
159 + keyboardType = KeyboardType.Uri,
160 + autoCorrect = false,
161 + imeAction = ImeAction.Done,
162 + ),
163 + keyboardActions = KeyboardActions(onDone = { use() }),
164 + modifier = Modifier.fillMaxWidth().focusRequester(focus),
165 + )
166 + FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
167 + Button(onClick = ::use, modifier = Modifier.sizeIn(minHeight = 48.dp)) { Text("Use") }
168 + TextButton(
169 + onClick = { error = null; onEditingChange(false) },
170 + modifier = Modifier.sizeIn(minHeight = 48.dp),
171 + ) { Text("Cancel") }
172 + if (!isDefault) {
173 + TextButton(
174 + onClick = {
175 + flows.resetServer()
176 + error = null
177 + onEditingChange(false)
178 + },
179 + modifier = Modifier.sizeIn(minHeight = 48.dp),
180 + ) { Text("Reset to default (${ServerChoice.host(flows.defaultServer)})") }
181 + }
182 + }
183 +}
184 +
82 185 /**
83 186 * Scan: the existing pairing, unchanged. A QR from the web holds the server
84 187 * and a device token; the app checks the token and keeps it. The camera
@@ -196,11 +299,19 @@ fun ScanSheet(flows: LoginFlows, onSignedIn: () -> Unit) {
196 299 * App Link, which the app trades for its device token.
197 300 */
198 301 @Composable
199 −fun OidcSheet(flows: LoginFlows, methods: AuthMethods, onDone: () -> Unit) {
302 +fun OidcSheet(
303 + flows: LoginFlows,
304 + methods: AuthMethods,
305 + editingServer: Boolean,
306 + onEditingServerChange: (Boolean) -> Unit,
307 + onDone: () -> Unit,
308 +) {
200 309 val context = LocalContext.current
201 310 var error by remember { mutableStateOf<String?>(null) }
202 311
203 312 SheetColumn(methods.oidcLabel) {
313 + ServerRow(flows, editingServer, onEditingServerChange)
314 + if (editingServer) return@SheetColumn
204 315 Text(
205 316 "Your browser opens the sign-in page. When you're done there, you come straight back here.",
206 317 style = MaterialTheme.typography.bodyMedium,
@@ -210,8 +321,10 @@ fun OidcSheet(flows: LoginFlows, methods: AuthMethods, onDone: () -> Unit) {
210 321 if (flows.startOidc(context, methods)) onDone()
211 322 else error = "No browser is available to sign in with."
212 323 },
324 + enabled = methods.oidc.enabled,
213 325 modifier = buttonHeight,
214 326 ) { Text("Continue to ${methods.oidcLabel.removePrefix("Sign in with ")}") }
327 + if (!methods.oidc.enabled) Status(methods.oidc.reason ?: "Not available on this server.", true)
215 328 Status(error, true)
216 329 }
217 330 }
@@ -222,7 +335,13 @@ fun OidcSheet(flows: LoginFlows, methods: AuthMethods, onDone: () -> Unit) {
222 335 */
223 336 @OptIn(ExperimentalComposeUiApi::class)
224 337 @Composable
225 −fun UsernameSheet(flows: LoginFlows, methods: AuthMethods, onSignedIn: () -> Unit) {
338 +fun UsernameSheet(
339 + flows: LoginFlows,
340 + methods: AuthMethods,
341 + editingServer: Boolean,
342 + onEditingServerChange: (Boolean) -> Unit,
343 + onSignedIn: () -> Unit,
344 +) {
226 345 val scope = rememberCoroutineScope()
227 346 var email by rememberSaveable { mutableStateOf(flows.prefs.lastEmail.orEmpty()) }
228 347 var password by remember { mutableStateOf("") }
@@ -265,6 +384,8 @@ fun UsernameSheet(flows: LoginFlows, methods: AuthMethods, onSignedIn: () -> Uni
265 384 }
266 385
267 386 SheetColumn("Sign in with your email") {
387 + ServerRow(flows, editingServer, onEditingServerChange)
388 + if (editingServer) return@SheetColumn
268 389 OutlinedTextField(
269 390 value = email,
270 391 onValueChange = { email = it },
added android/app/src/test/java/org/neiam/vigil/app/auth/login/ServerChoiceTest.kt
+73 −0
@@ -0,0 +1,73 @@
1 +package org.neiam.vigil.app.auth.login
2 +
3 +import org.junit.Assert.assertEquals
4 +import org.junit.Assert.assertFalse
5 +import org.junit.Assert.assertNull
6 +import org.junit.Assert.assertTrue
7 +import org.junit.Test
8 +
9 +class ServerChoiceTest {
10 + private val default = "https://vigil.neiam.org"
11 +
12 + @Test
13 + fun `a fresh install uses the build's default`() {
14 + assertEquals(default, ServerChoice.initial(null, default))
15 + assertEquals(default, ServerChoice.initial(null, "vigil.neiam.org/"))
16 + }
17 +
18 + @Test
19 + fun `the last server used wins over the default`() {
20 + assertEquals("https://other.example", ServerChoice.initial("https://other.example", default))
21 + }
22 +
23 + @Test
24 + fun `a saved value that is no server falls back to the default`() {
25 + assertEquals(default, ServerChoice.initial("not a server", default))
26 + assertEquals(default, ServerChoice.initial("", default))
27 + }
28 +
29 + @Test
30 + fun `an edit is normalised`() {
31 + assertEquals("https://app.example.org", ServerChoice.parse(" app.example.org/ "))
32 + assertEquals("https://app.example.org", ServerChoice.parse("HTTPS://App.Example.org"))
33 + assertEquals("http://10.0.2.2:4000", ServerChoice.parse("http://10.0.2.2:4000"))
34 + assertEquals("http://localhost:4000", ServerChoice.parse("http://localhost:4000"))
35 + }
36 +
37 + @Test
38 + fun `anything that isn't a bare server address is refused`() {
39 + listOf(
40 + "", " ", "app example org", "ftp://app.example.org", "https://",
41 + "https://app.example.org/path", "https://app.example.org/?x=1",
42 + "https://user@app.example.org", "intranet", "vigil://auth",
43 + ).forEach { assertNull(it, ServerChoice.parse(it)) }
44 + }
45 +
46 + @Test
47 + fun `an invalid edit keeps the server in use, with an error`() {
48 + val e = ServerChoice.edit("https://other.example", "no such thing")
49 + assertEquals("https://other.example", e.server)
50 + assertEquals(ServerChoice.INVALID, e.error)
51 + }
52 +
53 + @Test
54 + fun `a valid edit replaces it`() {
55 + val e = ServerChoice.edit(default, "other.example")
56 + assertEquals("https://other.example", e.server)
57 + assertNull(e.error)
58 + }
59 +
60 + @Test
61 + fun `reset to default is offered only off the default`() {
62 + assertTrue(ServerChoice.isDefault("https://VIGIL.neiam.org/", default))
63 + assertFalse(ServerChoice.isDefault("https://other.example", default))
64 + // After a reset the initial choice is the default again.
65 + assertEquals(default, ServerChoice.initial(null, default))
66 + }
67 +
68 + @Test
69 + fun `the host is what the sheets show`() {
70 + assertEquals("vigil.neiam.org", ServerChoice.host(default))
71 + assertEquals("10.0.2.2:4000", ServerChoice.host("http://10.0.2.2:4000"))
72 + }
73 +}
modified docs/app-login.md
+8 −1
@@ -27,8 +27,15 @@ neiam_auth (`NeiamAuth.App`, v0.5.0).
27 27 - **Username**: the email, with "Email me a sign-in link" first. Below it
28 28 are a password field and "Sign in", for accounts that have a password
29 29 (Settings → password on the web).
30 +- **The server**: the last one used, else the build's default
31 + (`DEFAULT_SERVER`, vigil.neiam.org), so the page loads at once. The OIDC and
32 + Username sheets show it as text with **Change**, which opens an editor
33 + already filled in with it: Use applies it, Reset to default goes back to
34 + vigil.neiam.org, and an address that isn't one keeps the server in use with
35 + an error. Back closes the editor before the sheet. If the server can't be
36 + reached, OIDC and Username still open, so it can be changed.
30 37 - **Help** explains each way in, where the QR is, that emailed sign-in links
31 − open the app, and the server in use (which can be changed there).
38 + open the app, and the server in use (changed in the sheets).
32 39
33 40 The code is `android/app/src/main/java/org/neiam/vigil/app/auth/login/`.
34 41 It is the same in every NEIAM app except the package name. The app's own

Parents: a76b392