use serde::{Deserialize, Serialize}; #[tarpc::service] pub trait RealmAuth { async fn test(name: String) -> String; async fn server_token_validation(server_token: String, username: String, server_id: String, domain: String, tarpc_port: u16) -> bool; async fn create_account_flow(username: String, email: String) -> ErrorCode; //NOTE: Still require sign in flow async fn create_login_flow(username: Option, email: Option) -> ErrorCode; async fn finish_login_flow(username: String, login_code: u16) -> Result; //NOTE: Need to be the user async fn change_email_flow(username: String, new_email: String, token: String) -> ErrorCode; async fn finish_change_email_flow(username: String, token: String, login_code: u16) -> ErrorCode; async fn change_username(username: String, token: String, new_username: String) -> ErrorCode; async fn change_avatar(username: String, token: String, new_avatar: String) -> ErrorCode; async fn get_all_data(username: String, token: String) -> Result; async fn sign_out(username: String, token: String) -> ErrorCode; //NOTE: Anyone can call async fn get_avatar_for_user(username: String) -> Result; //TODO: // Create account // Change email // Change username // OAuth login, check against email, store token, take avatar: Google, Apple, GitHub, Discord } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum ErrorCode { NoError, Error, Unauthorized, EmailTaken, UsernameTaken, InvalidLoginCode, InvalidImage, InvalidUsername, InvalidEmail, InvalidToken, UnableToConnectToMail, UnableToSendMail, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AuthUser { pub id: u32, pub username: String, pub email: String, pub avatar: String, pub login_code: Option, pub bigtoken: Option, pub google_oauth: Option, pub apple_oauth: Option, pub github_oauth: Option, pub discord_oauth: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AuthEmail { pub server_address: String, pub server_port: u16, pub auth_name: String, pub auth_from_address: String, pub auth_username: String, pub auth_password: String, }