ACCOUNT CREATION AND LOGIN
This commit is contained in:
@@ -4,17 +4,19 @@ use rand::TryRng;
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub enum ClientMsgInst {
|
||||
CreateAccountV0(CreateAccountV0) = 0,
|
||||
RequestMsgsV0 = 1,
|
||||
SendMsgV0(SendMsgV0) = 2,
|
||||
LoginV0(LoginV0) = 1,
|
||||
RequestMsgsV0 = 2,
|
||||
SendMsgV0(SendMsgV0) = 3,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub enum ServerMsgInst {
|
||||
CreateAccountV0(CreateAccountRespV0) = 0,
|
||||
LoadMsgV0(LoadMsgV0) = 1,
|
||||
LoadMsgsV0(Vec<LoadMsgV0>) = 2,
|
||||
ServerErrorV0(ServerErrorV0) = 3,
|
||||
CreateAccountRespV0(CreateAccountRespV0) = 0,
|
||||
LoginRespV0(LoginRespV0) = 1,
|
||||
LoadMsgV0(LoadMsgV0) = 2,
|
||||
LoadMsgsV0(Vec<LoadMsgV0>) = 3,
|
||||
ServerErrorV0(ServerErrorV0) = 4,
|
||||
}
|
||||
|
||||
pub type UserIdV0 = u64;
|
||||
@@ -24,7 +26,12 @@ pub struct CreateAccountV0 {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub token: String,
|
||||
pub login_key: LoginKeyV0,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct LoginV0 {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
@@ -34,6 +41,13 @@ pub enum CreateAccountRespV0 {
|
||||
InvalidToken,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub enum LoginRespV0 {
|
||||
Ok { id: UserIdV0 },
|
||||
UnknownUsername,
|
||||
InvalidPassword,
|
||||
}
|
||||
|
||||
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
||||
pub struct LoginKeyV0(Vec<u8>);
|
||||
impl LoginKeyV0 {
|
||||
@@ -47,6 +61,10 @@ impl LoginKeyV0 {
|
||||
.expect("failed to generate random key");
|
||||
Self(key.to_vec())
|
||||
}
|
||||
|
||||
pub fn bytes(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl From<Vec<u8>> for LoginKeyV0 {
|
||||
fn from(value: Vec<u8>) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user