account: new login page, kept away while signed in; profile and avatar

The login page no longer opens when a session is saved: the session is
checked in the background and only an expired one brings the page back.
Continue without an account is remembered (ui.skip_account_prompt) until
the next sign-in.

The page is redesigned: the night artwork with what an account gives
beside the form on wide windows, the form alone on narrow ones; email,
password with a show button, the one-time code when asked, notices as
banners. Settings -> My Account shows the profile instead of a list of
notes.

voelin-myts asks the user service (/user, the route of the official
client) for getAccountData (description, registration, previous sign-in,
badges, devices, avatar file names) and requestAvatarSignedUrl, then
fetches the avatar (HTTPS only, at most 4 MiB). The UI keeps the profile
in the session's keyring bundle and the picture in <data>/account/avatar,
fetches it again only when its name changes, and uses it as the sidebar's
profile picture where a server has none for us.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VZBWxxMsxUzp4PSTKVzbZN
This commit is contained in:
Claude committed 2026-10-04 22:12:07 +00:00
1 parent a44f994236
commit a57dfee83a
13 files changed
+1182 -143

No files matched your search

+36
View File
@@ -3,8 +3,10 @@
//! Requests use the official client's method envelope and password derivation. //! Requests use the official client's method envelope and password derivation.
//! No requests or credentials are logged. //! No requests or credentials are logged.
mod identity; mod identity;
mod profile;
mod transport; mod transport;
pub use identity::IdentityError; pub use identity::IdentityError;
pub use profile::{Badge, Device, Profile};
pub use tsproto::myts::Identity as ServerIdentity; pub use tsproto::myts::Identity as ServerIdentity;
use zeroize::{Zeroize, Zeroizing}; use zeroize::{Zeroize, Zeroizing};
@@ -22,6 +24,9 @@ pub struct Login {
pub renewal: Option<Renewal>, pub renewal: Option<Renewal>,
/// Validated server identity, or why this session cannot associate with servers. /// Validated server identity, or why this session cannot associate with servers.
pub identity: Result<ServerIdentity, IdentityError>, pub identity: Result<ServerIdentity, IdentityError>,
/// What the login response tells about the account (the avatar's file
/// names, the description); [`Client::profile`] tells more.
pub profile: Profile,
} }
/// Server-provided alternative login material, stored only in a secret store. /// Server-provided alternative login material, stored only in a secret store.
@@ -67,6 +72,10 @@ pub enum Error {
CredentialPreparation, CredentialPreparation,
#[error("renewal requires both a renewal token and an auth token")] #[error("renewal requires both a renewal token and an auth token")]
MissingRenewalCredentials, MissingRenewalCredentials,
#[error("account service refused the request (code {0})")]
Refused(i32),
#[error("account service returned no usable avatar link")]
AvatarUrl,
} }
impl Error { impl Error {
pub fn status_code(&self) -> Option<i32> { pub fn status_code(&self) -> Option<i32> {
@@ -83,6 +92,7 @@ impl Error {
/// Only the explicit expired-session status permits an automatic renewal. /// Only the explicit expired-session status permits an automatic renewal.
pub fn is_invalid_session(&self) -> bool { pub fn is_invalid_session(&self) -> bool {
self.status_code() == Some(api::ErrorCommon::ErrorSessionExpired as i32) self.status_code() == Some(api::ErrorCommon::ErrorSessionExpired as i32)
|| matches!(self, Self::Refused(code) if *code == profile::SESSION_EXPIRED)
} }
} }
@@ -180,9 +190,11 @@ impl Client {
}) })
.await .await
.map_err(|_| Error::CredentialPreparation)?; .map_err(|_| Error::CredentialPreparation)?;
let profile = Profile::from_login(&response);
Ok(Login { Ok(Login {
token, token,
identity, identity,
profile,
uuid: response.uuid, uuid: response.uuid,
username: response.username, username: response.username,
renewal: response.alternative_login_info.map(|info| Renewal { renewal: response.alternative_login_info.map(|info| Renewal {
@@ -193,6 +205,30 @@ impl Client {
}) })
} }
/// The signed-in user's account: names, description, dates, badges,
/// devices and avatar file names (`getAccountData` at `/user`).
pub async fn profile(&self, token: &SessionToken) -> Result<Profile, Error> {
transport::check_input_size(&[token.as_str()])?;
let request = profile::request(token);
let bytes = self.transport.call("user", "getAccountData", &wire::encode(&request)).await?;
profile::from_account_data(wire::decode(bytes)?)
}
/// The picture of an avatar file of the signed-in user (one of
/// [`Profile::avatars`]): the service signs a download link
/// (`requestAvatarSignedUrl` at `/user`), which is then fetched.
pub async fn avatar(&self, token: &SessionToken, file_name: &str) -> Result<Vec<u8>, Error> {
transport::check_input_size(&[token.as_str(), file_name])?;
let request = api::user::AvatarSignedUrlRequest {
session: token.as_str().into(),
file_names: vec![file_name.into()],
};
let bytes =
self.transport.call("user", "requestAvatarSignedUrl", &wire::encode(&request)).await?;
let url = profile::signed_url(wire::decode(bytes)?, file_name)?;
self.transport.download(&url, profile::MAX_AVATAR_BYTES).await
}
pub async fn validate_session(&self, token: &SessionToken) -> Result<(), Error> { pub async fn validate_session(&self, token: &SessionToken) -> Result<(), Error> {
let response = self.session_call("session", token).await?; let response = self.session_call("session", token).await?;
Ok(session::validate_session_status(&response)?) Ok(session::validate_session_status(&response)?)
+246
View File
@@ -0,0 +1,246 @@
//! The account's profile: what `getAccountData` and the login response tell
//! about the signed-in user, and the avatar's download link.
use crate::Error;
use schema_api::SessionToken;
use schema_api::api::{self, user};
/// `ERROR_SESSION_EXPIRED` of the `/user` service.
pub(crate) const SESSION_EXPIRED: i32 = user::ErrorReturnCode::ErrorSessionExpired as i32;
/// Avatars are small pictures; anything larger is not one.
pub(crate) const MAX_AVATAR_BYTES: usize = 4 << 20;
/// The signed-in user's account, as the account service has it.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Profile {
pub username: String,
pub email: String,
pub description: String,
/// When the account was registered, Unix seconds (0: not told).
pub registered: i64,
/// The last sign-in before this one, Unix seconds (0: not told).
pub last_login: i64,
pub badges: Vec<Badge>,
/// The avatar's file names, the one for "online" first.
pub avatars: Vec<String>,
/// Devices signed in to the account.
pub devices: Vec<Device>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Badge {
pub name: String,
pub description: String,
/// The badge's picture.
pub url: String,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Device {
pub name: String,
/// Unix seconds (0: not told).
pub last_login: i64,
pub region: String,
}
impl Profile {
/// What a login response carries: the avatar and the description.
pub(crate) fn from_login(response: &api::LoginSession) -> Self {
Self {
username: response.username.clone(),
description: response
.user_data
.as_ref()
.map(|d| d.description.clone())
.unwrap_or_default(),
avatars: avatar_files(response.user_avatar.as_ref().and_then(|a| a.info.as_ref())),
..Default::default()
}
}
}
/// `getAccountData` for what the profile shows.
pub(crate) fn request(token: &SessionToken) -> user::AccountDataRequest {
use user::UserAccountDataSelector as S;
user::AccountDataRequest {
session: token.as_str().into(),
selector: [S::BasicInfo, S::Avatars, S::Description, S::Badges, S::AuthenticatedDevices]
.map(|s| s as i32)
.into(),
..Default::default()
}
}
pub(crate) fn from_account_data(data: user::UserAccountData) -> Result<Profile, Error> {
check(data.return_code.as_ref())?;
Ok(Profile {
username: data.username,
email: data.email_address,
description: data.description,
registered: unix_seconds(data.registration_date),
last_login: unix_seconds(data.last_login),
badges: data
.badges
.into_iter()
.map(|b| Badge { name: b.name, description: b.description, url: b.url })
.collect(),
avatars: avatar_files(data.avatar_info.as_ref()),
devices: data
.authenticated_devices
.into_iter()
.map(|d| Device {
name: d.device_name,
last_login: unix_seconds(d.last_login),
region: d.region,
})
.collect(),
})
}
/// The signed link for `file_name`; only HTTPS (and loopback HTTP in tests).
pub(crate) fn signed_url(
response: user::AvatarSignedUrlResponse,
file_name: &str,
) -> Result<String, Error> {
check(response.return_code.as_ref())?;
let url = response
.signed_urls
.into_iter()
.find(|u| u.file_name == file_name || u.file_name.is_empty())
.map(|u| u.signed_url)
.ok_or(Error::AvatarUrl)?;
let allowed =
url.starts_with("https://") || (cfg!(test) && url.starts_with("http://127.0.0.1:"));
if !allowed || url.len() > 4096 {
return Err(Error::AvatarUrl);
}
Ok(url)
}
/// A refusal: `success` unset with an error code. (A reply without a return
/// code is taken as it is: the service sets one when it refuses.)
fn check(code: Option<&user::ReturnCode>) -> Result<(), Error> {
match code {
Some(code) if !code.success && code.error_code != 0 => Err(Error::Refused(code.error_code)),
_ => Ok(()),
}
}
/// The avatar's file names, the "online" picture first, without duplicates.
fn avatar_files(info: Option<&api::AvatarInfo>) -> Vec<String> {
let mut maps: Vec<_> = info.map(|i| i.map.iter().collect()).unwrap_or_default();
maps.sort_by_key(|m| m.state != api::AvatarState::Online as i32);
let mut names: Vec<String> = Vec::new();
for map in maps {
if !map.name.is_empty() && !names.contains(&map.name) {
names.push(map.name.clone());
}
}
names
}
/// Dates come in seconds or milliseconds; seconds either way.
fn unix_seconds(value: i64) -> i64 {
if value > 100_000_000_000 { value / 1000 } else { value.max(0) }
}
#[cfg(test)]
mod tests {
use super::*;
fn map(state: api::AvatarState, name: &str) -> api::avatar_info::AvatarMap {
api::avatar_info::AvatarMap { state: state as i32, name: name.into() }
}
#[test]
fn account_data_becomes_a_profile() {
let data = user::UserAccountData {
return_code: Some(user::ReturnCode { success: true, ..Default::default() }),
username: "Alex".into(),
email_address: "alex@example.test".into(),
description: "Hi".into(),
registration_date: 1_700_000_000_000,
last_login: 1_750_000_000,
avatar_info: Some(api::AvatarInfo {
map: vec![
map(api::AvatarState::Away, "away.png"),
map(api::AvatarState::Online, "online.png"),
map(api::AvatarState::Dnd, "online.png"),
map(api::AvatarState::Offline, ""),
],
}),
badges: vec![user::UserBadge {
name: "Early".into(),
description: "Was there".into(),
url: "https://badges.example.test/early.svg".into(),
..Default::default()
}],
authenticated_devices: vec![user::AuthenticatedDevice {
device_name: "Voelin".into(),
last_login: 1_760_000_000_000,
region: "EU".into(),
..Default::default()
}],
..Default::default()
};
let profile = from_account_data(data).unwrap();
assert_eq!(profile.username, "Alex");
assert_eq!(profile.email, "alex@example.test");
assert_eq!(profile.registered, 1_700_000_000);
assert_eq!(profile.last_login, 1_750_000_000);
assert_eq!(profile.avatars, ["online.png", "away.png"]);
assert_eq!(profile.badges[0].name, "Early");
assert_eq!(profile.devices[0].last_login, 1_760_000_000);
}
#[test]
fn refusals_and_bad_links_are_errors() {
let refused = user::UserAccountData {
return_code: Some(user::ReturnCode {
error_code: SESSION_EXPIRED,
..Default::default()
}),
..Default::default()
};
let error = from_account_data(refused).unwrap_err();
assert!(error.is_invalid_session());
let response = |url: &str| user::AvatarSignedUrlResponse {
return_code: Some(user::ReturnCode { success: true, ..Default::default() }),
signed_urls: vec![user::avatar_signed_url_response::SignedUrl {
file_name: "a.png".into(),
signed_url: url.into(),
}],
};
assert_eq!(
signed_url(response("https://cdn.example.test/a.png?sig=1"), "a.png").unwrap(),
"https://cdn.example.test/a.png?sig=1"
);
assert!(matches!(
signed_url(response("http://cdn.example.test/a"), "a.png"),
Err(Error::AvatarUrl)
));
assert!(matches!(
signed_url(response("file:///etc/passwd"), "a.png"),
Err(Error::AvatarUrl)
));
assert!(matches!(signed_url(response("https://x"), "b.png"), Err(Error::AvatarUrl)));
}
#[test]
fn the_login_response_carries_avatar_and_description() {
let response = api::LoginSession {
username: "Alex".into(),
user_avatar: Some(api::AvatarData {
info: Some(api::AvatarInfo { map: vec![map(api::AvatarState::Online, "o.png")] }),
..Default::default()
}),
user_data: Some(api::UserData { description: "Hi".into() }),
..Default::default()
};
let profile = Profile::from_login(&response);
assert_eq!(
(profile.avatars, profile.description.as_str()),
(vec!["o.png".to_owned()], "Hi")
);
}
}
+24
View File
@@ -49,6 +49,30 @@ impl Transport {
} }
} }
/// GET a file from a link the service handed out (a signed avatar link),
/// at most `max` bytes.
pub(crate) async fn download(&self, url: &str, max: usize) -> Result<Vec<u8>, Error> {
tokio::time::timeout(self.timeout, async {
let mut response = self.client.get(url).send().await?;
if !response.status().is_success() {
return Err(Error::Http(response.status().as_u16()));
}
if response.content_length().is_some_and(|length| length > max as u64) {
return Err(Error::ResponseTooLarge);
}
let mut bytes = Vec::new();
while let Some(chunk) = response.chunk().await? {
if chunk.len() > max - bytes.len() {
return Err(Error::ResponseTooLarge);
}
bytes.extend_from_slice(&chunk);
}
Ok(bytes)
})
.await
.map_err(|_| Error::Timeout)?
}
pub(crate) async fn call( pub(crate) async fn call(
&self, &self,
service: &str, service: &str,
+1 -1
View File
@@ -662,7 +662,7 @@ pub fn run(options: RunOptions) -> Result<()> {
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
runtime: runtime.clone(), runtime: runtime.clone(),
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
myts: Default::default(), myts: crate::myts::Account::new(dir.join("account")),
ui: ui.as_weak(), ui: ui.as_weak(),
store, store,
// The sample data of VOELIN_DEMO_UI never reaches the system keyring. // The sample data of VOELIN_DEMO_UI never reaches the system keyring.
+12
View File
@@ -184,6 +184,18 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
account.uuid = "00000000-0000-0000-0000-000000000001".into(); account.uuid = "00000000-0000-0000-0000-000000000001".into();
account.myts_id = "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB".into(); account.myts_id = "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB".into();
account.identity_status = 1; account.identity_status = 1;
account.initials = "AE".into();
account.description = "Usually in the Raid channel after 8.".into();
account.member_since = "2019-03-14".into();
account.last_login = "2026-10-03".into();
let strings = |items: &[&str]| {
slint::ModelRc::new(slint::VecModel::from(
items.iter().map(|s| slint::SharedString::from(*s)).collect::<Vec<_>>(),
))
};
account.badges = strings(&["TeamSpeak 6 Beta", "Early supporter"]);
account.devices =
strings(&["Voelin · EU · 2026-10-03", "TeamSpeak · EU · 2026-09-28"]);
nav.invoke_open_settings(SettingsSection::Account); nav.invoke_open_settings(SettingsSection::Account);
} }
account.otp_required = arg == "otp"; account.otp_required = arg == "otp";
+5
View File
@@ -176,6 +176,11 @@ pub fn picture(key: &str, bytes: &[u8]) -> Image {
CACHE.with(|c| c.borrow_mut().get_or_load(&cache_key, || decode(bytes))).unwrap_or_default() CACHE.with(|c| c.borrow_mut().get_or_load(&cache_key, || decode(bytes))).unwrap_or_default()
} }
/// Forget the decoded picture kept by `key` (a changed account avatar).
pub fn forget_picture(key: &str) {
CACHE.with(|c| c.borrow_mut().remove(&format!("picture:{key}")));
}
/// A Twemoji by key; an empty image if there is none. /// A Twemoji by key; an empty image if there is none.
pub fn emoji(key: &str) -> Image { pub fn emoji(key: &str) -> Image {
if key.is_empty() { if key.is_empty() {
+289 -4
View File
@@ -1,8 +1,9 @@
//! Desktop account state. Only the UI thread mutates state or persists credentials. //! Desktop account state. Only the UI thread mutates state or persists credentials.
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use slint::ComponentHandle; use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use voelin_myts::{Client, Login, ServerIdentity, SessionToken}; use voelin_myts::{Client, Login, Profile, ServerIdentity, SessionToken};
use voelin_store::Secrets; use voelin_store::Secrets;
use crate::app::{App, Bridge, MytsForm, later}; use crate::app::{App, Bridge, MytsForm, later};
@@ -25,13 +26,81 @@ struct Saved {
// Private account identity belongs in the same secret-store transaction. // Private account identity belongs in the same secret-store transaction.
#[serde(default)] #[serde(default)]
identity: Option<ServerIdentity>, identity: Option<ServerIdentity>,
/// What the account service tells about the account, shown at once on
/// the next start.
#[serde(default)]
profile: SavedProfile,
}
/// The profile of [`voelin_myts::Profile`] worth keeping between runs.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
struct SavedProfile {
description: String,
/// Unix seconds; 0: not known.
registered: i64,
last_login: i64,
badges: Vec<String>,
/// "Name · region · date" per signed-in device.
devices: Vec<String>,
/// The avatar file shown, as the service names it; the picture is
/// [`AVATAR_FILE`] in the account directory.
avatar: String,
}
/// The account's avatar picture, in the account directory.
const AVATAR_FILE: &str = "avatar";
/// A date (Unix seconds) as the profile shows it; empty when not known.
fn date(seconds: i64) -> String {
chrono::DateTime::from_timestamp(seconds, 0)
.filter(|_| seconds > 0)
.map(|d| d.with_timezone(&chrono::Local).format("%Y-%m-%d").to_string())
.unwrap_or_default()
}
impl SavedProfile {
/// Take what the service told; empty fields keep what was known.
fn update(&mut self, profile: &Profile) {
if !profile.description.is_empty() {
self.description = profile.description.clone();
}
if profile.registered > 0 {
self.registered = profile.registered;
}
if profile.last_login > 0 {
self.last_login = profile.last_login;
}
if !profile.badges.is_empty() {
self.badges = profile.badges.iter().map(|b| b.name.clone()).collect();
}
if !profile.devices.is_empty() {
self.devices = profile
.devices
.iter()
.map(|d| {
[d.name.as_str(), d.region.as_str(), &date(d.last_login)]
.into_iter()
.filter(|part| !part.is_empty())
.collect::<Vec<_>>()
.join(" · ")
})
.collect();
}
}
} }
#[derive(Default)] #[derive(Default)]
pub(crate) struct Account { pub(crate) struct Account {
/// Where the avatar picture is kept (`<data>/account`); none in tests.
dir: Option<PathBuf>,
/// The avatar, decoded.
avatar: slint::Image,
saved: Option<Saved>, saved: Option<Saved>,
signed_in: bool, signed_in: bool,
busy: bool, busy: bool,
/// The saved session is being checked (not a password sign-in).
checking: bool,
otp_required: bool, otp_required: bool,
status: i32, status: i32,
persistence_status: i32, persistence_status: i32,
@@ -44,10 +113,56 @@ pub(crate) struct Account {
} }
impl Account { impl Account {
pub(crate) fn new(dir: PathBuf) -> Self {
Self { dir: Some(dir), ..Default::default() }
}
fn avatar_path(&self) -> Option<PathBuf> {
self.dir.as_ref().map(|dir| dir.join(AVATAR_FILE))
}
/// The kept picture, shown while the session is checked.
fn load_avatar(&mut self) {
let bytes = self.avatar_path().and_then(|path| std::fs::read(path).ok());
self.avatar = bytes.map(|b| crate::images::picture("myts-avatar", &b)).unwrap_or_default();
}
/// A new picture from the service: kept on disk and shown.
fn set_avatar(&mut self, name: String, bytes: &[u8]) {
crate::images::forget_picture("myts-avatar");
self.avatar = crate::images::picture("myts-avatar", bytes);
if self.avatar.size().width == 0 {
return;
}
if let Some(path) = self.avatar_path() {
let written = path
.parent()
.map_or(Ok(()), std::fs::create_dir_all)
.and_then(|()| std::fs::write(&path, bytes));
if let Err(error) = written {
tracing::warn!(%error, "could not keep the account's avatar");
}
}
if let Some(saved) = self.saved.as_mut() {
saved.profile.avatar = name;
}
}
fn forget_avatar(&mut self) {
self.avatar = slint::Image::default();
crate::images::forget_picture("myts-avatar");
if let Some(path) = self.avatar_path() {
let _ = std::fs::remove_file(path);
}
}
fn load(&mut self, secrets: &dyn Secrets) { fn load(&mut self, secrets: &dyn Secrets) {
match read_saved(secrets) { match read_saved(secrets) {
Ok(saved) => { Ok(saved) => {
self.saved = saved; self.saved = saved;
if self.saved.is_some() {
self.load_avatar();
}
self.can_forget = false; self.can_forget = false;
self.status = 0; self.status = 0;
self.persistence_status = 0; self.persistence_status = 0;
@@ -80,7 +195,17 @@ impl Account {
.renewal .renewal
.map(|renewal| (renewal.token, renewal.device_id, renewal.otp_token)) .map(|renewal| (renewal.token, renewal.device_id, renewal.otp_token))
.unwrap_or_default(); .unwrap_or_default();
// Another account's picture is not this one's.
let same_account =
self.saved.as_ref().is_some_and(|s| !s.uuid.is_empty() && s.uuid == login.uuid);
let mut profile =
if same_account { self.saved.take().unwrap().profile } else { SavedProfile::default() };
if !same_account {
self.forget_avatar();
}
profile.update(&login.profile);
let saved = Saved { let saved = Saved {
profile,
session: login.token.into_inner(), session: login.token.into_inner(),
email, email,
username: login.username, username: login.username,
@@ -108,12 +233,44 @@ impl Account {
self.status = 9; self.status = 9;
} }
} }
/// Store what the account service told (`Client::profile`).
fn take_profile(&mut self, secrets: &dyn Secrets, profile: &Profile) {
let Some(saved) = self.saved.as_mut() else { return };
if !profile.username.is_empty() {
saved.username = profile.username.clone();
}
saved.profile.update(profile);
if self.persistence_status == 0 && !save(secrets, saved) {
self.persistence_status = 5;
}
}
fn form(&self) -> MytsForm { fn form(&self) -> MytsForm {
let identity = self.identity(); let identity = self.identity();
let profile = self.saved.as_ref().map(|s| s.profile.clone()).unwrap_or_default();
let name = self
.saved
.as_ref()
.map(|s| if s.username.is_empty() { s.email.as_str() } else { s.username.as_str() })
.unwrap_or_default();
let strings = |items: Vec<String>| -> ModelRc<SharedString> {
ModelRc::new(VecModel::from(
items.into_iter().map(SharedString::from).collect::<Vec<_>>(),
))
};
MytsForm { MytsForm {
available: true, available: true,
prompt: self.prompt, prompt: self.prompt,
signed_in: self.signed_in, signed_in: self.signed_in,
// A saved session being checked: its profile shows, not the form.
restoring: !self.signed_in && self.busy && self.checking && self.saved.is_some(),
avatar: self.avatar.clone(),
initials: crate::vm::avatar::initials(name).into(),
description: profile.description.into(),
member_since: date(profile.registered).into(),
last_login: date(profile.last_login).into(),
badges: strings(profile.badges),
devices: strings(profile.devices),
email: self.saved.as_ref().map(|s| s.email.as_str()).unwrap_or_default().into(), email: self.saved.as_ref().map(|s| s.email.as_str()).unwrap_or_default().into(),
username: self.saved.as_ref().map(|s| s.username.as_str()).unwrap_or_default().into(), username: self.saved.as_ref().map(|s| s.username.as_str()).unwrap_or_default().into(),
uuid: self.saved.as_ref().map(|s| s.uuid.as_str()).unwrap_or_default().into(), uuid: self.saved.as_ref().map(|s| s.uuid.as_str()).unwrap_or_default().into(),
@@ -143,6 +300,7 @@ impl Account {
} }
self.generation += 1; self.generation += 1;
self.busy = true; self.busy = true;
self.checking = false;
self.status = 0; self.status = 0;
Some(self.generation) Some(self.generation)
} }
@@ -152,12 +310,14 @@ impl Account {
return false; return false;
} }
self.busy = false; self.busy = false;
self.checking = false;
true true
} }
fn forget(&mut self, secrets: &dyn Secrets) -> bool { fn forget(&mut self, secrets: &dyn Secrets) -> bool {
self.generation += 1; self.generation += 1;
self.busy = false; self.busy = false;
self.checking = false;
self.signed_in = false; self.signed_in = false;
self.prompt = true; self.prompt = true;
self.saved = None; self.saved = None;
@@ -166,6 +326,7 @@ impl Account {
let cleared = secrets.delete(KEY).is_ok(); let cleared = secrets.delete(KEY).is_ok();
self.persistence_status = if cleared { 0 } else { 8 }; self.persistence_status = if cleared { 0 } else { 8 };
self.can_forget = !cleared; self.can_forget = !cleared;
self.forget_avatar();
cleared cleared
} }
} }
@@ -238,15 +399,68 @@ impl App {
self.refresh_myts(); self.refresh_myts();
return; return;
} }
self.myts.prompt = true; self.myts.load(self.secrets.as_ref());
// Signed in before: no login page. The saved session is checked in
// the background, and only one that has expired asks again. Without
// one, the page shows unless "Continue without an account" was
// chosen before.
self.myts.prompt = self.myts.saved.is_none() && !self.settings.skip_account_prompt;
self.myts_retry(); self.myts_retry();
} }
pub(crate) fn myts_dismiss(&mut self) { pub(crate) fn myts_dismiss(&mut self) {
self.myts.prompt = false; self.myts.prompt = false;
if !self.demo_ui && !self.settings.skip_account_prompt {
self.settings.skip_account_prompt = true;
self.store_settings();
}
self.refresh_myts(); self.refresh_myts();
} }
/// Ask the account service for the profile and avatar of the signed-in
/// account; what comes back is stored and shown.
fn refresh_myts_profile(&self) {
let Some(token) =
self.myts.saved.as_ref().and_then(|s| SessionToken::new(s.session.clone()).ok())
else {
return;
};
let shown = self.myts.saved.as_ref().map(|s| s.profile.avatar.clone()).unwrap_or_default();
let has_picture = self.myts.avatar.size().width > 0;
let generation = self.myts.generation;
self.runtime.spawn(async move {
let client = match Client::new() {
Ok(client) => client,
Err(error) => return tracing::debug!(%error, "no account client"),
};
let profile = match client.profile(&token).await {
Ok(profile) => profile,
Err(error) => return tracing::info!(%error, "account profile not refreshed"),
};
let avatar = profile.avatars.first().cloned();
later(move |app| {
if app.myts.generation == generation && app.myts.signed_in {
app.myts.take_profile(app.secrets.as_ref(), &profile);
app.refresh_myts();
}
});
// The picture only when it changed (or was never fetched).
let Some(name) = avatar.filter(|name| *name != shown || !has_picture) else { return };
match client.avatar(&token, &name).await {
Ok(bytes) => later(move |app| {
if app.myts.generation == generation && app.myts.signed_in {
app.myts.set_avatar(name, &bytes);
if let Some(saved) = app.myts.saved.as_ref() {
let _ = save(app.secrets.as_ref(), saved);
}
app.refresh_myts();
}
}),
Err(error) => tracing::info!(%error, "account avatar not fetched"),
}
});
}
pub(crate) fn myts_portal(&mut self, action: i32) { pub(crate) fn myts_portal(&mut self, action: i32) {
let Some(url) = portal_url(action).filter(|_| !self.myts.busy) else { let Some(url) = portal_url(action).filter(|_| !self.myts.busy) else {
return; return;
@@ -269,6 +483,7 @@ impl App {
}; };
let token = SessionToken::new(saved.session.clone()).expect("validated stored token"); let token = SessionToken::new(saved.session.clone()).expect("validated stored token");
let generation = self.myts.begin().expect("startup is idle"); let generation = self.myts.begin().expect("startup is idle");
self.myts.checking = true;
self.refresh_myts(); self.refresh_myts();
self.runtime.spawn(async move { self.runtime.spawn(async move {
// Password login does not provide the separate auth token required // Password login does not provide the separate auth token required
@@ -280,7 +495,10 @@ impl App {
} }
let was_signed_in = app.myts.signed_in; let was_signed_in = app.myts.signed_in;
match result { match result {
Ok(()) => app.myts.restored(), Ok(()) => {
app.myts.restored();
app.refresh_myts_profile();
}
Err(error) => { Err(error) => {
app.myts.otp_required = app.myts.otp_required =
error.is_otp_required() || error.status_code() == Some(209); error.is_otp_required() || error.status_code() == Some(209);
@@ -288,6 +506,8 @@ impl App {
if error.is_invalid_session() { if error.is_invalid_session() {
app.myts.signed_in = false; app.myts.signed_in = false;
app.myts.status = 15; app.myts.status = 15;
// Expired: ask to sign in again.
app.myts.prompt = true;
} }
} }
} }
@@ -331,6 +551,11 @@ impl App {
Ok(login) => { Ok(login) => {
app.myts.accept(app.secrets.as_ref(), login, email.trim().to_owned()); app.myts.accept(app.secrets.as_ref(), login, email.trim().to_owned());
app.publish_myts_identity(); app.publish_myts_identity();
if app.settings.skip_account_prompt {
app.settings.skip_account_prompt = false;
app.store_settings();
}
app.refresh_myts_profile();
} }
Err(error) => { Err(error) => {
app.myts.otp_required = app.myts.otp_required =
@@ -398,6 +623,7 @@ impl App {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use slint::Model;
use voelin_store::MemorySecrets; use voelin_store::MemorySecrets;
fn login(name: &str) -> Login { fn login(name: &str) -> Login {
@@ -406,6 +632,11 @@ mod tests {
uuid: format!("{name}-uuid"), uuid: format!("{name}-uuid"),
username: name.into(), username: name.into(),
identity: Ok(server_identity()), identity: Ok(server_identity()),
profile: Profile {
description: format!("{name}'s profile"),
avatars: vec![format!("{name}.png")],
..Default::default()
},
renewal: Some(voelin_myts::Renewal { renewal: Some(voelin_myts::Renewal {
token: format!("{name}-renewal"), token: format!("{name}-renewal"),
otp_token: format!("{name}-otp"), otp_token: format!("{name}-otp"),
@@ -598,6 +829,59 @@ mod tests {
assert_eq!(account.status, 0); assert_eq!(account.status, 0);
} }
#[test]
fn a_saved_session_being_checked_shows_its_profile_not_the_form() {
let secrets = MemorySecrets::default();
let mut account = Account::default();
account.accept(&secrets, login("Alice"), "alice@example.test".into());
assert_eq!(account.form().description, "Alice's profile");
let mut restarted = Account { prompt: true, ..Default::default() };
restarted.load(&secrets);
restarted.begin().unwrap();
restarted.checking = true;
let form = restarted.form();
assert!(form.restoring && !form.signed_in);
assert_eq!((form.username.as_str(), form.initials.as_str()), ("Alice", "AL"));
// A password sign-in over an expired saved session shows the form.
restarted.finish(restarted.generation);
restarted.begin().unwrap();
assert!(!restarted.form().restoring);
}
#[test]
fn the_service_profile_is_kept_and_another_account_starts_empty() {
let secrets = MemorySecrets::default();
let mut account = Account::default();
account.accept(&secrets, login("Alice"), "alice@example.test".into());
let profile = Profile {
username: "Alice B".into(),
registered: 1_600_000_000,
badges: vec![voelin_myts::Badge { name: "Early".into(), ..Default::default() }],
devices: vec![voelin_myts::Device {
name: "Voelin".into(),
region: "EU".into(),
last_login: 0,
}],
..Default::default()
};
account.take_profile(&secrets, &profile);
let saved = read_saved(&secrets).unwrap().unwrap();
assert_eq!(saved.username, "Alice B");
assert_eq!(saved.profile.registered, 1_600_000_000);
assert_eq!(saved.profile.badges, ["Early"]);
assert_eq!(saved.profile.devices, ["Voelin · EU"]);
assert_eq!(saved.profile.description, "Alice's profile", "kept: not in this reply");
let form = account.form();
assert_eq!(form.member_since, date(1_600_000_000));
assert_eq!(form.badges.row_count(), 1);
// The same account signing in again keeps it, another one does not.
account.accept(&secrets, login("Alice"), "alice@example.test".into());
assert_eq!(account.saved.as_ref().unwrap().profile.registered, 1_600_000_000);
account.accept(&secrets, login("Bob"), "bob@example.test".into());
let bob = &account.saved.as_ref().unwrap().profile;
assert_eq!((bob.registered, bob.description.as_str()), (0, "Bob's profile"));
}
#[test] #[test]
fn form_exposes_signed_out_busy_otp_and_signed_in_states_without_tokens() { fn form_exposes_signed_out_busy_otp_and_signed_in_states_without_tokens() {
let mut account = Account::default(); let mut account = Account::default();
@@ -639,6 +923,7 @@ mod tests {
otp_token: "otp renewal".into(), otp_token: "otp renewal".into(),
uuid: "account-uuid".into(), uuid: "account-uuid".into(),
identity: Some(server_identity()), identity: Some(server_identity()),
profile: SavedProfile { description: "Hi".into(), ..Default::default() },
}; };
assert!(save(&secrets, &saved)); assert!(save(&secrets, &saved));
let loaded = read_saved(&secrets).unwrap().unwrap(); let loaded = read_saved(&secrets).unwrap().unwrap();
+4
View File
@@ -268,6 +268,9 @@ pub struct UiSettings {
pub share: ShareDefaults, pub share: ShareDefaults,
/// Write crash reports to disk (opt-in; never uploaded). /// Write crash reports to disk (opt-in; never uploaded).
pub crash_reports: bool, pub crash_reports: bool,
/// "Continue without an account" was chosen on the login page: it does
/// not show at start any more (signing in clears it).
pub skip_account_prompt: bool,
} }
impl Default for UiSettings { impl Default for UiSettings {
@@ -279,6 +282,7 @@ impl Default for UiSettings {
portal_restore_token: None, portal_restore_token: None,
share: ShareDefaults::default(), share: ShareDefaults::default(),
crash_reports: false, crash_reports: false,
skip_account_prompt: false,
} }
} }
} }
+13 -1
View File
@@ -769,8 +769,20 @@ export struct MytsForm {
identity-status: int, identity-status: int,
available: bool, available: bool,
signed_in: bool, signed_in: bool,
// A saved session is being checked: its profile shows meanwhile.
restoring: bool,
email: string, email: string,
username: string, username: string,
// From the account service: the avatar, the initials without one, the
// description, dates as YYYY-MM-DD ("" when not known), badge names and
// the signed-in devices ("name · region · date").
avatar: image,
initials: string,
description: string,
member-since: string,
last-login: string,
badges: [string],
devices: [string],
status: int, status: int,
persistence-status: int, persistence-status: int,
busy: bool, busy: bool,
@@ -1104,7 +1116,7 @@ export global Bridge {
callback settings-section(int); callback settings-section(int);
in property <AccountForm> account; in property <AccountForm> account;
in property <MytsForm> myts; in property <MytsForm> myts;
in property <string> primary-name: myts.signed-in ? (myts.username != "" ? myts.username : myts.email) : nickname != "" ? nickname : app-name; in property <string> primary-name: myts.signed-in || myts.restoring ? (myts.username != "" ? myts.username : myts.email) : nickname != "" ? nickname : app-name;
callback myts-dismiss(); callback myts-dismiss();
callback myts-retry(); callback myts-retry();
callback myts-portal(int); callback myts-portal(int);
+510 -123
View File
@@ -1,8 +1,11 @@
// Shared account form for first launch and Settings → My Account. // The myTeamSpeak account: the login page at start (not shown while a saved
// session exists) and the card in Settings → My Account. Both use the same
// sign-in form; signed in, the card shows the account's profile.
import { Theme } from "../theme.slint"; import { Theme } from "../theme.slint";
import { Icons } from "../icons.slint"; import { Icons } from "../icons.slint";
import { Bridge } from "../bridge.slint"; import { Bridge } from "../bridge.slint";
import { Button, TextField, Field, Card, ScrollView } from "../components/index.slint"; import { Nav } from "../nav.slint";
import { Icon, Spinner, Button, ButtonKind, IconButton, TextField, Field, Card, Divider, Banner, Avatar, Status, Chip, ScrollView } from "../components/index.slint";
component Note inherits Text { component Note inherits Text {
// Keep wrapped account copy in the card’s layout bounds. // Keep wrapped account copy in the card’s layout bounds.
@@ -12,9 +15,66 @@ component Note inherits Text {
wrap: word-wrap; wrap: word-wrap;
} }
component LoginForm inherits VerticalLayout { // What happened last, for `MytsForm.status`.
global AccountText {
pure public function status(code: int) -> string {
return code == 2 ? @tr("Saved session could not be validated. Your saved credentials were retained; sign in again or clear them.") :
code == 3 ? @tr("Enter your password again and the one-time code.") :
code == 4 ? @tr("Sign-in failed. Check your credentials and connection; the experimental service may be unavailable.") :
code == 7 ? @tr("Signed out.") :
code == 9 ? @tr("Signed out and saved credentials cleared. Remote session revocation failed.") :
code == 10 ? @tr("Could not open your browser. Visit myteamspeak.com to manage your account.") :
code == 11 ? @tr("Account website opened in your browser. When finished, return here and sign in again to apply changes.") :
code == 13 ? @tr("Your email address has not been verified. Activate your account using the link in your email, or request a new activation email.") :
code == 14 ? @tr("The one-time code was not accepted. Enter your password and a new code.") :
code == 15 ? @tr("Your saved session has expired. Sign in again.") :
code == 16 ? @tr("Email or password was not accepted. Check your details and try again.") :
code == 17 ? @tr("Too many requests. Wait a while before trying again.") : "";
}
// Information rather than a problem.
pure public function is-info(code: int) -> bool {
return code == 7 || code == 11;
}
pure public function persistence(code: int) -> string {
return code == 1 ? @tr("Saved account credentials could not be read. Unlock the keyring or clear the saved session.") :
code == 5 ? @tr("Account credentials could not be saved. This session will not be restored after restarting.") :
code == 6 ? @tr("Account credentials could not be saved, and older credentials could not be removed. Unlock your keyring and clear the saved session.") :
code == 8 ? @tr("Signed out locally, but saved credentials could not be removed. Unlock your keyring and clear the saved session again.") : "";
}
}
// The last result as a banner, and the keyring's problems.
component AccountNotices inherits VerticalLayout {
spacing: Theme.space-3; spacing: Theme.space-3;
property <string> status: AccountText.status(Bridge.myts.status);
property <string> persistence: AccountText.persistence(Bridge.myts.persistence-status);
if root.status != "": Banner {
text: root.status;
icon: AccountText.is-info(Bridge.myts.status) ? Icons.info : Icons.triangle-alert;
tone: AccountText.is-info(Bridge.myts.status) ? Theme.info : Theme.warning;
}
if Bridge.myts.status == 13: Button {
text: @tr("Resend activation email in browser");
icon: Icons.mail;
small: true;
enabled: !Bridge.myts.busy;
clicked => { Bridge.myts-portal(3); }
}
if root.persistence != "": Banner {
text: root.persistence;
icon: Icons.key-round;
tone: Theme.danger;
}
}
// Email, password (and the one-time code when asked for), Sign in, and
// the website's registration and password recovery.
component LoginForm inherits VerticalLayout {
spacing: Theme.space-4;
property <string> otp-text; property <string> otp-text;
property <bool> show-password;
function submit() { function submit() {
// The one-time code is asked for, never required to submit: another // The one-time code is asked for, never required to submit: another
// account needs none, and without it a 2FA account is asked again. // account needs none, and without it a 2FA account is asked again.
@@ -22,185 +82,512 @@ component LoginForm inherits VerticalLayout {
Bridge.myts-login(email.text, password.text, otp-text); Bridge.myts-login(email.text, password.text, otp-text);
password.clear(); password.clear();
otp-text = ""; otp-text = "";
show-password = false;
} }
} }
Field { Field {
label: @tr("Email"); label: @tr("Email");
email := TextField { email := TextField {
text: Bridge.myts.email; text: Bridge.myts.email;
placeholder: @tr("Email"); placeholder: @tr("you@example.com");
label: @tr("Email");
icon: Icons.mail;
enabled: !Bridge.myts.busy; enabled: !Bridge.myts.busy;
accepted(_) => { root.submit(); } accepted(_) => { password.focus(); }
} }
} }
Field { Field {
label: @tr("Password"); label: @tr("Password");
password := TextField { HorizontalLayout {
placeholder: @tr("Password"); spacing: Theme.space-2;
input-type: InputType.password; password := TextField {
enabled: !Bridge.myts.busy; placeholder: @tr("Password");
accepted(_) => { root.submit(); } label: @tr("Password");
icon: Icons.lock;
input-type: root.show-password ? InputType.text : InputType.password;
enabled: !Bridge.myts.busy;
accepted(_) => { root.submit(); }
}
IconButton {
icon: root.show-password ? Icons.eye-off : Icons.eye;
label: root.show-password ? @tr("Hide password") : @tr("Show password");
checked: root.show-password;
clicked => { root.show-password = !root.show-password; }
}
} }
} }
if Bridge.myts.otp-required: Field { if Bridge.myts.otp-required: Field {
label: @tr("One-time code"); label: @tr("One-time code");
hint: @tr("The code from your authenticator app.");
TextField { TextField {
text <=> root.otp-text; text <=> root.otp-text;
placeholder: @tr("One-time code"); placeholder: "123456";
input-type: InputType.password; label: @tr("One-time code");
icon: Icons.key-round;
input-type: InputType.number;
enabled: !Bridge.myts.busy; enabled: !Bridge.myts.busy;
accepted(_) => { root.submit(); } accepted(_) => { root.submit(); }
} }
} }
Button { Button {
text: @tr("Sign in"); kind: ButtonKind.primary;
icon: Icons.log-in;
text: Bridge.myts.busy ? @tr("Signing in…") : @tr("Sign in");
enabled: !Bridge.myts.busy && email.text != "" && password.text != ""; enabled: !Bridge.myts.busy && email.text != "" && password.text != "";
clicked => { root.submit(); } clicked => { root.submit(); }
} }
Button { HorizontalLayout {
text: @tr("Create account in browser"); spacing: Theme.space-2;
enabled: !Bridge.myts.busy; Button {
clicked => { Bridge.myts-portal(0); } kind: ButtonKind.ghost;
small: true;
text: @tr("Forgot password?");
enabled: !Bridge.myts.busy;
clicked => { Bridge.myts-portal(1); }
}
Rectangle { horizontal-stretch: 1; }
Button {
kind: ButtonKind.ghost;
small: true;
icon: Icons.user-plus;
text: @tr("Create an account");
enabled: !Bridge.myts.busy;
clicked => { Bridge.myts-portal(0); }
}
} }
Button {
text: @tr("Forgot password?");
enabled: !Bridge.myts.busy;
clicked => { Bridge.myts-portal(1); }
}
Note { text: @tr("Registration and password recovery open the official myTeamSpeak website. Return here to sign in when finished."); }
} }
export component AccountCard inherits Card { // A labelled line of the profile: an icon, a label and its value.
title: @tr("myTeamSpeak"); component ProfileRow inherits HorizontalLayout {
icon: Icons.user; in property <image> icon;
property <string> account-status: Bridge.myts.status == 2 ? @tr("Saved session could not be validated. Your saved credentials were retained; sign in again or clear them.") : in property <string> label;
Bridge.myts.status == 3 ? @tr("Enter your password again and the one-time code.") : in property <string> value;
Bridge.myts.status == 4 ? @tr("Sign-in failed. Check your credentials and connection; the experimental service may be unavailable.") : spacing: Theme.space-3;
Bridge.myts.status == 7 ? @tr("Signed out.") : Icon {
Bridge.myts.status == 9 ? @tr("Signed out and saved credentials cleared. Remote session revocation failed.") : source: root.icon;
Bridge.myts.status == 10 ? @tr("Could not open your browser. Visit myteamspeak.com to manage your account.") : size: Theme.icon-sm;
Bridge.myts.status == 11 ? @tr("Account website opened in your browser. When finished, return here and sign in again to apply changes.") : tint: Theme.text-muted;
Bridge.myts.status == 13 ? @tr("Your email address has not been verified. Activate your account using the link in your email, or request a new activation email.") : y: (parent.height - self.height) / 2;
Bridge.myts.status == 14 ? @tr("The one-time code was not accepted. Enter your password and a new code.") : }
Bridge.myts.status == 15 ? @tr("Your saved session has expired. Sign in again.") : Text {
Bridge.myts.status == 16 ? @tr("Email or password was not accepted. Check your details and try again.") : text: root.label;
Bridge.myts.status == 17 ? @tr("Too many requests. Wait a while before trying again.") : ""; color: Theme.text-secondary;
if !Bridge.myts.available: Note { text: @tr("Account sign-in is available on desktop."); } font-size: Theme.font-sm;
if Bridge.myts.available && !Bridge.myts.signed-in: LoginForm { } vertical-alignment: center;
if Bridge.myts.signed-in: VerticalLayout { }
spacing: Theme.space-3; Text {
Note { text: @tr("Primary account"); } text: root.value;
color: Theme.text;
font-size: Theme.font-sm;
horizontal-alignment: right;
vertical-alignment: center;
horizontal-stretch: 1;
overflow: elide;
}
}
// Avatar, name, email and what state the account is in.
component ProfileHeader inherits HorizontalLayout {
in property <length> avatar-size: 72px;
spacing: Theme.space-5;
Avatar {
size: root.avatar-size;
image: Bridge.myts.avatar;
initials: Bridge.myts.initials;
tint: Theme.accent;
label: Bridge.primary-name;
status: Bridge.myts.signed-in ? Status.online : Status.idle;
y: (parent.height - self.height) / 2;
}
VerticalLayout {
alignment: center;
spacing: Theme.space-2;
horizontal-stretch: 1;
Text { Text {
text: Bridge.primary-name; text: Bridge.primary-name;
color: Theme.text; color: Theme.text;
font-size: Theme.font-lg; font-size: Theme.font-2xl;
font-weight: Theme.weight-semibold; font-weight: Theme.weight-semibold;
wrap: word-wrap; overflow: elide;
} }
Note { text: Bridge.myts.email; } if Bridge.myts.email != "": Text {
if Bridge.myts.uuid != "": Field { text: Bridge.myts.email;
color: Theme.text-secondary;
overflow: elide;
}
HorizontalLayout {
spacing: Theme.space-2;
alignment: start;
if Bridge.myts.restoring: Chip {
text: @tr("Checking session…");
icon: Icons.loader;
}
if Bridge.myts.signed-in: Chip {
text: @tr("Signed in");
icon: Icons.circle-check;
tint: Theme.success;
fill: Theme.success-soft;
}
if Bridge.myts.signed-in && Bridge.myts.identity-status == 1: Chip {
text: @tr("myTS ID active");
icon: Icons.shield-check;
tint: Theme.accent-text;
fill: Theme.accent-soft;
}
}
}
}
// What the account service tells: description, dates, badges, devices.
component ProfileDetails inherits VerticalLayout {
spacing: Theme.space-3;
if Bridge.myts.description != "": Text {
text: Bridge.myts.description;
color: Theme.text;
font-italic: true;
wrap: word-wrap;
}
if Bridge.myts.member-since != "": ProfileRow {
icon: Icons.calendar;
label: @tr("Member since");
value: Bridge.myts.member-since;
}
if Bridge.myts.last-login != "": ProfileRow {
icon: Icons.clock;
label: @tr("Previous sign-in");
value: Bridge.myts.last-login;
}
if Bridge.myts.badges.length > 0: VerticalLayout {
spacing: Theme.space-2;
Text {
text: @tr("Badges");
color: Theme.text-secondary;
font-size: Theme.font-sm;
font-weight: Theme.weight-medium;
}
for badge in Bridge.myts.badges: HorizontalLayout {
spacing: Theme.space-3;
Icon {
source: Icons.star;
size: Theme.icon-sm;
tint: Theme.gold;
}
Text {
text: badge;
color: Theme.text;
font-size: Theme.font-sm;
overflow: elide;
horizontal-stretch: 1;
}
}
}
if Bridge.myts.devices.length > 0: VerticalLayout {
spacing: Theme.space-2;
Text {
text: @tr("Signed-in devices");
color: Theme.text-secondary;
font-size: Theme.font-sm;
font-weight: Theme.weight-medium;
}
for device in Bridge.myts.devices: HorizontalLayout {
spacing: Theme.space-3;
Icon {
source: Icons.monitor;
size: Theme.icon-sm;
tint: Theme.text-muted;
}
Text {
text: device;
color: Theme.text;
font-size: Theme.font-sm;
overflow: elide;
horizontal-stretch: 1;
}
}
}
}
// The signed-in account (or the saved one being checked).
component AccountProfile inherits VerticalLayout {
spacing: Theme.space-5;
ProfileHeader { }
ProfileDetails { }
Divider { }
if Bridge.myts.uuid != "": Field {
label: @tr("Account ID");
TextField {
text: Bridge.myts.uuid;
read-only: true;
label: @tr("Account ID"); label: @tr("Account ID");
TextField { icon: Icons.id-card;
text: Bridge.myts.uuid;
read-only: true;
label: @tr("Account ID");
}
} }
if Bridge.myts.myts-id != "": Field { }
if Bridge.myts.myts-id != "": Field {
label: @tr("myTS ID");
TextField {
text: Bridge.myts.myts-id;
read-only: true;
label: @tr("myTS ID"); label: @tr("myTS ID");
TextField { icon: Icons.shield-check;
text: Bridge.myts.myts-id;
read-only: true;
label: @tr("myTS ID");
}
} }
if Bridge.myts.identity-status == 1: Note { }
text: @tr("Your account identity is available for authentication on voice servers."); if Bridge.myts.signed-in && Bridge.myts.identity-status == 1: Note {
} text: @tr("Your account identity is available for authentication on voice servers.");
if Bridge.myts.identity-status == 2: Note { }
text: @tr("Sign out and sign in with your password to enable your myTS ID on voice servers."); if Bridge.myts.signed-in && Bridge.myts.identity-status == 2: Note {
} text: @tr("Sign out and sign in with your password to enable your myTS ID on voice servers.");
if Bridge.myts.identity-status == 3: Note { }
text: @tr("Signed in, but the account identity could not be unlocked. Voice servers will not receive your myTS ID. Try signing in again; older account encryption may be unsupported."); if Bridge.myts.signed-in && Bridge.myts.identity-status == 3: Note {
} text: @tr("Signed in, but the account identity could not be unlocked. Voice servers will not receive your myTS ID. Try signing in again; older account encryption may be unsupported.");
Note { text: @tr("This is your main app profile. Server identities and server nicknames are managed separately."); } }
Note { text: @tr("Account management opens the official website. Check which account is signed in there. Sign in again here after making changes."); } Note { text: @tr("This is your main app profile. Server identities and server nicknames are managed separately."); }
Button { }
text: @tr("Manage account in browser");
enabled: !Bridge.myts.busy; // Changes are made on the official website.
clicked => { Bridge.myts-portal(2); } component AccountManagement inherits VerticalLayout {
} spacing: Theme.space-3;
for action in [ Text {
{ text: @tr("Change username"), portal: 4 }, text: @tr("Manage your account");
{ text: @tr("Change email"), portal: 5 }, color: Theme.text;
{ text: @tr("Change password"), portal: 6 }, font-weight: Theme.weight-semibold;
{ text: @tr("Two-factor authentication"), portal: 7 }, }
{ text: @tr("Manage account deletion"), portal: 8 }, Note { text: @tr("Account management opens the official website. Check which account is signed in there. Sign in again here after making changes."); }
{ text: @tr("Export account data"), portal: 9 }, Button {
]: Button { icon: Icons.external-link;
text: action.text; text: @tr("Manage account in browser");
enabled: !Bridge.myts.busy;
clicked => { Bridge.myts-portal(2); }
}
for row in [
[{ text: @tr("Change username"), icon: Icons.user, portal: 4 }, { text: @tr("Change email"), icon: Icons.mail, portal: 5 }],
[{ text: @tr("Change password"), icon: Icons.lock, portal: 6 }, { text: @tr("Two-factor authentication"), icon: Icons.key-round, portal: 7 }],
[{ text: @tr("Export account data"), icon: Icons.download, portal: 9 }, { text: @tr("Manage account deletion"), icon: Icons.trash-2, portal: 8 }],
]: HorizontalLayout {
spacing: Theme.space-3;
for action in row: Button {
horizontal-stretch: 1;
kind: ButtonKind.ghost;
small: true; small: true;
centered: false;
icon: action.icon;
text: action.text;
enabled: !Bridge.myts.busy; enabled: !Bridge.myts.busy;
clicked => { Bridge.myts-portal(action.portal); } clicked => { Bridge.myts-portal(action.portal); }
} }
} }
if Bridge.myts.busy: Note { text: @tr("Contacting account service…"); } }
if root.account-status != "": Note { text: root.account-status; }
if Bridge.myts.persistence-status == 1: Note { // Retry a saved session, sign out or clear what is stored.
text: @tr("Saved account credentials could not be read. Unlock the keyring or clear the saved session."); component SessionActions inherits HorizontalLayout {
spacing: Theme.space-3;
alignment: start;
if Bridge.myts.busy: Spinner {
size: 18px;
y: (parent.height - self.height) / 2;
} }
if Bridge.myts.persistence-status == 5: Note { if Bridge.myts.busy: Text {
text: @tr("Account credentials could not be saved. This session will not be restored after restarting."); text: Bridge.myts.restoring ? @tr("Checking your saved session…") : @tr("Contacting account service…");
} color: Theme.text-secondary;
if Bridge.myts.persistence-status == 6: Note { font-size: Theme.font-sm;
text: @tr("Account credentials could not be saved, and older credentials could not be removed. Unlock your keyring and clear the saved session."); vertical-alignment: center;
}
if Bridge.myts.persistence-status == 8: Note {
text: @tr("Signed out locally, but saved credentials could not be removed. Unlock your keyring and clear the saved session again.");
}
if Bridge.myts.status == 13: Button {
text: @tr("Resend activation email in browser");
enabled: !Bridge.myts.busy;
clicked => { Bridge.myts-portal(3); }
} }
if Bridge.myts.can-forget && !Bridge.myts.busy: Button { if Bridge.myts.can-forget && !Bridge.myts.busy: Button {
icon: Icons.refresh-cw;
small: true;
text: Bridge.myts.signed-in ? @tr("Check session") : @tr("Retry saved session"); text: Bridge.myts.signed-in ? @tr("Check session") : @tr("Retry saved session");
clicked => { Bridge.myts-retry(); } clicked => { Bridge.myts-retry(); }
} }
if Bridge.myts.can-forget || Bridge.myts.busy: Button { if Bridge.myts.can-forget || Bridge.myts.busy: Button {
kind: Bridge.myts.signed-in ? ButtonKind.secondary : ButtonKind.danger;
icon: Icons.log-out;
small: true;
text: Bridge.myts.busy ? @tr("Cancel and clear session") : Bridge.myts.signed-in ? @tr("Sign out") : @tr("Clear saved session"); text: Bridge.myts.busy ? @tr("Cancel and clear session") : Bridge.myts.signed-in ? @tr("Sign out") : @tr("Clear saved session");
clicked => { Bridge.myts-logout(); } clicked => { Bridge.myts-logout(); }
} }
} }
export component LoginPage inherits ScrollView { // Settings → My Account.
export component AccountCard inherits Card {
title: @tr("myTeamSpeak");
icon: Icons.user;
subtitle: Bridge.myts.signed-in ? @tr("Your account") : Bridge.myts.restoring ? @tr("Checking your saved session") : @tr("Sign in to make your account your main profile");
if !Bridge.myts.available: Note { text: @tr("Account sign-in is available on desktop."); }
if Bridge.myts.signed-in || Bridge.myts.restoring: AccountProfile { }
if Bridge.myts.available && !Bridge.myts.signed-in && !Bridge.myts.restoring: LoginForm { }
AccountNotices { }
SessionActions { }
if Bridge.myts.signed-in: Divider { }
if Bridge.myts.signed-in: AccountManagement { }
}
// The artwork beside the form: the night landscape, what an account gives.
component LoginHero inherits Rectangle {
clip: true;
border-radius: Theme.radius-xl;
background: @linear-gradient(150deg, #0e1d5c 0%, #1c1470 45%, #3a1f86 75%, #0b2a6b 100%);
property <float> ratio: art.source.width * 1.0 / max(1, art.source.height);
art := Image {
source: Icons.art-banner;
// Cover the panel, the moon (right) kept.
width: max(root.width, root.height * root.ratio);
height: self.width / root.ratio;
x: root.width - self.width;
y: root.height - self.height;
image-fit: fill;
accessible-role: AccessibleRole.none;
}
Rectangle {
background: @linear-gradient(180deg, #060c2ce0 0%, #060c2c90 45%, #060c2c30 100%);
}
VerticalLayout { VerticalLayout {
width: root.visible-width; padding: Theme.space-8;
padding: Theme.space-4; spacing: Theme.space-6;
spacing: Theme.space-5;
alignment: start; alignment: start;
HorizontalLayout { HorizontalLayout {
Rectangle { horizontal-stretch: 1; } spacing: Theme.space-4;
VerticalLayout { alignment: start;
max-width: 480px; Image {
width: 48px;
height: 48px;
source: Icons.logo;
}
Text {
text: Bridge.app-name;
color: #ffffff;
font-size: Theme.font-3xl;
font-weight: Theme.weight-bold;
vertical-alignment: center;
}
}
Text {
text: @tr("Your TeamSpeak account, everywhere you talk.");
color: #ffffff;
font-size: Theme.font-2xl;
font-weight: Theme.weight-semibold;
wrap: word-wrap;
}
for feature in [
{ icon: Icons.user-check, text: @tr("Your myTeamSpeak name and avatar become your profile.") },
{ icon: Icons.shield-check, text: @tr("Voice servers recognise you by your myTS ID.") },
{ icon: Icons.star, text: @tr("Your badges and devices at a glance.") },
]: HorizontalLayout {
spacing: Theme.space-4;
Rectangle {
width: 36px;
height: 36px;
border-radius: Theme.radius-md;
background: #ffffff1f;
Icon {
source: feature.icon;
tint: #ffffff;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
}
Text {
text: feature.text;
color: #e4e9ff;
vertical-alignment: center;
wrap: word-wrap;
horizontal-stretch: 1; horizontal-stretch: 1;
spacing: Theme.space-4;
Text {
text: @tr("Welcome to {}", Bridge.app-name);
color: Theme.text;
font-size: Theme.font-xl;
font-weight: Theme.weight-semibold;
wrap: word-wrap;
}
Note { text: @tr("Sign in to make your myTeamSpeak account your main profile."); }
AccountCard { }
Button {
text: @tr("Continue without an account");
clicked => { Bridge.myts-dismiss(); }
}
Note { text: @tr("You can connect to servers without an account and sign in later in Settings → My Account."); }
} }
Rectangle { horizontal-stretch: 1; } }
}
}
// First launch without a saved session: sign in or go on without.
export component LoginPage inherits Rectangle {
background: Theme.backdrop;
// The window's width (`Nav.narrow`), not this page's: the artwork's
// width is part of the page's own layout.
property <bool> wide: !Nav.narrow;
HorizontalLayout {
padding: root.wide ? Theme.space-6 : 0px;
spacing: Theme.space-6;
// Half the window at most, by stretch (a width from the page's own
// width would loop through its layout).
if root.wide: LoginHero {
horizontal-stretch: 1;
min-width: 320px;
max-width: 600px;
}
scroll := ScrollView {
horizontal-stretch: 1;
VerticalLayout {
width: scroll.visible-width;
min-height: scroll.visible-height;
padding: Theme.space-6;
alignment: center;
HorizontalLayout {
Rectangle { horizontal-stretch: 1; }
VerticalLayout {
max-width: 440px;
horizontal-stretch: 1;
spacing: Theme.space-5;
if !root.wide: HorizontalLayout {
spacing: Theme.space-3;
alignment: start;
Image {
width: 36px;
height: 36px;
source: Icons.logo;
}
Text {
text: Bridge.app-name;
color: Theme.text;
font-size: Theme.font-2xl;
font-weight: Theme.weight-bold;
vertical-alignment: center;
}
}
VerticalLayout {
spacing: Theme.space-2;
Text {
text: @tr("Sign in");
color: Theme.text;
font-size: Theme.font-3xl;
font-weight: Theme.weight-bold;
}
Note { text: @tr("Use your myTeamSpeak account to make it your main profile in {}.", Bridge.app-name); }
}
Rectangle {
border-radius: Theme.radius-xl;
background: Theme.surface;
border-width: 1px;
border-color: Theme.border;
VerticalLayout {
padding: Theme.space-7;
spacing: Theme.space-5;
if !Bridge.myts.available: Note { text: @tr("Account sign-in is available on desktop."); }
if Bridge.myts.available: LoginForm { }
AccountNotices { }
SessionActions { }
}
}
HorizontalLayout {
spacing: Theme.space-3;
Divider { y: (parent.height - self.height) / 2; }
Text {
text: @tr("or");
color: Theme.text-muted;
font-size: Theme.font-sm;
horizontal-stretch: 0;
}
Divider { y: (parent.height - self.height) / 2; }
}
Button {
icon: Icons.arrow-right;
text: @tr("Continue without an account");
clicked => { Bridge.myts-dismiss(); }
}
Note {
text: @tr("Servers work without an account. You can sign in later in Settings → My Account; this page will not ask again.");
horizontal-alignment: center;
}
}
Rectangle { horizontal-stretch: 1; }
}
}
} }
} }
} }
+3 -2
View File
@@ -180,7 +180,8 @@ export component UserCard inherits Rectangle {
Avatar { Avatar {
size: 38px; size: 38px;
initials: Bridge.myts.signed-in || Bridge.nickname != "" ? "" : "?"; initials: Bridge.myts.signed-in || Bridge.nickname != "" ? "" : "?";
image: Bridge.own-avatar; // The server's avatar for us, else the account's.
image: Bridge.own-avatar.width > 0 ? Bridge.own-avatar : Bridge.myts.avatar;
tint: Theme.accent; tint: Theme.accent;
label: Bridge.primary-name; label: Bridge.primary-name;
// Green ring while our voice goes out. // Green ring while our voice goes out.
@@ -190,7 +191,7 @@ export component UserCard inherits Rectangle {
source: Icons.user; source: Icons.user;
size: 20px; size: 20px;
tint: #ffffff; tint: #ffffff;
visible: (Bridge.myts.signed-in || Bridge.nickname != "") && Bridge.own-avatar.width == 0; visible: (Bridge.myts.signed-in || Bridge.nickname != "") && Bridge.own-avatar.width == 0 && Bridge.myts.avatar.width == 0;
} }
} }
} }
+25 -6
View File
@@ -84,11 +84,30 @@ are stored together as a single `myts/session` item through the app's secret
store, never in plaintext settings. Replacing one item prevents a partial write store, never in plaintext settings. Replacing one item prevents a partial write
from mixing credentials from different accounts. The bundle also stores the from mixing credentials from different accounts. The bundle also stores the
account UUID, username and email, with backward-compatible defaults for older account UUID, username and email, with backward-compatible defaults for older
bundles. Startup validates a saved session before showing its profile as signed bundles. With a saved session the login page does not open at all: startup
in. A valid session closes the login page; errors leave retry and manual sign-in validates the session in the background (Settings → My Account shows the saved
available. Transport failures retain saved credentials. A locked keyring can be profile as "Checking session…" meanwhile) and only an expired session brings
retried without restarting. Continue without an account dismisses the prompt the page back. Errors leave retry and manual sign-in available. Transport
for the current run and leaves server features available. failures retain saved credentials. A locked keyring can be retried without
restarting. Continue without an account dismisses the page and is remembered
(`ui.skip_account_prompt`), so it does not ask at the next start; signing in
clears that.
### Profile and avatar
After a sign-in or a validated saved session the app asks the user service,
`https://clientapi.myteamspeak.com/user` (the route string is in the TS6
client next to `/authentication` and `/session`), for `getAccountData` with the
basic info, avatars, description, badges and authenticated devices, and shows
them in Settings → My Account (and the avatar in the sidebar's profile when
the server has none for us). `requestAvatarSignedUrl` turns the avatar's file
name (the "online" one first) into a signed HTTPS link, which is fetched
(at most 4 MiB) and kept in `<data>/account/avatar` for the next start; it is
fetched again only when the file name changes. The login response's own
avatar file names and description are used until then. What is kept goes into
the same secret-store bundle as the session (`profile`), never the token into
a URL. Neither call has been run against the live service from this
environment.
Sign-out returns to login, clears local account material and attempts remote Sign-out returns to login, clears local account material and attempts remote
session deletion; storage or remote errors are reported. A late completion session deletion; storage or remote errors are reported. A late completion
@@ -131,7 +150,7 @@ The main account is shared by all voice connections. Each new connection signs
its own challenge. Account changes cancel an unfinished handshake; connected its own challenge. Account changes cancel an unfinished handshake; connected
clients send `updatemytsid`, and logout sends an empty myTS ID. Rejected or clients send `updatemytsid`, and logout sends an empty myTS ID. Rejected or
unanswered account updates disconnect rather than retaining a previous account unanswered account updates disconnect rather than retaining a previous account
association. Cloud avatar retrieval is outside this branch. association.
Static TS3 evidence in the binary identified above: proof helper `0x1018580`, Static TS3 evidence in the binary identified above: proof helper `0x1018580`,
`clientinit` invocation `0x1020c3b`, live update `0x1049659`, scalar signing `clientinit` invocation `0x1020c3b`, live update `0x1049659`, scalar signing
+14 -6
View File
@@ -192,12 +192,20 @@ Settings sections (`settings:<section>`):
Settings controls read and write `voelin_core::settings` and apply at once; Settings controls read and write `voelin_core::settings` and apply at once;
numbers are typed freely next to the presets. numbers are typed freely next to the presets.
Desktop startup shows the shared myTeamSpeak login page until a saved session Desktop startup shows the myTeamSpeak login page (`LoginPage` in
is validated, a login succeeds, or the user chooses Continue without an account. `screens/account.slint`: the artwork and what an account gives beside the
The signed-in username/email becomes the primary app profile in the desktop form on wide windows, the form alone on narrow ones; email, password with a
user card and mobile You page; it does not replace server identities or bookmark show button, the one-time code when asked, Sign in, password recovery and
nicknames. Settings → My Account reuses the form, supports retry/OTP/sign-out, registration on the website) only when no session is saved and Continue
and opens official browser flows for registration, activation, recovery and without an account was never chosen (`ui.skip_account_prompt`). A saved
session is checked in the background; only an expired one brings the page
back. The signed-in username/email and the account's avatar become the
primary app profile in the desktop user card and mobile You page; they do
not replace server identities or bookmark nicknames. Settings → My Account
shows the profile from the account service (avatar, name, email,
description, member since, previous sign-in, badges, signed-in devices, the
account and myTS ids) or the sign-in form, supports retry/OTP/sign-out, and
opens official browser flows for registration, activation, recovery and
account management. Account and renewal material live only in the keyring; account management. Account and renewal material live only in the keyring;
passwords and one-time codes are cleared after submission. Expired sessions passwords and one-time codes are cleared after submission. Expired sessions
require fresh sign-in because password login supplies no renewal auth token. require fresh sign-in because password login supplies no renewal auth token.