Login: change the welcome message based if first login or not.

This shared login screen was a shortcut we took a while back, but it's
now time to fix it and make it clear what's going on, just like in the
other apps.
pull/108/head
Tom Hacohen 4 years ago
parent df94fde5ff
commit ccc17ba141

@ -12,6 +12,7 @@ import com.etesync.syncadapter.HttpClient
import com.etesync.journalmanager.Crypto
import com.etesync.journalmanager.Exceptions
import com.etesync.journalmanager.JournalAuthenticator
import com.etesync.journalmanager.UserInfoManager
import com.etesync.syncadapter.log.Logger
import com.etesync.syncadapter.model.CollectionInfo
import okhttp3.HttpUrl
@ -37,8 +38,13 @@ class BaseConfigurationFinder(protected val context: Context, protected val cred
val authenticator = JournalAuthenticator(httpClient, HttpUrl.get(credentials.uri!!)!!)
var authtoken: String? = null
var userInfo: UserInfoManager.UserInfo? = null
try {
authtoken = authenticator.getAuthToken(credentials.userName, credentials.password)
val authenticatedHttpClient = HttpClient.Builder(context, credentials.uri.host, authtoken!!).build().okHttpClient
val userInfoManager = UserInfoManager(authenticatedHttpClient, HttpUrl.get(credentials.uri)!!)
userInfo = userInfoManager.fetch(credentials.userName)
} catch (e: Exceptions.HttpException) {
Logger.log.warning(e.message)
exception = e
@ -51,6 +57,7 @@ class BaseConfigurationFinder(protected val context: Context, protected val cred
credentials.uri,
credentials.userName, authtoken,
cardDavConfig, calDavConfig,
userInfo,
exception
)
}
@ -68,7 +75,7 @@ class BaseConfigurationFinder(protected val context: Context, protected val cred
class Configuration
// We have to use URI here because HttpUrl is not serializable!
(val url: URI, val userName: String, val authtoken: String?, val cardDAV: ServiceInfo, val calDAV: ServiceInfo, var error: Throwable?) : Serializable {
(val url: URI, val userName: String, val authtoken: String?, val cardDAV: ServiceInfo, val calDAV: ServiceInfo, var userInfo: UserInfoManager.UserInfo?, var error: Throwable?) : Serializable {
var rawPassword: String? = null
var password: String? = null
var keyPair: Crypto.AsymmetricKeyPair? = null

@ -31,8 +31,16 @@ class EncryptionDetailsFragment : Fragment() {
val config = arguments!!.getSerializable(KEY_CONFIG) as BaseConfigurationFinder.Configuration
val accountName = v.findViewById<View>(R.id.account_name) as TextView
accountName.text = getString(R.string.login_encryption_account_label) + " " + config.userName
val encryptionFormInfo = v.findViewById<View>(R.id.encryption_form_info) as TextView
if (config.userInfo == null) {
encryptionFormInfo.text = getString(R.string.login_encryption_set_new_password)
val extra_details = v.findViewById<TextView>(R.id.encryption_extra_info)
extra_details.visibility = View.VISIBLE
extra_details.text = getString(R.string.login_encryption_extra_info, Constants.faqUri.buildUpon().appendEncodedPath("#securing-etesync").build().toString())
} else {
encryptionFormInfo.text = getString(R.string.login_encryption_enter_password, config.userName)
}
editPassword = v.findViewById<View>(R.id.encryption_password) as TextInputLayout
@ -45,9 +53,6 @@ class EncryptionDetailsFragment : Fragment() {
SetupEncryptionFragment.newInstance(config).show(fragmentManager!!, null)
})
val extra_details = v.findViewById<View>(R.id.encryption_extra_info) as TextView
extra_details.text = getString(R.string.login_encryption_extra_info, Constants.faqUri.buildUpon().appendEncodedPath("#securing-etesync").build().toString())
return v
}

@ -97,8 +97,7 @@ class SetupEncryptionFragment : DialogFragment() {
val cryptoManager: Crypto.CryptoManager
val httpClient = HttpClient.Builder(context, config.url.host, config.authtoken!!).build().okHttpClient
val userInfoManager = UserInfoManager(httpClient, HttpUrl.get(config.url)!!)
val userInfo = userInfoManager.fetch(config.userName)
val userInfo = config.userInfo
if (userInfo != null) {
Logger.log.info("Fetched userInfo for " + config.userName)
cryptoManager = Crypto.CryptoManager(userInfo.version!!.toInt(), config.password!!, "userInfo")

@ -32,7 +32,7 @@
android:layout_marginBottom="14dp"/>
<TextView
android:id="@+id/account_name"
android:id="@+id/encryption_form_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
@ -49,16 +49,12 @@
android:hint="@string/login_encryption_password"/>
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/login_encryption_check_password"/>
<TextView
android:id="@+id/encryption_extra_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:visibility="gone"
android:text="@string/login_encryption_extra_info"/>
</LinearLayout>
</ScrollView>

@ -201,8 +201,10 @@
<string name="login_custom_server_error">Invalid URL found, did you forget to include https://?</string>
<string name="login_toggle_advanced">Show advanced settings</string>
<string name="login_encryption_password">Encryption Password</string>
<string name="login_encryption_set_new_password">Please set your encryption password below, and make sure you got it right, as it *can\'t* be recovered if lost!</string>
<string name="login_encryption_enter_password">You are logged in as \"%s\". Please enter your encryption password to continue, or log out from the side menu.</string>
<string name="login_encryption_check_password">* Please double-check the password, as it can\'t be recovered if wrong!</string>
<string name="login_encryption_extra_info">This password is used to encrypt your data, unlike the previous one, which is used to log into the service.\nYou are asked to choose a separate encryption password for security reasons. For more information, please refer to the FAQ at: %s</string>
<string name="login_encryption_extra_info">* This password is used to encrypt your data, unlike the previous one, which is used to log into the service.\nYou are asked to choose a separate encryption password for security reasons. For more information, please refer to the FAQ at: %s</string>
<string name="login_password_required">Password required</string>
<string name="login_login">Log In</string>
<string name="login_signup">Sign Up</string>

Loading…
Cancel
Save