From 9464f6d8a6cc25e8aeef6923c8f24443ef7bc9ec Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Sat, 20 Aug 2022 13:06:04 +0000 Subject: [PATCH] signinWithoutSecurityCode is added --- src/identity/service.rs | 110 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/src/identity/service.rs b/src/identity/service.rs index 6f22cc0..73f79f6 100644 --- a/src/identity/service.rs +++ b/src/identity/service.rs @@ -30,6 +30,7 @@ impl Service { self.check_nickname_for_duplication(), self.captcha(), self.signin(), + self.signin_without_security_code(), ) .map(|_| ()) } @@ -487,4 +488,113 @@ impl Service { Ok(()) } + + async fn signin_without_security_code(&self) -> Result<(), Box> { + let s = self + .connection_broker + .queue_subscribe( + bpr::c2se::frontend::identity::SUBJECT_SIGNIN_WITHOUT_SECURITY_CODE, + self.queue_broker.as_str(), + ) + .await?; + + while let Some(message) = s.next().await { + if let Err(e) = async { + let client = self.get_client_in_header(&message)?; + + let req = + bpr::c2se::identity::SigninWithoutSecurityCodeRequest::decode(message.data.as_slice()) + .map_err(|e| { + bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest { + message: format!("invalid request: {}", e), + }) + })?; + + let ss_signin_without_security_code_req = + bpr::ss::identity::SigninWithoutSecurityCodeRequest { + client: Some(client), + request: Some( + bpr::ss::identity::signin_without_security_code_request::Request { + username: req.username, + password: req.password, + }, + ), + }; + + let ss_signin_without_security_code_res_msg = self + .connection_broker + .request( + bpr::ss::identity::SUBJECT_SIGNIN_WITHOUT_SECURITY_CODE, + ss_signin_without_security_code_req.encode_to_vec(), + ) + .await + .map_err(|e| { + bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + }) + })?; + + let ss_signin_without_security_code_res = + bpr::ss::identity::SigninWithoutSecurityCodeResponse::decode( + ss_signin_without_security_code_res_msg.data.as_slice(), + ) + .map_err(|e| { + bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + }) + })?; + + if let Some(e) = ss_signin_without_security_code_res.error { + return Err(bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + })); + } + + if let Some(r) = ss_signin_without_security_code_res.result { + message + .respond( + bpr::c2se::identity::SigninWithoutSecurityCodeResponse { + error: None, + result: Some( + bpr::c2se::identity::signin_without_security_code_response::Result { + access_token: r.access_token, + }, + ), + } + .encode_to_vec(), + ) + .await + .map_err(|e| { + bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + }) + })?; + } + + Ok::<(), bcr::error::rpc::Error>(()) + } + .await + { + message + .respond( + bpr::c2se::identity::SigninWithoutSecurityCodeResponse { + error: Some(bpr::protobuf::rpc::Error::from(e)), + result: None, + } + .encode_to_vec(), + ) + .await?; + } + } + + Ok(()) + } }