Changeset View
Changeset View
Standalone View
Standalone View
services/identity/src/client_service.rs
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | async fn register_password_user_start( | ||||
request: tonic::Request<RegistrationStartRequest>, | request: tonic::Request<RegistrationStartRequest>, | ||||
) -> Result<tonic::Response<RegistrationStartResponse>, tonic::Status> { | ) -> Result<tonic::Response<RegistrationStartResponse>, tonic::Status> { | ||||
let message = request.into_inner(); | let message = request.into_inner(); | ||||
let username_taken = self | let username_taken = self | ||||
.client | .client | ||||
.username_taken(message.username.clone()) | .username_taken(message.username.clone()) | ||||
.await | .await | ||||
.map_err(handle_db_error)?; | .map_err(handle_db_error)?; | ||||
let username_in_reserved_usernames_table = self | |||||
.client | |||||
.username_in_reserved_usernames_table(&message.username) | |||||
.await | |||||
.map_err(handle_db_error)?; | |||||
if username_taken { | if username_taken || username_in_reserved_usernames_table { | ||||
return Err(tonic::Status::already_exists("username already exists")); | return Err(tonic::Status::already_exists("username already exists")); | ||||
} | } | ||||
if CONFIG.reserved_usernames.contains(&message.username) { | if CONFIG.reserved_usernames.contains(&message.username) { | ||||
return Err(tonic::Status::invalid_argument("username reserved")); | return Err(tonic::Status::invalid_argument("username reserved")); | ||||
} | } | ||||
if let client_proto::RegistrationStartRequest { | if let client_proto::RegistrationStartRequest { | ||||
▲ Show 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | impl IdentityClientService for ClientService { | ||||
} | } | ||||
async fn login_password_user_start( | async fn login_password_user_start( | ||||
&self, | &self, | ||||
request: tonic::Request<OpaqueLoginStartRequest>, | request: tonic::Request<OpaqueLoginStartRequest>, | ||||
) -> Result<tonic::Response<OpaqueLoginStartResponse>, tonic::Status> { | ) -> Result<tonic::Response<OpaqueLoginStartResponse>, tonic::Status> { | ||||
let message = request.into_inner(); | let message = request.into_inner(); | ||||
let (user_id, password_file_bytes) = self | let user_id_and_password_file = self | ||||
.client | .client | ||||
.get_user_id_and_password_file_from_username(&message.username) | .get_user_id_and_password_file_from_username(&message.username) | ||||
.await | .await | ||||
.map_err(handle_db_error)? | .map_err(handle_db_error)?; | ||||
.ok_or(tonic::Status::not_found("user not found"))?; | |||||
let (user_id, password_file_bytes) = | |||||
if let Some(data) = user_id_and_password_file { | |||||
data | |||||
} else { | |||||
// It's possible that the user attempting login is already registered | |||||
// on Ashoat's keyserver. If they are, we should send back a gRPC status | |||||
// code instructing them to get a signed message from Ashoat's keyserver | |||||
// in order to claim their username and register with the Identity | |||||
// service. | |||||
let username_in_reserved_usernames_table = self | |||||
.client | |||||
.username_in_reserved_usernames_table(&message.username) | |||||
.await | |||||
.map_err(handle_db_error)?; | |||||
if username_in_reserved_usernames_table { | |||||
return Err(tonic::Status::failed_precondition( | |||||
"need keyserver message to claim username", | |||||
)); | |||||
} | |||||
return Err(tonic::Status::not_found("user not found")); | |||||
}; | |||||
if let client_proto::OpaqueLoginStartRequest { | if let client_proto::OpaqueLoginStartRequest { | ||||
opaque_login_request: login_message, | opaque_login_request: login_message, | ||||
username, | username, | ||||
device_key_upload: | device_key_upload: | ||||
Some(client_proto::DeviceKeyUpload { | Some(client_proto::DeviceKeyUpload { | ||||
device_key_info: | device_key_info: | ||||
Some(client_proto::IdentityKeyInfo { | Some(client_proto::IdentityKeyInfo { | ||||
▲ Show 20 Lines • Show All 354 Lines • Show Last 20 Lines |