Commit 00fe8b78 authored by Wilko Manger's avatar Wilko Manger

Merge branch 'master' into 'master'

Make the username input more flexible and case-insensitive

See merge request !8
parents cb1f6d02 01a5edac
Pipeline #271 passed with stages
in 3 minutes
......@@ -76,29 +76,33 @@ class UsernameFragment : StartBaseFragment() {
setError(null)
val username: String
val localpart: String
// Check if there is an '@' and ':' in the username,
// if so, treat it as a full Matrix ID, otherwise just
// use the local part.
if (text.startsWith('@') && text.contains(':')) {
val (localpart, serverName) = text.split(':', limit = 2)
username = localpart.trimStart('@')
// Check if there is a ':' in the username,
// if so, treat it as a full Matrix ID (without or without '@').
// Otherwise use the local part (with or without '@').
if (text.contains(':')) {
val (local, serverName) = text.split(':', limit = 2)
localpart = local
try {
log(serverName)
val serverUrl = Uri.parse("https://$serverName")
model.homeserver = serverUrl
} catch(t: Throwable) {
} catch (t: Throwable) {
setError(getString(R.string.start_username_error_invalid_hostname))
t.printStackTrace()
return
}
} else {
username = text
localpart = text
}
val usernameRegex = Regex("[A-z0-9\\-.=_\\/]+")
// Convert username to lower-case as it is case-insensitive.
username = localpart.trimStart('@').toLowerCase()
val usernameRegex = Regex("[a-z0-9\\-.=_\\/]+")
if (usernameRegex.matchEntire(username) == null) {
setError(getString(R.string.start_username_error_invalid_username))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment