[update] Hide private key after user input

This commit is contained in:
acite
2025-08-25 15:21:54 +08:00
parent c2d348ddfb
commit c4d5a5cb95
4 changed files with 37 additions and 12 deletions

View File

@@ -23,7 +23,7 @@ _🚀This is the client of the multimedia server Abyss, which can also be extend
### High Priority
- [x] Fix tablet full-screen mode bug
- [ ] Hide private key after user input
- [x] Hide private key after user input
- [ ] Replace Android robot icon with custom design
- [ ] Configure server baseURL in client settings
- [ ] Implement proper access control for directory queries

View File

@@ -94,8 +94,7 @@ fun MeScreen(meScreenViewModel: MeScreenViewModel = viewModel())
// Save Button
Button(
onClick = {
meScreenViewModel.updateAccount(username, privateKey);
Toast.makeText(context, "Account updated", Toast.LENGTH_SHORT).show()
meScreenViewModel.updateAccount(username, privateKey, context)
},
modifier = Modifier.fillMaxWidth()
) {

View File

@@ -70,11 +70,11 @@ class HomeScreenViewModel(application: Application) : AndroidViewModel(applicati
u,
p
)!!
Global.loggedIn = true
}catch(e: Exception)
{
print(e.message)
}finally {
Global.loggedIn = true
}
}
}

View File

@@ -1,6 +1,7 @@
package com.acitelight.aether.viewModel
import android.app.Application
import android.content.Context
import android.widget.Toast
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.LocalContext
@@ -8,16 +9,19 @@ import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.acitelight.aether.Global
import com.acitelight.aether.dataStore
import com.acitelight.aether.model.Video
import com.acitelight.aether.service.ApiClient
import com.acitelight.aether.service.AuthManager
import com.acitelight.aether.service.MediaManager
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
class MeScreenViewModel(application: Application) : AndroidViewModel(application)
{
class MeScreenViewModel(application: Application) : AndroidViewModel(application) {
private val dataStore = application.dataStore
private val USER_NAME_KEY = stringPreferencesKey("user_name")
private val PRIVATE_KEY = stringPreferencesKey("private_key")
@@ -36,17 +40,39 @@ class MeScreenViewModel(application: Application) : AndroidViewModel(application
init {
viewModelScope.launch {
username.value = userNameFlow.first()
privateKey.value = privateKeyFlow.first()
privateKey.value = if (privateKeyFlow.first() == "") "" else "******"
}
}
fun updateAccount(u: String, p: String)
{
fun updateAccount(u: String, p: String, context: Context) {
viewModelScope.launch {
dataStore.edit { preferences ->
preferences[USER_NAME_KEY] = u
preferences[PRIVATE_KEY] = p
}
privateKey.value = "******"
Global.loggedIn = false
val u = userNameFlow.first()
val p = privateKeyFlow.first()
if (u == "" || p == "") return@launch
try {
MediaManager.token = AuthManager.fetchToken(
ApiClient.base,
u,
p
)!!
Global.loggedIn = true
Toast.makeText(context, "Account Updated", Toast.LENGTH_SHORT).show()
} catch (e: Exception) {
print(e.message)
Toast.makeText(context, "Invalid Account Information", Toast.LENGTH_SHORT).show()
}
}
}
}