diff --git a/Cargo.toml b/Cargo.toml index 51bf07b..be465e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,15 +11,15 @@ path = "./src/main.rs" [dependencies] +base64 = { version = "0" } futures = { version = "0", default-features = false, features = [ "async-await", ] } -tokio = { version = "1", features = ["macros", "rt-multi-thread"] } -prost = { version = "0" } nats = { version = "0" } -base64 = { version = "0" } +prost = { version = "0" } +tokio = { version = "1", features = ["macros", "rt-multi-thread"] } -beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.74-snapshot" } -beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.58-snapshot" } +beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.77-snapshot" } +beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.62-snapshot" } [build-dependencies] diff --git a/resources/public.pem b/resources/public.pem new file mode 100644 index 0000000..a54921a --- /dev/null +++ b/resources/public.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw/GvSFLy8K5uT79REy5l +JtIS+Y9uAP1SJEyLvAqWfdPh9YO5QCnYPp1uCqL3xWozkhrQWUbaYkO+65vjmYcG +BMlzO+7KvZcHh4wr8ybA03M6Yy6JSbnXRQvVm2Bvp2Z1B0dkT11CtZxiaNywYFvM +hh5+zEbsrbFkzN5zI+hNpyg4uaaQY5Oy2jGW3zuOIy/i0qzs3pCHWDAk0d5hpGvf +lUIj7BOQtl7CcFoB8tMp6F2fi8t9m/Qa0yvQz8CNf7pdDqprUlm509wKzB4HgX8a +G5SMwMlfuQjvT3jQNLRnHJFDghdZuCaop8IKf4PVGjuLo0SEebYzVEYfzLQrHemo +RwIDAQAB +-----END PUBLIC KEY----- \ No newline at end of file diff --git a/src/member/service.rs b/src/member/service.rs index e537a2d..d7c27a5 100644 --- a/src/member/service.rs +++ b/src/member/service.rs @@ -70,6 +70,57 @@ impl Service { } } + async fn get_member_session_with_renewal( + &self, + client: &bpr::models::core::network::Client, + ) -> Result, bcr::error::rpc::Error> { + let ss_get_member_session_req = bpr::ss::member_session::GetMemberSessionWithRenewalRequest { + client: Some(client.clone()), + request: Some(bpr::ss::member_session::get_member_session_with_renewal_request::Request {}), + }; + + let ss_get_member_session_res_msg = self + .connection_broker + .request( + bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION_WITH_RENEWAL, + ss_get_member_session_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_get_member_session_res = + bpr::ss::member_session::GetMemberSessionWithRenewalResponse::decode( + ss_get_member_session_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_get_member_session_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_get_member_session_res.result { + return Ok(r.member_session); + } + + Ok(None) + } + async fn create_member(&self) -> Result<(), Box> { let s = self .connection_broker @@ -439,6 +490,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member::UpdateMemberRequest::decode(message.data.as_slice()).map_err(|e| { @@ -507,7 +568,7 @@ impl Service { let ss_update_member_req = bpr::ss::member::UpdateMemberRequest { client: Some(client), request: Some(bpr::ss::member::update_member_request::Request { - id: req.id, + id: member_session.member_id.clone(), site_id: req.site_id, member_level_id: req.member_level_id, mobile_phone_number: req.mobile_phone_number, @@ -602,6 +663,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member::UpdateMemberForPasswordRequest::decode(message.data.as_slice()) @@ -615,7 +686,7 @@ impl Service { client: Some(client), request: Some( bpr::ss::member::update_member_for_password_request::Request { - id: req.id, + id: member_session.member_id.clone(), password: req.password, }, ), @@ -705,6 +776,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member::DeleteMemberRequest::decode(message.data.as_slice()).map_err(|e| { @@ -715,7 +796,9 @@ impl Service { let ss_delete_member_req = bpr::ss::member::DeleteMemberRequest { client: Some(client), - request: Some(bpr::ss::member::delete_member_request::Request { id: req.id }), + request: Some(bpr::ss::member::delete_member_request::Request { + id: member_session.member_id.clone(), + }), }; let ss_delete_member_res_msg = self diff --git a/src/member_bank_account/service.rs b/src/member_bank_account/service.rs index f5e72ed..7c56463 100644 --- a/src/member_bank_account/service.rs +++ b/src/member_bank_account/service.rs @@ -68,6 +68,57 @@ impl Service { } } + async fn get_member_session_with_renewal( + &self, + client: &bpr::models::core::network::Client, + ) -> Result, bcr::error::rpc::Error> { + let ss_get_member_session_req = bpr::ss::member_session::GetMemberSessionWithRenewalRequest { + client: Some(client.clone()), + request: Some(bpr::ss::member_session::get_member_session_with_renewal_request::Request {}), + }; + + let ss_get_member_session_res_msg = self + .connection_broker + .request( + bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION_WITH_RENEWAL, + ss_get_member_session_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_get_member_session_res = + bpr::ss::member_session::GetMemberSessionWithRenewalResponse::decode( + ss_get_member_session_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_get_member_session_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_get_member_session_res.result { + return Ok(r.member_session); + } + + Ok(None) + } + async fn create_member_bank_account(&self) -> Result<(), Box> { let s = self .connection_broker diff --git a/src/member_bank_deposit/service.rs b/src/member_bank_deposit/service.rs index 3b127f8..0fc48d4 100644 --- a/src/member_bank_deposit/service.rs +++ b/src/member_bank_deposit/service.rs @@ -69,6 +69,57 @@ impl Service { } } + async fn get_member_session_with_renewal( + &self, + client: &bpr::models::core::network::Client, + ) -> Result, bcr::error::rpc::Error> { + let ss_get_member_session_req = bpr::ss::member_session::GetMemberSessionWithRenewalRequest { + client: Some(client.clone()), + request: Some(bpr::ss::member_session::get_member_session_with_renewal_request::Request {}), + }; + + let ss_get_member_session_res_msg = self + .connection_broker + .request( + bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION_WITH_RENEWAL, + ss_get_member_session_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_get_member_session_res = + bpr::ss::member_session::GetMemberSessionWithRenewalResponse::decode( + ss_get_member_session_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_get_member_session_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_get_member_session_res.result { + return Ok(r.member_session); + } + + Ok(None) + } + async fn create_member_bank_deposit(&self) -> Result<(), Box> { let s = self .connection_broker @@ -82,6 +133,17 @@ impl Service { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; + let req = bpr::c2se::member_bank_deposit::CreateMemberBankDepositRequest::decode( message.data.as_slice(), ) @@ -96,7 +158,7 @@ impl Service { client: Some(client), request: Some( bpr::ss::member_bank_deposit::create_member_bank_deposit_request::Request { - member_id: "".to_string(), + member_id: member_session.member_id.clone(), name: req.name, amount: req.amount, memo: req.memo, @@ -193,6 +255,17 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_deposit::ListMemberBankDepositsRequest::decode(message.data.as_slice()) .map_err(|e| { @@ -206,18 +279,17 @@ impl Service { request: Some(bpr::ss::member_bank_deposit::list_member_bank_deposits_request::Request { pagination: req.pagination, sorts: req.sorts, - search: match req.search { - Some(s) => Some(bpr::ss::member_bank_deposit::list_member_bank_deposits_request::request::Search { - member_id: s.member_id, - name_like: s.name_like, - amount: s.amount, - state: s.state, - memo_like: s.memo_like, - }), - None => None, - } + search: match req.search { + Some(s) => Some(bpr::ss::member_bank_deposit::list_member_bank_deposits_request::request::Search { + member_id: Some(member_session.member_id.clone()), + name_like: s.name_like, + amount: s.amount, + state: s.state, + memo_like: s.memo_like, + }), + None => None, + } }) - }; let ss_list_member_bank_deposits_res_msg = self @@ -305,6 +377,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_deposit::GetMemberBankDepositRequest::decode( message.data.as_slice(), @@ -412,6 +494,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_deposit::UpdateMemberBankDepositRequest::decode( message.data.as_slice(), @@ -524,7 +616,17 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; - + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; + let req = bpr::c2se::member_bank_deposit::DeleteMemberBankDepositRequest::decode( message.data.as_slice(), ) diff --git a/src/member_bank_withdraw/service.rs b/src/member_bank_withdraw/service.rs index 7e0dd3d..908531a 100644 --- a/src/member_bank_withdraw/service.rs +++ b/src/member_bank_withdraw/service.rs @@ -69,6 +69,57 @@ impl Service { } } + async fn get_member_session_with_renewal( + &self, + client: &bpr::models::core::network::Client, + ) -> Result, bcr::error::rpc::Error> { + let ss_get_member_session_req = bpr::ss::member_session::GetMemberSessionWithRenewalRequest { + client: Some(client.clone()), + request: Some(bpr::ss::member_session::get_member_session_with_renewal_request::Request {}), + }; + + let ss_get_member_session_res_msg = self + .connection_broker + .request( + bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION_WITH_RENEWAL, + ss_get_member_session_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_get_member_session_res = + bpr::ss::member_session::GetMemberSessionWithRenewalResponse::decode( + ss_get_member_session_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_get_member_session_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_get_member_session_res.result { + return Ok(r.member_session); + } + + Ok(None) + } + async fn create_member_bank_withdraw(&self) -> Result<(), Box> { let s = self .connection_broker @@ -81,6 +132,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_withdraw::CreateMemberBankWithdrawRequest::decode( message.data.as_slice(), @@ -96,7 +157,7 @@ impl Service { client: Some(client), request: Some( bpr::ss::member_bank_withdraw::create_member_bank_withdraw_request::Request { - member_id: "".to_string(), + member_id: member_session.member_id.clone(), bank_name: req.bank_name, account_number: req.account_number, amount: req.amount, @@ -196,6 +257,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_withdraw::ListMemberBankWithdrawsRequest::decode(message.data.as_slice()) .map_err(|e| { @@ -209,18 +280,18 @@ impl Service { request: Some(bpr::ss::member_bank_withdraw::list_member_bank_withdraws_request::Request{ pagination: req.pagination, sorts: req.sorts, - search: match req.search { - Some(s) => Some(bpr::ss::member_bank_withdraw::list_member_bank_withdraws_request::request::Search { - name_like: s.name_like, - member_id: s.member_id, - bank_name_like: s.bank_name_like, - account_number_like: s.account_number_like, - amount: s.amount, - state: s.state, + search: match req.search { + Some(s) => Some(bpr::ss::member_bank_withdraw::list_member_bank_withdraws_request::request::Search { + name_like: s.name_like, + member_id: Some(member_session.member_id.clone()), + bank_name_like: s.bank_name_like, + account_number_like: s.account_number_like, + amount: s.amount, + state: s.state, memo_like: s.memo_like, - }), - None => None, - } + }), + None => None, + } }) }; @@ -310,6 +381,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_withdraw::GetMemberBankWithdrawRequest::decode(message.data.as_slice()) .map_err(|e| { @@ -408,6 +489,16 @@ impl Service { while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_withdraw::UpdateMemberBankWithdrawRequest::decode(message.data.as_slice()) .map_err(|e| { @@ -515,6 +606,16 @@ password: req.password, while let Some(message) = s.next().await { if let Err(e) = async { let client = self.get_client_in_header(&message)?; + let member_session = match self.get_member_session_with_renewal(&client).await? { + Some(ms) => ms, + None => { + return Err(bcr::error::rpc::Error::InvalidRequest( + bcr::error::rpc::InvalidRequest { + message: "Unauthorized".to_string(), + }, + )); + } + }; let req = bpr::c2se::member_bank_withdraw::DeleteMemberBankWithdrawRequest::decode(message.data.as_slice()) .map_err(|e| { diff --git a/src/member_referrer/service.rs b/src/member_referrer/service.rs index 961363d..f2d8166 100644 --- a/src/member_referrer/service.rs +++ b/src/member_referrer/service.rs @@ -62,6 +62,57 @@ impl Service { } } + async fn get_member_session_with_renewal( + &self, + client: &bpr::models::core::network::Client, + ) -> Result, bcr::error::rpc::Error> { + let ss_get_member_session_req = bpr::ss::member_session::GetMemberSessionWithRenewalRequest { + client: Some(client.clone()), + request: Some(bpr::ss::member_session::get_member_session_with_renewal_request::Request {}), + }; + + let ss_get_member_session_res_msg = self + .connection_broker + .request( + bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION_WITH_RENEWAL, + ss_get_member_session_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_get_member_session_res = + bpr::ss::member_session::GetMemberSessionWithRenewalResponse::decode( + ss_get_member_session_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_get_member_session_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_get_member_session_res.result { + return Ok(r.member_session); + } + + Ok(None) + } + async fn get_member_referrer_by_code(&self) -> Result<(), Box> { let s = self .connection_broker