Prevent login issue if SIP identity is given instead of username in third party account login

This commit is contained in:
Sylvain Berfini 2025-02-25 20:17:18 +01:00
parent a392cf3a6b
commit 8eda500dae
7 changed files with 24 additions and 24 deletions

View file

@ -442,9 +442,9 @@ class AccountCreationViewModel
operationInProgress.postValue(true)
createEnabled.postValue(false)
val usernameValue = username.value
val passwordValue = password.value
if (usernameValue.isNullOrEmpty() || passwordValue.isNullOrEmpty()) {
val usernameValue = username.value.orEmpty().trim()
val passwordValue = password.value.orEmpty().trim()
if (usernameValue.isEmpty() || passwordValue.isEmpty()) {
Log.e("$TAG Either username [$usernameValue] or password is null or empty!")
return
}

View file

@ -172,6 +172,8 @@ open class AccountLoginViewModel
"sip:$userInput@$defaultDomain"
}
}
Log.i("$TAG Computed identity is [$identity] from user input [$userInput]")
val identityAddress = Factory.instance().createAddress(identity)
if (identityAddress == null) {
Log.e("$TAG Can't parse [$identity] as Address!")

View file

@ -181,21 +181,21 @@ class ThirdPartySipAccountLoginViewModel
// Allow to enter SIP identity instead of simply username
// in case identity domain doesn't match proxy domain
val user = username.value.orEmpty().trim()
val userId = authId.value.orEmpty().trim()
val identity = if (user.startsWith("sip:")) {
if (user.contains("@")) {
user
} else {
"$user@$domain"
}
} else {
if (user.contains("@")) {
"sip:$user"
} else {
"sip:$user@$domain"
}
var user = username.value.orEmpty().trim()
if (user.startsWith("sip:")) {
user = user.substring("sip:".length)
} else if (user.startsWith("sips:")) {
user = user.substring("sips:".length)
}
if (user.contains("@")) {
user = user.split("@")[0]
}
val userId = authId.value.orEmpty().trim()
Log.i("$TAG Parsed username is [$user], user ID [$userId] and domain [$domain]")
val identity = "sip:$user@$domain"
val identityAddress = Factory.instance().createAddress(identity)
if (identityAddress == null) {
Log.e("$TAG Can't parse [$identity] as Address!")

View file

@ -74,11 +74,11 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:text="@string/assistant_third_party_sip_account_username_or_identity"
android:text="@{@string/username + `*`}"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintBottom_toTopOf="@id/username"
app:layout_constraintStart_toStartOf="@id/title"/>
app:layout_constraintStart_toStartOf="@id/username"/>
<androidx.appcompat.widget.AppCompatEditText
style="@style/default_text_style"
@ -109,7 +109,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:text="@string/password"
android:text="@{@string/password + `*`}"
app:layout_constraintTop_toBottomOf="@id/username"
app:layout_constraintBottom_toTopOf="@id/password"
app:layout_constraintStart_toStartOf="@id/password"/>

View file

@ -55,7 +55,7 @@
android:layout_marginTop="38dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/assistant_third_party_sip_account_username_or_identity"
android:text="@{@string/username + `*`}"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintStart_toStartOf="@id/username"/>
@ -87,7 +87,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:text="@string/password"
android:text="@{@string/password + `*`}"
app:layout_constraintTop_toBottomOf="@id/username"
app:layout_constraintStart_toStartOf="@id/password"/>

View file

@ -119,7 +119,6 @@
<string name="assistant_third_party_sip_account_warning_explanation">Certaines fonctionnalités telles que les conversations de groupe, les vidéo-conférences, etc… nécessitent un compte &appName;.\n\nCes fonctionnalités seront masquées si vous utilisez un compte SIP tiers.\n\nPour les activer dans un projet commercial, merci de nous contacter.</string>
<string name="assistant_third_party_sip_account_create_linphone_account">Je préfère créer un compte</string>
<string name="assistant_third_party_sip_account_warning_ok">J\'ai compris</string>
<string name="assistant_third_party_sip_account_username_or_identity">Nom d\'utilisateur ou identité SIP*</string>
<string name="assistant_account_register_unavailable_no_push_toast">Notifications push indisponible, la création de compte est donc désactivée.</string>
<string name="assistant_account_register_push_notification_not_received_error">Notification push non reçue, merci de réessayer plus tard</string>
<string name="assistant_account_register_unexpected_error">Un erreur inattendue est survenue, merci de réessayer plus tard</string>

View file

@ -158,7 +158,6 @@
<string name="assistant_third_party_sip_account_warning_explanation">Some features require a &appName; account, such as group messaging, video conferences…\n\nThese features are hidden when you register with a third party SIP account.\n\nTo enable it in a commercial project, please contact us.</string>
<string name="assistant_third_party_sip_account_create_linphone_account">I prefer to create an account</string>
<string name="assistant_third_party_sip_account_warning_ok">I understand</string>
<string name="assistant_third_party_sip_account_username_or_identity">Username or SIP identity*</string>
<string name="assistant_account_register_unavailable_no_push_toast">Push notifications not available, account creation disabled</string>
<string name="assistant_account_register_push_notification_not_received_error">Push notification with auth token not received in 5 seconds, please try again later</string>
<string name="assistant_account_register_unexpected_error">Unexpected error occurred, please try again later</string>