Commit f4c434e2 authored by aniket's avatar aniket

minor fixes

parent e528cdf2
...@@ -55,6 +55,7 @@ class LoginPresenter @Inject constructor( ...@@ -55,6 +55,7 @@ class LoginPresenter @Inject constructor(
private lateinit var credentialSecret: String private lateinit var credentialSecret: String
private lateinit var deepLinkUserId: String private lateinit var deepLinkUserId: String
private lateinit var deepLinkToken: String private lateinit var deepLinkToken: String
private var loginCredentials: Credential? = null
fun setupView() { fun setupView() {
setupConnectionInfo(currentServer) setupConnectionInfo(currentServer)
...@@ -304,10 +305,12 @@ class LoginPresenter @Inject constructor( ...@@ -304,10 +305,12 @@ class LoginPresenter @Inject constructor(
saveAccount(username) saveAccount(username)
saveToken(token) saveToken(token)
registerPushToken() registerPushToken()
var loginCredentials: Credential = Credential.Builder(usernameOrEmail) if (loginType == TYPE_LOGIN_USER_EMAIL) {
.setPassword(password) loginCredentials = Credential.Builder(usernameOrEmail)
.build() .setPassword(password)
view.saveSmartLockCredentials(loginCredentials) .build()
view.saveSmartLockCredentials(loginCredentials)
}
navigator.toChatList() navigator.toChatList()
} else if (loginType == TYPE_LOGIN_OAUTH) { } else if (loginType == TYPE_LOGIN_OAUTH) {
navigator.toRegisterUsername(token.userId, token.authToken) navigator.toRegisterUsername(token.userId, token.authToken)
......
...@@ -57,6 +57,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -57,6 +57,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener { private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
areLoginOptionsNeeded() areLoginOptionsNeeded()
} }
private var isOauthSuccessful = false
private var isGlobalLayoutListenerSetUp = false private var isGlobalLayoutListenerSetUp = false
private var deepLinkInfo: LoginDeepLinkInfo? = null private var deepLinkInfo: LoginDeepLinkInfo? = null
private var credentialsToBeSaved: Credential? = null private var credentialsToBeSaved: Credential? = null
...@@ -122,6 +123,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -122,6 +123,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
presenter.authenticateWithCas(getStringExtra(INTENT_CAS_TOKEN)) presenter.authenticateWithCas(getStringExtra(INTENT_CAS_TOKEN))
} }
} else if (requestCode == REQUEST_CODE_FOR_OAUTH) { } else if (requestCode == REQUEST_CODE_FOR_OAUTH) {
isOauthSuccessful = true
data?.apply { data?.apply {
presenter.authenticateWithOauth( presenter.authenticateWithOauth(
getStringExtra(INTENT_OAUTH_CREDENTIAL_TOKEN), getStringExtra(INTENT_OAUTH_CREDENTIAL_TOKEN),
...@@ -147,20 +149,12 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -147,20 +149,12 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
} else if (requestCode == MULTIPLE_CREDENTIALS_READ) { } else if (requestCode == MULTIPLE_CREDENTIALS_READ) {
Log.d("STATUS", "failed ") Log.d("STATUS", "failed ")
} }
//cancel button pressed by the user in case of reading from smart lock //cancel button pressed by the user in case of reading from smart lock
else if (resultCode == Activity.RESULT_CANCELED) { else if (resultCode == Activity.RESULT_CANCELED && requestCode == REQUEST_CODE_FOR_OAUTH) {
//add shared preference so that the dialog is not shown always Log.d("returned", "from oauth")
}
//create new account to use it as login account (deal with this case carefully, many edge cases)
else if (resultCode == CredentialsApi.ACTIVITY_RESULT_ADD_ACCOUNT) {
} }
//no hints for user id's exist //no hints for user id's exist
else if (resultCode == CredentialsApi.ACTIVITY_RESULT_NO_HINTS_AVAILABLE) { else if (resultCode == CredentialsApi.ACTIVITY_RESULT_NO_HINTS_AVAILABLE) {
} else {
Log.d("Status", "nothing happening")
} }
} }
...@@ -182,14 +176,14 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -182,14 +176,14 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
requestCredentials() if (!isOauthSuccessful) {
requestCredentials()
}
} }
private fun requestCredentials() { private fun requestCredentials() {
var request: CredentialRequest = CredentialRequest.Builder() var request: CredentialRequest = CredentialRequest.Builder()
.setPasswordLoginSupported(true) .setPasswordLoginSupported(true)
//add account types for custom login methods
/*.setAccountTypes(IdentityProviders.GOOGLE,IdentityProviders.FACEBOOK)*/
.build() .build()
Auth.CredentialsApi.request(googleApiClient, request).setResultCallback { credentialRequestResult -> Auth.CredentialsApi.request(googleApiClient, request).setResultCallback { credentialRequestResult ->
...@@ -224,14 +218,6 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks ...@@ -224,14 +218,6 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
private fun handleCredential(loginCredentials: Credential) { private fun handleCredential(loginCredentials: Credential) {
if (loginCredentials.accountType == null) { if (loginCredentials.accountType == null) {
presenter.authenticateWithUserAndPassword(loginCredentials.id, loginCredentials.password!!) presenter.authenticateWithUserAndPassword(loginCredentials.id, loginCredentials.password!!)
} else if (loginCredentials.accountType == IdentityProviders.GOOGLE) {
//TODO add SL code for google as custom login method
} else if (loginCredentials.accountType == IdentityProviders.FACEBOOK) {
//TODO add SL code for facebook as custom login method
} else if (loginCredentials.accountType == IdentityProviders.TWITTER) {
//TODO add SL code for twitter as custom login method
} else if (loginCredentials.accountType == IdentityProviders.LINKEDIN) {
//TODO add SL code for linkedin as custom login method
} }
} }
......
...@@ -40,7 +40,6 @@ class OauthWebViewActivity : AppCompatActivity() { ...@@ -40,7 +40,6 @@ class OauthWebViewActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_view) setContentView(R.layout.activity_web_view)
webPageUrl = intent.getStringExtra(INTENT_WEB_PAGE_URL) webPageUrl = intent.getStringExtra(INTENT_WEB_PAGE_URL)
requireNotNull(webPageUrl) { "no web_page_url provided in Intent extras" } requireNotNull(webPageUrl) { "no web_page_url provided in Intent extras" }
......
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