Changeset View
Changeset View
Standalone View
Standalone View
services/identity/src/client_service.rs
Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | ) -> Result<tonic::Response<RegistrationStartResponse>, tonic::Status> { | ||||
if username_in_reserved_usernames_table { | if username_in_reserved_usernames_table { | ||||
return Err(tonic::Status::already_exists("username already exists")); | return Err(tonic::Status::already_exists("username already exists")); | ||||
} | } | ||||
if RESERVED_USERNAME_SET.contains(&message.username) { | if RESERVED_USERNAME_SET.contains(&message.username) { | ||||
return Err(tonic::Status::invalid_argument("username reserved")); | return Err(tonic::Status::invalid_argument("username reserved")); | ||||
} | } | ||||
if let Some(fid) = &message.farcaster_id { | |||||
self.check_farcaster_id_taken(fid).await?; | |||||
} | |||||
let registration_state = construct_user_registration_info( | let registration_state = construct_user_registration_info( | ||||
&message, | &message, | ||||
None, | None, | ||||
message.username.clone(), | message.username.clone(), | ||||
message.farcaster_id.clone(), | message.farcaster_id.clone(), | ||||
)?; | )?; | ||||
let server_registration = comm_opaque2::server::Registration::new(); | let server_registration = comm_opaque2::server::Registration::new(); | ||||
let server_message = server_registration | let server_message = server_registration | ||||
▲ Show 20 Lines • Show All 398 Lines • ▼ Show 20 Lines | let username_in_reserved_usernames_table = self | ||||
.map_err(handle_db_error)?; | .map_err(handle_db_error)?; | ||||
if username_in_reserved_usernames_table { | if username_in_reserved_usernames_table { | ||||
return Err(tonic::Status::already_exists( | return Err(tonic::Status::already_exists( | ||||
"wallet address already exists", | "wallet address already exists", | ||||
)); | )); | ||||
} | } | ||||
if let Some(fid) = &message.farcaster_id { | |||||
self.check_farcaster_id_taken(fid).await?; | |||||
} | |||||
let flattened_device_key_upload = | let flattened_device_key_upload = | ||||
construct_flattened_device_key_upload(&message)?; | construct_flattened_device_key_upload(&message)?; | ||||
let login_time = chrono::Utc::now(); | let login_time = chrono::Utc::now(); | ||||
let social_proof = | let social_proof = | ||||
SocialProof::new(message.siwe_message, message.siwe_signature); | SocialProof::new(message.siwe_message, message.siwe_signature); | ||||
let serialized_social_proof = serde_json::to_string(&social_proof) | let serialized_social_proof = serde_json::to_string(&social_proof) | ||||
▲ Show 20 Lines • Show All 370 Lines • ▼ Show 20 Lines | ) -> Result<(), tonic::Status> { | ||||
if wallet_address_taken { | if wallet_address_taken { | ||||
return Err(tonic::Status::already_exists( | return Err(tonic::Status::already_exists( | ||||
"wallet address already exists", | "wallet address already exists", | ||||
)); | )); | ||||
} | } | ||||
Ok(()) | Ok(()) | ||||
} | } | ||||
async fn check_farcaster_id_taken( | |||||
&self, | |||||
farcaster_id: &str, | |||||
) -> Result<(), tonic::Status> { | |||||
let fid_already_registered = !self | |||||
.client | |||||
.get_farcaster_users(vec![farcaster_id.to_string()]) | |||||
.await | |||||
.map_err(handle_db_error)? | |||||
.is_empty(); | |||||
if fid_already_registered { | |||||
return Err(tonic::Status::already_exists( | |||||
"farcaster ID already associated with different user", | |||||
)); | |||||
} | |||||
Ok(()) | |||||
} | |||||
async fn verify_and_remove_nonce( | async fn verify_and_remove_nonce( | ||||
&self, | &self, | ||||
nonce: &str, | nonce: &str, | ||||
) -> Result<(), tonic::Status> { | ) -> Result<(), tonic::Status> { | ||||
match self | match self | ||||
.client | .client | ||||
.get_nonce_from_nonces_table(nonce) | .get_nonce_from_nonces_table(nonce) | ||||
.await | .await | ||||
▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines |