use std::sync::Arc; use nanoid::nanoid; use flowy_user::entities::{AuthTypePB, SignUpPayloadPB, UserProfilePB}; use flowy_user::errors::FlowyError; use flowy_user::event_map::UserEvent::*; use lib_dispatch::prelude::{AFPluginDispatcher, AFPluginRequest, ToBytes}; pub fn random_email() -> String { format!("{}@appflowy.io", nanoid!(20)) } pub fn login_email() -> String { "annie2@appflowy.io".to_string() } pub fn login_password() -> String { "HelloWorld!123".to_string() } pub struct SignUpContext { pub user_profile: UserProfilePB, pub password: String, } pub fn sign_up(dispatch: Arc) -> SignUpContext { let password = login_password(); let payload = SignUpPayloadPB { email: random_email(), name: "app flowy".to_string(), password: password.clone(), auth_type: AuthTypePB::Local, } .into_bytes() .unwrap(); let request = AFPluginRequest::new(SignUp).payload(payload); let user_profile = AFPluginDispatcher::sync_send(dispatch, request) .parse::() .unwrap() .unwrap(); SignUpContext { user_profile, password, } } pub async fn async_sign_up( dispatch: Arc, auth_type: AuthTypePB, ) -> SignUpContext { let password = login_password(); let email = random_email(); let payload = SignUpPayloadPB { email, name: "app flowy".to_string(), password: password.clone(), auth_type, } .into_bytes() .unwrap(); let request = AFPluginRequest::new(SignUp).payload(payload); let user_profile = AFPluginDispatcher::async_send(dispatch.clone(), request) .await .parse::() .unwrap() .unwrap(); // let _ = create_default_workspace_if_need(dispatch.clone(), &user_profile.id); SignUpContext { user_profile, password, } } pub async fn init_user_setting(dispatch: Arc) { let request = AFPluginRequest::new(InitUser); let _ = AFPluginDispatcher::async_send(dispatch.clone(), request).await; }