Commit 0fd3374c authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fix the CAS button not showing and stylizes the CAS button in the basis of the server settings.

parent a3f7898b
......@@ -113,25 +113,26 @@ interface LoginOptionsView : LoadingView, MessageView {
// CAS account.
/**
* Shows the CAS button if the sign in/sign out via CAS protocol is enabled by the server
* settings.
* Adds a CAS button into accounts container.
*
* REMARK: We must set up the CAS button listener before showing it [setupCasButtonListener].
* @param casUrl The CAS url.
* @param casToken The CAS token
* @param serviceName The SAML service name.
* @param serviceNameColor The SAML service name color (just stylizing).
* @param buttonColor The SAML button color (just stylizing).
* @see [showAccountsView]
*/
fun enableLoginByCas()
/**
* Setups the CAS button.
*
* @param casUrl The CAS URL to authenticate with.
* @param casToken The requested token to be sent to the CAS server.
*/
fun setupCasButtonListener(casUrl: String, casToken: String)
fun addCasButton(
caslUrl: String,
casToken: String,
serviceName: String,
serviceNameColor: Int,
buttonColor: Int
)
// Custom OAuth account.
/**
* Adds a custom OAuth button in the accounts container.
* Adds a custom OAuth button into accounts container.
*
* @customOauthUrl The custom OAuth url.
* @state A random string generated by the app, which you'll verify later
......@@ -151,12 +152,13 @@ interface LoginOptionsView : LoadingView, MessageView {
// SAML account.
/**
* Adds a SAML button in the accounts container.
* Adds a SAML button into accounts container.
*
* @samlUrl The SAML url.
* @serviceName The SAML service name.
* @serviceNameColor The SAML service name color (just stylizing).
* @buttonColor The SAML button color (just stylizing).
* @param samlUrl The SAML url.
* @param samlToken The SAML token.
* @param serviceName The SAML service name.
* @param serviceNameColor The SAML service name color (just stylizing).
* @param buttonColor The SAML button color (just stylizing).
* @see [showAccountsView]
*/
fun addSamlButton(
......
......@@ -40,6 +40,9 @@ private const val GITLAB_OAUTH_URL = "gitlab_oauth_url"
private const val WORDPRESS_OAUTH_URL = "wordpress_oauth_url"
private const val CAS_LOGIN_URL = "cas_login_url"
private const val CAS_TOKEN = "cas_token"
private const val CAS_SERVICE_NAME = "cas_service_name"
private const val CAS_SERVICE_NAME_TEXT_COLOR = "cas_service_name_text_color"
private const val CAS_SERVICE_BUTTON_COLOR = "cas_service_button_color"
private const val CUSTOM_OAUTH_URL = "custom_oauth_url"
private const val CUSTOM_OAUTH_SERVICE_NAME = "custom_oauth_service_name"
private const val CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR = "custom_oauth_service_name_text_color"
......@@ -69,6 +72,9 @@ fun newInstance(
wordpressOauthUrl: String? = null,
casLoginUrl: String? = null,
casToken: String? = null,
casServiceName: String? = null,
casServiceNameTextColor: Int = 0,
casServiceButtonColor: Int = 0,
customOauthUrl: String? = null,
customOauthServiceName: String? = null,
customOauthServiceNameTextColor: Int = 0,
......@@ -95,6 +101,9 @@ fun newInstance(
putString(WORDPRESS_OAUTH_URL, wordpressOauthUrl)
putString(CAS_LOGIN_URL, casLoginUrl)
putString(CAS_TOKEN, casToken)
putString(CAS_SERVICE_NAME, casServiceName)
putInt(CAS_SERVICE_NAME_TEXT_COLOR, casServiceNameTextColor)
putInt(CAS_SERVICE_BUTTON_COLOR, casServiceButtonColor)
putString(CUSTOM_OAUTH_URL, customOauthUrl)
putString(CUSTOM_OAUTH_SERVICE_NAME, customOauthServiceName)
putInt(CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR, customOauthServiceNameTextColor)
......@@ -127,6 +136,9 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
private var wordpressOauthUrl: String? = null
private var casLoginUrl: String? = null
private var casToken: String? = null
private var casServiceName: String? = null
private var casServiceNameTextColor: Int = 0
private var casServiceButtonColor: Int = 0
private var customOauthUrl: String? = null
private var customOauthServiceName: String? = null
private var customOauthServiceTextColor: Int = 0
......@@ -157,6 +169,9 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
wordpressOauthUrl = bundle.getString(WORDPRESS_OAUTH_URL)
casLoginUrl = bundle.getString(CAS_LOGIN_URL)
casToken = bundle.getString(CAS_TOKEN)
casServiceName = bundle.getString(CAS_SERVICE_NAME)
casServiceNameTextColor = bundle.getInt(CAS_SERVICE_NAME_TEXT_COLOR)
casServiceButtonColor = bundle.getInt(CAS_SERVICE_BUTTON_COLOR)
customOauthUrl = bundle.getString(CUSTOM_OAUTH_URL)
customOauthServiceName = bundle.getString(CUSTOM_OAUTH_SERVICE_NAME)
customOauthServiceTextColor = bundle.getInt(CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR)
......@@ -200,6 +215,7 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
setupCas()
setupCustomOauth()
setupSaml()
setupAccountsView()
setupLoginWithEmailView()
setupCreateNewAccountView()
}
......@@ -235,19 +251,17 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
setupWordpressButtonListener(wordpressOauthUrl.toString(), state.toString())
enableLoginByWordpress()
}
if (totalSocialAccountsEnabled > 0) {
showAccountsView()
if (totalSocialAccountsEnabled > 3) {
setupExpandAccountsView()
}
}
}
private fun setupCas() {
if (casLoginUrl != null && casToken != null) {
setupCasButtonListener(casLoginUrl.toString(), casToken.toString())
enableLoginByCas()
if (casLoginUrl != null && casToken != null && casServiceName != null) {
addCasButton(
casLoginUrl.toString(),
casToken.toString(),
casServiceName.toString(),
casServiceNameTextColor,
casServiceButtonColor
)
}
}
......@@ -275,6 +289,15 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
}
}
private fun setupAccountsView() {
if (totalSocialAccountsEnabled > 0) {
showAccountsView()
if (totalSocialAccountsEnabled > 3) {
setupExpandAccountsView()
}
}
}
private fun setupLoginWithEmailView() {
if (isLoginFormEnabled) {
showLoginWithEmailButton()
......@@ -319,10 +342,17 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
setupButtonListener(button_wordpress, wordpressUrl, state, REQUEST_CODE_FOR_OAUTH)
// CAS service account.
override fun enableLoginByCas() = enableAccountButton(button_cas)
override fun setupCasButtonListener(casUrl: String, casToken: String) =
setupButtonListener(button_cas, casUrl, casToken, REQUEST_CODE_FOR_CAS)
override fun addCasButton(
caslUrl: String,
casToken: String,
serviceName: String,
serviceNameColor: Int,
buttonColor: Int
) {
val button = getCustomServiceButton(serviceName, serviceNameColor, buttonColor)
setupButtonListener(button, caslUrl, casToken, REQUEST_CODE_FOR_CAS)
accounts_container.addView(button)
}
// Custom OAuth account.
override fun addCustomOauthButton(
......
......@@ -43,6 +43,9 @@ class OnBoardingPresenter @Inject constructor(
wordpressOauthUrl,
casLoginUrl,
casToken,
casServiceName,
casServiceNameTextColor,
casServiceButtonColor,
customOauthUrl,
customOauthServiceName,
customOauthServiceNameTextColor,
......
......@@ -30,6 +30,9 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
wordpressOauthUrl: String? = null,
casLoginUrl: String? = null,
casToken: String? = null,
casServiceName: String? = null,
casServiceNameTextColor: Int = 0,
casServiceButtonColor: Int = 0,
customOauthUrl: String? = null,
customOauthServiceName: String? = null,
customOauthServiceNameTextColor: Int = 0,
......@@ -59,6 +62,9 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
wordpressOauthUrl,
casLoginUrl,
casToken,
casServiceName,
casServiceNameTextColor,
casServiceButtonColor,
customOauthUrl,
customOauthServiceName,
customOauthServiceNameTextColor,
......
......@@ -53,6 +53,9 @@ class ServerPresenter @Inject constructor(
wordpressOauthUrl,
casLoginUrl,
casToken,
casServiceName,
casServiceNameTextColor,
casServiceButtonColor,
customOauthUrl,
customOauthServiceName,
customOauthServiceNameTextColor,
......
......@@ -13,6 +13,7 @@ import android.text.style.ReplacementSpan
import android.view.View
import androidx.core.content.res.ResourcesCompat
import androidx.core.util.PatternsCompat
import chat.rocket.android.R
import chat.rocket.android.chatroom.ui.StrikethroughDelimiterProcessor
import chat.rocket.android.emoji.EmojiParser
import chat.rocket.android.emoji.EmojiRepository
......
......@@ -61,6 +61,9 @@ abstract class CheckServerPresenter constructor(
internal var wordpressOauthUrl: String? = null
internal var casLoginUrl: String? = null
internal var casToken: String? = null
internal var casServiceName: String? = null
internal var casServiceNameTextColor: Int = 0
internal var casServiceButtonColor: Int = 0
internal var customOauthUrl: String? = null
internal var customOauthServiceName: String? = null
internal var customOauthServiceNameTextColor: Int = 0
......@@ -125,7 +128,7 @@ abstract class CheckServerPresenter constructor(
if (services.isNotEmpty()) {
state = OauthHelper.getState()
checkEnabledOauthAccounts(services, serverUrl)
checkEnabledCasAccounts(serverUrl)
checkEnabledCasAccounts(services, serverUrl)
checkEnabledCustomOauthAccounts(services, serverUrl)
checkEnabledSamlAccounts(services, serverUrl)
}
......@@ -227,11 +230,25 @@ abstract class CheckServerPresenter constructor(
}
}
private fun checkEnabledCasAccounts(serverUrl: String) {
private fun checkEnabledCasAccounts(services: List<Map<String,Any>>, serverUrl: String) {
if (settings.isCasAuthenticationEnabled()) {
casToken = generateRandomString(17)
casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString())
totalSocialAccountsEnabled++
getCasServices(services).let {
for (serviceMap in it) {
casServiceName = getServiceName(serviceMap)
val serviceNameTextColor = getServiceNameColor(serviceMap)
val serviceButtonColor = getServiceButtonColor(serviceMap)
if (casServiceName != null &&
serviceNameTextColor != null &&
serviceButtonColor != null
) {
casServiceNameTextColor = serviceNameTextColor
casServiceButtonColor = serviceButtonColor
totalSocialAccountsEnabled++
}
}
}
}
}
......@@ -244,7 +261,7 @@ abstract class CheckServerPresenter constructor(
val clientId = getOauthClientId(serviceMap)
val scope = getCustomOauthScope(serviceMap)
val serviceNameTextColor =
getServiceNameColorForCustomOauthOrSaml(serviceMap)
getServiceNameColor(serviceMap)
val serviceButtonColor = getServiceButtonColor(serviceMap)
if (customOauthServiceName != null &&
host != null &&
......@@ -276,9 +293,9 @@ abstract class CheckServerPresenter constructor(
samlToken = generateRandomString(17)
for (serviceMap in it) {
val provider = getSamlProvider(serviceMap)
samlServiceName = getSamlServiceName(serviceMap)
samlServiceName = getServiceName(serviceMap)
val serviceNameTextColor =
getServiceNameColorForCustomOauthOrSaml(serviceMap)
getServiceNameColor(serviceMap)
val serviceButtonColor = getServiceButtonColor(serviceMap)
if (provider != null &&
......@@ -369,6 +386,14 @@ abstract class CheckServerPresenter constructor(
private fun getCustomOauthServiceName(serviceMap: Map<String, Any>): String? =
serviceMap["service"] as? String
/**
* Returns a CAS service list.
*
* @return A CAS service list, otherwise an empty list if there is no CAS service.
*/
private fun getCasServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> =
listMap.filter { map -> map["service"] == "cas" }
/**
* Returns a SAML OAuth service list.
*
......@@ -388,26 +413,27 @@ abstract class CheckServerPresenter constructor(
/**
* Returns the text of the SAML service.
* REMARK: This can be used SAML or CAS.
*
* @param serviceMap The service map to get the text of the SAML service.
* @return The text of the SAML service, otherwise null.
*/
private fun getSamlServiceName(serviceMap: Map<String, Any>): String? =
private fun getServiceName(serviceMap: Map<String, Any>): String? =
serviceMap["buttonLabelText"] as? String
/**
* Returns the text color of the service name.
* REMARK: This can be used for custom OAuth or SAML.
* REMARK: This can be used for custom OAuth, SAML or CAS.
*
* @param serviceMap The service map to get the text color from.
* @return The text color of the service (custom OAuth or SAML), otherwise null.
*/
private fun getServiceNameColorForCustomOauthOrSaml(serviceMap: Map<String, Any>): Int? =
private fun getServiceNameColor(serviceMap: Map<String, Any>): Int? =
(serviceMap["buttonLabelColor"] as? String)?.parseColor()
/**
* Returns the button color of the service name.
* REMARK: This can be used for custom OAuth or SAML.
* REMARK: This can be used for custom OAuth, SAML or CAS.
*
* @param serviceMap The service map to get the button color from.
* @return The button color of the service (custom OAuth or SAML), otherwise null.
......
......@@ -133,15 +133,6 @@
android:textSize="16sp"
android:visibility="gone"
tools:visibility="visible" />
<Button
android:id="@+id/button_cas"
style="@style/Authentication.Button"
android:layout_marginTop="10dp"
android:clickable="false"
android:text="@string/action_login_or_sign_up"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
......
......@@ -24,7 +24,6 @@
<!-- Actions -->
<string name="action_connect">Verbinde</string>
<string name="action_use_this_username">Benutze den Benutzernamen</string>
<string name="action_login_or_sign_up">Klick diesen Knopf um sich anzumelden oder einen Account zu erstellen</string>
<string name="action_terms_of_service">Nutzungsbedingungen</string>
<string name="action_privacy_policy">Datenschutz</string>
<string name="action_search">Suche</string>
......
......@@ -23,7 +23,6 @@
<!-- Actions -->
<string name="action_connect">Conectar</string>
<string name="action_use_this_username">Usa este nombre de usuario</string>
<string name="action_login_or_sign_up">Toca en este botón para iniciar sesión o crear una cuenta</string>
<string name="action_terms_of_service">Términos de Servicio</string>
<string name="action_privacy_policy">Política de Privacidad</string>
<string name="action_search">Buscar</string>
......
......@@ -25,7 +25,6 @@
<!-- Actions -->
<string name="action_connect">Se connecter</string>
<string name="action_use_this_username">Utilisez ce nom d\'utilisateur</string>
<string name="action_login_or_sign_up">Touchez ce bouton pour vous connecter ou créer un compte</string>
<string name="action_terms_of_service">Conditions d\'utilisation</string>
<string name="action_privacy_policy">Politique de confidentialité</string>
<string name="action_search">Chercher</string>
......
......@@ -24,7 +24,6 @@
<!-- Actions -->
<string name="action_connect">जुडिये</string>
<string name="action_use_this_username">इस उपयोगकर्ता नाम का उपयोग करें</string>
<string name="action_login_or_sign_up">लॉग इन करने या खाता बनाने के लिए इस बटन को टैप करें</string>
<string name="action_terms_of_service">सेवा की शर्तें</string>
<string name="action_privacy_policy">गोपनीयता नीति</string>
<string name="action_search">खोजें</string>
......
......@@ -26,7 +26,6 @@
<!-- Actions -->
<string name="action_connect">接続</string>
<string name="action_use_this_username">このユーザー名を使用する</string>
<string name="action_login_or_sign_up">ログインまたはアカウントを作成するにはこのボタンを押してください</string>
<string name="action_terms_of_service">サービス利用規約</string>
<string name="action_privacy_policy">プライバシーポリシー</string>
<string name="action_search">検索</string>
......
......@@ -24,7 +24,6 @@
<!-- Actions -->
<string name="action_connect">Conectar</string>
<string name="action_use_this_username">Usar este nome de usuário</string>
<string name="action_login_or_sign_up">Toque neste botão para fazer login ou criar uma conta</string>
<string name="action_terms_of_service">Termos de Serviço</string>
<string name="action_privacy_policy">Política de Privacidade</string>
<string name="action_search">Pesquisar</string>
......
......@@ -24,7 +24,6 @@
<!-- Actions -->
<string name="action_connect">Подключиться</string>
<string name="action_use_this_username">Использовать это имя</string>
<string name="action_login_or_sign_up">Нажмите эту кнопку, чтобы войти в систему или создать учетную запись</string>
<string name="action_terms_of_service">Условия использования</string>
<string name="action_privacy_policy">Политика конфиденциальности</string>
<string name="action_search">Поиск</string>
......
......@@ -24,7 +24,6 @@
<!-- Actions -->
<string name="action_connect">Bağlan</string>
<string name="action_use_this_username">Bu kullanıcı adını kullan</string>
<string name="action_login_or_sign_up">Giriş yapmak veya yeni hesap oluşturmak için buraya tıklayın.</string>
<string name="action_terms_of_service">Kullanım Şartları</string>
<string name="action_privacy_policy">Gizlilik Sözleşmesi</string>
<string name="action_search">Ara</string>
......
......@@ -24,7 +24,6 @@
<!-- Actions -->
<string name="action_connect">Підключитися</string>
<string name="action_use_this_username">Використати це ім\'я</string>
<string name="action_login_or_sign_up">Натисніть цю кнопку, щоб увійти до системи або створити аккаунт</string>
<string name="action_terms_of_service">Умови використання</string>
<string name="action_privacy_policy">Політика конфіденційності</string>
<string name="action_search">Пошук</string>
......
......@@ -36,7 +36,6 @@ https://github.com/RocketChat/java-code-styles/blob/master/CODING_STYLE.md#strin
<!-- Actions -->
<string name="action_connect">Connect</string>
<string name="action_use_this_username">Use this username</string>
<string name="action_login_or_sign_up">Tap this button to log in or create an account</string>
<string name="action_terms_of_service">Terms of Service</string>
<string name="action_privacy_policy">Privacy Policy</string>
<string name="action_search">Search</string>
......
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