Unverified Commit a63ed591 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #855 from RocketChat/feature/login-with-ldap

[NEW] Login with ldap
parents 8e746265 ff4f95e2
...@@ -11,12 +11,10 @@ import chat.rocket.android.util.extensions.isEmailValid ...@@ -11,12 +11,10 @@ import chat.rocket.android.util.extensions.isEmailValid
import chat.rocket.android.util.extensions.launchUI import chat.rocket.android.util.extensions.launchUI
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.common.RocketChatTwoFactorException import chat.rocket.common.RocketChatTwoFactorException
import chat.rocket.common.model.Token
import chat.rocket.common.util.ifNull import chat.rocket.common.util.ifNull
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.login import chat.rocket.core.internal.rest.*
import chat.rocket.core.internal.rest.loginWithEmail
import chat.rocket.core.internal.rest.me
import chat.rocket.core.internal.rest.registerPushToken
import javax.inject.Inject import javax.inject.Inject
class LoginPresenter @Inject constructor(private val view: LoginView, class LoginPresenter @Inject constructor(private val view: LoginView,
...@@ -95,20 +93,31 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -95,20 +93,31 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
view.showLoading() view.showLoading()
try { try {
val token = if (usernameOrEmail.isEmailValid()) { var token: Token? = null
client.loginWithEmail(usernameOrEmail, password) if (usernameOrEmail.isEmailValid()) {
token = client.loginWithEmail(usernameOrEmail, password)
} else { } else {
client.login(usernameOrEmail, password) val settings = settingsInteractor.get(server)
if (settings != null) {
token = if (settings.ldapEnabled()) {
client.loginWithLdap(usernameOrEmail, password)
} else {
client.login(usernameOrEmail, password)
}
} else {
navigator.toServerScreen()
}
} }
val me = client.me() if (token != null) {
multiServerRepository.save( val me = client.me()
server, multiServerRepository.save(server, TokenModel(token.userId, token.authToken))
TokenModel(token.userId, token.authToken) localRepository.save(LocalRepository.USERNAME_KEY, me.username)
) registerPushToken()
localRepository.save(LocalRepository.USERNAME_KEY, me.username) navigator.toChatList()
registerPushToken() } else {
navigator.toChatList() view.showGenericErrorMessage()
}
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
when (exception) { when (exception) {
is RocketChatTwoFactorException -> { is RocketChatTwoFactorException -> {
......
...@@ -58,6 +58,7 @@ fun PublicSettings.gitlabEnabled(): Boolean = this[ACCOUNT_GITLAB]?.value == tru ...@@ -58,6 +58,7 @@ fun PublicSettings.gitlabEnabled(): Boolean = this[ACCOUNT_GITLAB]?.value == tru
fun PublicSettings.wordpressEnabled(): Boolean = this[ACCOUNT_WORDPRESS]?.value == true fun PublicSettings.wordpressEnabled(): Boolean = this[ACCOUNT_WORDPRESS]?.value == true
fun PublicSettings.useRealName(): Boolean = this[USE_REALNAME]?.value == true fun PublicSettings.useRealName(): Boolean = this[USE_REALNAME]?.value == true
fun PublicSettings.ldapEnabled(): Boolean = this[LDAP_ENABLE]?.value == true
// Message settings // Message settings
fun PublicSettings.showDeletedStatus(): Boolean = this[SHOW_DELETED_STATUS]?.value == true fun PublicSettings.showDeletedStatus(): Boolean = this[SHOW_DELETED_STATUS]?.value == true
......
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