From c4d5a5cb9572d181093011a864f171c175549c3f Mon Sep 17 00:00:00 2001 From: acite <1498045907@qq.com> Date: Mon, 25 Aug 2025 15:21:54 +0800 Subject: [PATCH] [update] Hide private key after user input --- README.md | 2 +- .../com/acitelight/aether/view/MeScreen.kt | 3 +- .../aether/viewModel/HomeScreenViewModel.kt | 4 +- .../aether/viewModel/MeScreenViewModel.kt | 40 +++++++++++++++---- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b7308d6..8e1b474 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/src/main/java/com/acitelight/aether/view/MeScreen.kt b/app/src/main/java/com/acitelight/aether/view/MeScreen.kt index 7f098d5..bf48041 100644 --- a/app/src/main/java/com/acitelight/aether/view/MeScreen.kt +++ b/app/src/main/java/com/acitelight/aether/view/MeScreen.kt @@ -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() ) { diff --git a/app/src/main/java/com/acitelight/aether/viewModel/HomeScreenViewModel.kt b/app/src/main/java/com/acitelight/aether/viewModel/HomeScreenViewModel.kt index 38b6cf9..9290612 100644 --- a/app/src/main/java/com/acitelight/aether/viewModel/HomeScreenViewModel.kt +++ b/app/src/main/java/com/acitelight/aether/viewModel/HomeScreenViewModel.kt @@ -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 } } } diff --git a/app/src/main/java/com/acitelight/aether/viewModel/MeScreenViewModel.kt b/app/src/main/java/com/acitelight/aether/viewModel/MeScreenViewModel.kt index b2952f4..77fa15f 100644 --- a/app/src/main/java/com/acitelight/aether/viewModel/MeScreenViewModel.kt +++ b/app/src/main/java/com/acitelight/aether/viewModel/MeScreenViewModel.kt @@ -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,25 +9,28 @@ 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") + private val PRIVATE_KEY = stringPreferencesKey("private_key") val userNameFlow: Flow = dataStore.data.map { preferences -> preferences[USER_NAME_KEY] ?: "" } - val privateKeyFlow: Flow = dataStore.data.map { preferences -> + val privateKeyFlow: Flow = dataStore.data.map { preferences -> preferences[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() + } } } } \ No newline at end of file