From 8c956b9a060f710e8d64f315b5613aa000f0382f Mon Sep 17 00:00:00 2001 From: Wang Zixiao Date: Mon, 27 May 2024 15:33:59 +0800 Subject: [PATCH] feat(ui): register with name (#2248) * feat(ui): register with name * fix test * name required in registration * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- ee/tabby-schema/graphql/schema.graphql | 2 +- ee/tabby-schema/src/schema/auth.rs | 1 + ee/tabby-schema/src/schema/mod.rs | 3 +- .../signup/components/user-register-form.tsx | 16 ++++++++++ ee/tabby-webserver/src/service/auth.rs | 30 ++++++++++++++----- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index a5cb182c8e01..173494111a42 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -363,7 +363,7 @@ type Mutation { updateUserRole(id: ID!, isAdmin: Boolean!): Boolean! uploadUserAvatarBase64(id: ID!, avatarBase64: String): Boolean! updateUserName(id: ID!, name: String!): Boolean! - register(email: String!, password1: String!, password2: String!, invitationCode: String): RegisterResponse! + register(email: String!, password1: String!, password2: String!, invitationCode: String, name: String!): RegisterResponse! tokenAuth(email: String!, password: String!): TokenAuthResponse! verifyToken(token: String!): Boolean! refreshToken(refreshToken: String!): RefreshTokenResponse! diff --git a/ee/tabby-schema/src/schema/auth.rs b/ee/tabby-schema/src/schema/auth.rs index 9d8f85fb4a5f..e0befb1ef13d 100644 --- a/ee/tabby-schema/src/schema/auth.rs +++ b/ee/tabby-schema/src/schema/auth.rs @@ -363,6 +363,7 @@ pub trait AuthenticationService: Send + Sync { email: String, password1: String, invitation_code: Option, + name: Option, ) -> Result; async fn allow_self_signup(&self) -> Result; diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index 313fd5d2fb34..da3f2b6defc6 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -834,6 +834,7 @@ impl Mutation { password1: String, password2: String, invitation_code: Option, + name: String, ) -> Result { let input = auth::RegisterInput { email, @@ -844,7 +845,7 @@ impl Mutation { ctx.locator .auth() - .register(input.email, input.password1, invitation_code) + .register(input.email, input.password1, invitation_code, Some(name)) .await } diff --git a/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx b/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx index 3640a0b90cc9..dbb8a47fd6a2 100644 --- a/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx +++ b/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx @@ -30,12 +30,14 @@ import { export const registerUser = graphql(/* GraphQL */ ` mutation register( + $name: String! $email: String! $password1: String! $password2: String! $invitationCode: String ) { register( + name: $name email: $email password1: $password1 password2: $password2 @@ -48,6 +50,7 @@ export const registerUser = graphql(/* GraphQL */ ` `) const formSchema = z.object({ + name: z.string(), email: z.string().email('Invalid email address'), password1: z.string(), password2: z.string(), @@ -104,6 +107,19 @@ export function UserAuthForm({
+ ( + + Name + + + + + + )} + /> , + name: Option, ) -> Result { let is_admin_initialized = self.is_admin_initialized().await?; if is_admin_initialized && is_demo_mode() { @@ -85,12 +86,17 @@ impl AuthenticationService for AuthenticationServiceImpl { Some(pwd_hash), !is_admin_initialized, invitation.id, - None, + name.clone(), ) .await? } else { self.db - .create_user(email.clone(), Some(pwd_hash), !is_admin_initialized, None) + .create_user( + email.clone(), + Some(pwd_hash), + !is_admin_initialized, + name.clone(), + ) .await? }; @@ -736,7 +742,12 @@ mod tests { async fn register_admin_user(service: &AuthenticationServiceImpl) -> RegisterResponse { service - .register(ADMIN_EMAIL.to_owned(), ADMIN_PASSWORD.to_owned(), None) + .register( + ADMIN_EMAIL.to_owned(), + ADMIN_PASSWORD.to_owned(), + None, + None, + ) .await .unwrap() } @@ -791,7 +802,7 @@ mod tests { // Admin initialized, registeration requires a invitation code; assert_matches!( service - .register(email.to_owned(), password.to_owned(), None) + .register(email.to_owned(), password.to_owned(), None, None) .await, Err(_) ); @@ -802,7 +813,8 @@ mod tests { .register( email.to_owned(), password.to_owned(), - Some("abc".to_owned()) + Some("abc".to_owned()), + None ) .await, Err(_) @@ -814,6 +826,7 @@ mod tests { email.to_owned(), password.to_owned(), Some(invitation.code.clone()), + None ) .await .is_ok()); @@ -824,7 +837,8 @@ mod tests { .register( email.to_owned(), password.to_owned(), - Some(invitation.code.clone()) + Some(invitation.code.clone()), + None ) .await, Err(_) @@ -1017,7 +1031,7 @@ mod tests { .unwrap(); service - .register("test@example.com".into(), "".into(), Some(code.code)) + .register("test@example.com".into(), "".into(), Some(code.code), None) .await .unwrap(); @@ -1303,7 +1317,7 @@ mod tests { // Create owner user. service - .register("a@example.com".into(), "pass".into(), None) + .register("a@example.com".into(), "pass".into(), None, None) .await .unwrap();