mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
d842f228e8
* feat: integrate supabase auth service * chore: ignore the sercet * feat: separate and inject the auth service * chore: integrate auth service into sign in/up page * feat: integrate github and google sign in * chore: update user trait * feat: box any params in UserCloudService trait * feat: add flowy-server crate * refactor: user trait * docs: doc ThirdPartyAuthPB * feat: server provider * feat: pass the uuid to rust side * feat: pass supabase config to rust side * feat: integrate env file * feat: implement login as guest * feat: impl postgrest * test: use env * chore: upper case key * feat: optimize the file storage * fix: don't call set auth when user login in local * docs: add docs * feat: create/update/get user using postgrest * feat: optimize the login as guest * feat: create user workspace * feat: create user default workspace * feat: redesign the setting path location page * feat: use uuid as view id * feat: send auth info to rust backend * fix: sign up * fix: skip to wrong page after login * fix: integrate test error * fix: indent command error * feat: add discord login in type * fix: flutter analyze * ci: fix rust tests * ci: fix tauri build * ci: fix tauri build --------- Co-authored-by: nathan <nathan@appflowy.io>
153 lines
3.2 KiB
Rust
153 lines
3.2 KiB
Rust
use std::convert::TryInto;
|
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
use crate::entities::parser::{UserEmail, UserIcon, UserName, UserOpenaiKey, UserPassword};
|
|
use crate::entities::{AuthTypePB, UpdateUserProfileParams, UserProfile};
|
|
use crate::errors::ErrorCode;
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
pub struct UserTokenPB {
|
|
#[pb(index = 1)]
|
|
pub token: String,
|
|
}
|
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
pub struct UserSettingPB {
|
|
#[pb(index = 1)]
|
|
pub(crate) user_folder: String,
|
|
}
|
|
|
|
#[derive(ProtoBuf, Default, Debug, PartialEq, Eq, Clone)]
|
|
pub struct UserProfilePB {
|
|
#[pb(index = 1)]
|
|
pub id: i64,
|
|
|
|
#[pb(index = 2)]
|
|
pub email: String,
|
|
|
|
#[pb(index = 3)]
|
|
pub name: String,
|
|
|
|
#[pb(index = 4)]
|
|
pub token: String,
|
|
|
|
#[pb(index = 5)]
|
|
pub icon_url: String,
|
|
|
|
#[pb(index = 6)]
|
|
pub openai_key: String,
|
|
}
|
|
|
|
impl std::convert::From<UserProfile> for UserProfilePB {
|
|
fn from(user_profile: UserProfile) -> Self {
|
|
Self {
|
|
id: user_profile.id,
|
|
email: user_profile.email,
|
|
name: user_profile.name,
|
|
token: user_profile.token,
|
|
icon_url: user_profile.icon_url,
|
|
openai_key: user_profile.openai_key,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
pub struct UpdateUserProfilePayloadPB {
|
|
#[pb(index = 1)]
|
|
pub id: i64,
|
|
|
|
#[pb(index = 2, one_of)]
|
|
pub name: Option<String>,
|
|
|
|
#[pb(index = 3, one_of)]
|
|
pub email: Option<String>,
|
|
|
|
#[pb(index = 4, one_of)]
|
|
pub password: Option<String>,
|
|
|
|
#[pb(index = 5, one_of)]
|
|
pub icon_url: Option<String>,
|
|
|
|
#[pb(index = 6, one_of)]
|
|
pub openai_key: Option<String>,
|
|
|
|
#[pb(index = 7)]
|
|
pub auth_type: AuthTypePB,
|
|
}
|
|
|
|
impl UpdateUserProfilePayloadPB {
|
|
pub fn new(id: i64) -> Self {
|
|
Self {
|
|
id,
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
pub fn name(mut self, name: &str) -> Self {
|
|
self.name = Some(name.to_owned());
|
|
self
|
|
}
|
|
|
|
pub fn email(mut self, email: &str) -> Self {
|
|
self.email = Some(email.to_owned());
|
|
self
|
|
}
|
|
|
|
pub fn password(mut self, password: &str) -> Self {
|
|
self.password = Some(password.to_owned());
|
|
self
|
|
}
|
|
|
|
pub fn icon_url(mut self, icon_url: &str) -> Self {
|
|
self.icon_url = Some(icon_url.to_owned());
|
|
self
|
|
}
|
|
|
|
pub fn openai_key(mut self, openai_key: &str) -> Self {
|
|
self.openai_key = Some(openai_key.to_owned());
|
|
self
|
|
}
|
|
}
|
|
|
|
impl TryInto<UpdateUserProfileParams> for UpdateUserProfilePayloadPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<UpdateUserProfileParams, Self::Error> {
|
|
let name = match self.name {
|
|
None => None,
|
|
Some(name) => Some(UserName::parse(name)?.0),
|
|
};
|
|
|
|
let email = match self.email {
|
|
None => None,
|
|
Some(email) => Some(UserEmail::parse(email)?.0),
|
|
};
|
|
|
|
let password = match self.password {
|
|
None => None,
|
|
Some(password) => Some(UserPassword::parse(password)?.0),
|
|
};
|
|
|
|
let icon_url = match self.icon_url {
|
|
None => None,
|
|
Some(icon_url) => Some(UserIcon::parse(icon_url)?.0),
|
|
};
|
|
|
|
let openai_key = match self.openai_key {
|
|
None => None,
|
|
Some(openai_key) => Some(UserOpenaiKey::parse(openai_key)?.0),
|
|
};
|
|
|
|
Ok(UpdateUserProfileParams {
|
|
id: self.id,
|
|
auth_type: self.auth_type.into(),
|
|
name,
|
|
email,
|
|
password,
|
|
icon_url,
|
|
openai_key,
|
|
})
|
|
}
|
|
}
|