mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Fixed issue with account login
This commit is contained in:
parent
f93e771bab
commit
aedd1a2577
3 changed files with 29 additions and 16 deletions
|
|
@ -92,25 +92,24 @@ class LandingFragment : Fragment() {
|
|||
}
|
||||
|
||||
viewModel.redirectToDigestAuthEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
goToLoginFragment()
|
||||
it.consume { address ->
|
||||
goToLoginFragment(address)
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.redirectToSingleSignOnEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
goToSingleSignOnActivity()
|
||||
it.consume { address ->
|
||||
goToSingleSignOnActivity(address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun goToLoginFragment() {
|
||||
val identity = viewModel.sipIdentity.value.orEmpty()
|
||||
private fun goToLoginFragment(identity: String) {
|
||||
val action = LandingFragmentDirections.actionLandingFragmentToLoginFragment(identity)
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
|
||||
private fun goToSingleSignOnActivity() {
|
||||
private fun goToSingleSignOnActivity(identity: String) {
|
||||
startActivity(Intent(requireContext(), OpenIdActivity::class.java))
|
||||
requireActivity().finish()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,10 +134,20 @@ class AccountLoginViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val identity = sipIdentity.value.orEmpty().trim()
|
||||
val identityAddress = core.interpretUrl(identity, false)
|
||||
identityAddress ?: return@postOnCoreThread
|
||||
if (identityAddress == null) {
|
||||
Log.e("$TAG Can't parse [$identity] as Address!")
|
||||
// TODO: show error
|
||||
return@postOnCoreThread
|
||||
}
|
||||
|
||||
val user = identityAddress.username
|
||||
user ?: return@postOnCoreThread
|
||||
if (user == null) {
|
||||
Log.e(
|
||||
"$TAG Address [${identityAddress.asStringUriOnly()}] doesn't contains an username!"
|
||||
)
|
||||
// TODO: show error
|
||||
return@postOnCoreThread
|
||||
}
|
||||
|
||||
val domain = identityAddress.domain
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import androidx.lifecycle.ViewModel
|
|||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.core.Factory
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class LandingViewModel @UiThread constructor() : ViewModel() {
|
||||
|
|
@ -36,12 +37,12 @@ class LandingViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val sipIdentity = MutableLiveData<String>()
|
||||
|
||||
val redirectToDigestAuthEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
val redirectToDigestAuthEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
val redirectToSingleSignOnEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
val redirectToSingleSignOnEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
var conditionsAndPrivacyPolicyAccepted = false
|
||||
|
|
@ -56,7 +57,7 @@ class LandingViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
@UiThread
|
||||
fun login() {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
coreContext.postOnCoreThread {
|
||||
var identity = sipIdentity.value.orEmpty()
|
||||
if (!identity.startsWith("sip:")) {
|
||||
identity = "sip:$identity"
|
||||
|
|
@ -67,14 +68,17 @@ class LandingViewModel @UiThread constructor() : ViewModel() {
|
|||
val identityAddress = Factory.instance().createAddress(identity)
|
||||
if (identityAddress == null) {
|
||||
// TODO: FIXME: show error
|
||||
Log.e("$TAG Can't parse [$identity] as Address!")
|
||||
return@postOnCoreThread
|
||||
}
|
||||
|
||||
// TODO: SSO or password auth?
|
||||
if (identityAddress.domain == corePreferences.defaultDomain) {
|
||||
redirectToDigestAuthEvent.postValue(Event(true))
|
||||
Log.i("$TAG Address matches default domain, using digest authentication")
|
||||
redirectToDigestAuthEvent.postValue(Event(identityAddress.asStringUriOnly()))
|
||||
} else {
|
||||
redirectToSingleSignOnEvent.postValue(Event(true))
|
||||
Log.i("$TAG Address doesn't match default domain, using Single Sign On")
|
||||
redirectToSingleSignOnEvent.postValue(Event(identityAddress.asStringUriOnly()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue