2021-07-05 21:23:13 +08:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2021-11-07 21:45:18 +08:00
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
|
|
|
|
use crate::{errors::*, parser::*};
|
|
|
|
|
2021-08-31 17:25:08 +08:00
|
|
|
#[derive(ProtoBuf, Default)]
|
2022-02-24 21:49:18 +08:00
|
|
|
pub struct SignInPayload {
|
2021-08-31 17:25:08 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub password: String,
|
2021-11-06 22:35:45 +08:00
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub name: String,
|
2021-08-31 17:25:08 +08:00
|
|
|
}
|
|
|
|
|
2021-09-06 16:18:34 +08:00
|
|
|
#[derive(Default, ProtoBuf, Debug)]
|
2021-08-31 17:25:08 +08:00
|
|
|
pub struct SignInParams {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub password: String,
|
2021-11-06 22:35:45 +08:00
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub name: String,
|
2021-08-31 17:25:08 +08:00
|
|
|
}
|
|
|
|
|
2021-12-09 22:28:11 +08:00
|
|
|
#[derive(Debug, Default, ProtoBuf, Clone)]
|
2021-08-31 17:25:08 +08:00
|
|
|
pub struct SignInResponse {
|
|
|
|
#[pb(index = 1)]
|
2021-09-08 18:25:32 +08:00
|
|
|
pub user_id: String,
|
2021-08-31 17:25:08 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub token: String,
|
|
|
|
}
|
|
|
|
|
2022-02-24 21:49:18 +08:00
|
|
|
impl TryInto<SignInParams> for SignInPayload {
|
2021-11-07 21:45:18 +08:00
|
|
|
type Error = ErrorCode;
|
2021-08-31 17:25:08 +08:00
|
|
|
|
|
|
|
fn try_into(self) -> Result<SignInParams, Self::Error> {
|
2021-11-07 21:45:18 +08:00
|
|
|
let email = UserEmail::parse(self.email)?;
|
|
|
|
let password = UserPassword::parse(self.password)?;
|
2021-08-31 17:25:08 +08:00
|
|
|
|
|
|
|
Ok(SignInParams {
|
|
|
|
email: email.0,
|
|
|
|
password: password.0,
|
2021-11-06 22:35:45 +08:00
|
|
|
name: self.name,
|
2021-08-31 17:25:08 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-05 21:23:13 +08:00
|
|
|
#[derive(ProtoBuf, Default)]
|
2022-02-24 21:49:18 +08:00
|
|
|
pub struct SignUpPayload {
|
2021-07-05 21:23:13 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub password: String,
|
|
|
|
}
|
2022-02-24 21:49:18 +08:00
|
|
|
impl TryInto<SignUpParams> for SignUpPayload {
|
2021-11-07 21:45:18 +08:00
|
|
|
type Error = ErrorCode;
|
2021-07-05 21:23:13 +08:00
|
|
|
|
2021-07-09 14:02:42 +08:00
|
|
|
fn try_into(self) -> Result<SignUpParams, Self::Error> {
|
2021-11-07 21:45:18 +08:00
|
|
|
let email = UserEmail::parse(self.email)?;
|
|
|
|
let password = UserPassword::parse(self.password)?;
|
|
|
|
let name = UserName::parse(self.name)?;
|
2021-07-11 21:54:55 +08:00
|
|
|
|
2021-07-09 14:02:42 +08:00
|
|
|
Ok(SignUpParams {
|
2021-07-05 21:23:13 +08:00
|
|
|
email: email.0,
|
|
|
|
name: name.0,
|
|
|
|
password: password.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 16:18:34 +08:00
|
|
|
#[derive(ProtoBuf, Default, Debug)]
|
2021-07-09 14:02:42 +08:00
|
|
|
pub struct SignUpParams {
|
2021-07-05 21:23:13 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub password: String,
|
|
|
|
}
|
|
|
|
|
2021-12-09 22:28:11 +08:00
|
|
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
2021-07-09 14:02:42 +08:00
|
|
|
pub struct SignUpResponse {
|
2021-07-05 21:23:13 +08:00
|
|
|
#[pb(index = 1)]
|
2021-09-02 14:47:39 +08:00
|
|
|
pub user_id: String,
|
2021-07-05 21:23:13 +08:00
|
|
|
|
2021-08-20 11:52:45 +08:00
|
|
|
#[pb(index = 2)]
|
2021-08-20 14:38:03 +08:00
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
2021-08-20 11:52:45 +08:00
|
|
|
pub email: String,
|
2021-08-31 17:56:38 +08:00
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub token: String,
|
2021-07-05 21:23:13 +08:00
|
|
|
}
|