refactoring
This commit is contained in:
parent
63b98eceac
commit
6263a3d557
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -25,7 +25,6 @@
|
|||
"QUEUE_BROKER": "bet.beteran",
|
||||
"CAPTCHA_SALT": "!#%&(24680qetuWRYI",
|
||||
"PASSWORD_SALT": "@$^*)13579wryipQETUO",
|
||||
"JWT_SECRET": "!@$^*)13579wryipQETUO!",
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
|
@ -52,7 +51,6 @@
|
|||
"QUEUE_BROKER": "bet.beteran",
|
||||
"CAPTCHA_SALT": "!#%&(24680qetuWRYI",
|
||||
"PASSWORD_SALT": "@$^*)13579wryipQETUO",
|
||||
"JWT_SECRET": "!@$^*)13579wryipQETUO!",
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
|
|
|
@ -27,7 +27,6 @@ diesel-derive-enum = { version = "1", features = ["postgres"] }
|
|||
futures = { version = "0", default-features = false, features = [
|
||||
"async-await",
|
||||
] }
|
||||
jsonwebtoken = { version = "8" }
|
||||
nats = { version = "0" }
|
||||
prost = { version = "0" }
|
||||
rust-argon2 = { version = "1" }
|
||||
|
@ -38,7 +37,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
|||
tokio-cron-scheduler = { version = "0" }
|
||||
uuid = { version = "0", features = ["serde", "v4", "v5"] }
|
||||
|
||||
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]
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
use super::models;
|
||||
use crate::repositories;
|
||||
use time::{Duration, OffsetDateTime};
|
||||
|
||||
pub struct Composition {
|
||||
jwt_secret: String,
|
||||
site_repository: repositories::site::repository::Repository,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Composition {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Composition of members").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Composition {
|
||||
///
|
||||
pub fn new(jwt_secret: String) -> Composition {
|
||||
Composition {
|
||||
jwt_secret,
|
||||
site_repository: repositories::site::repository::Repository::new(),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn get_token(
|
||||
&self,
|
||||
issuer: String,
|
||||
session_id: String,
|
||||
) -> Result<String, jsonwebtoken::errors::Error> {
|
||||
use jsonwebtoken::{encode, Algorithm, EncodingKey, Header};
|
||||
|
||||
let header = Header::new(Algorithm::HS512);
|
||||
|
||||
let issued_at = OffsetDateTime::now_utc();
|
||||
let expiration_at = issued_at + Duration::days(1);
|
||||
let claims = models::Claims {
|
||||
iss: issuer,
|
||||
iat: issued_at.unix_timestamp(),
|
||||
exp: expiration_at.unix_timestamp(),
|
||||
session_id,
|
||||
};
|
||||
|
||||
let token = encode(
|
||||
&header,
|
||||
&claims,
|
||||
&EncodingKey::from_secret(self.jwt_secret.as_bytes()),
|
||||
)?;
|
||||
|
||||
Ok(token)
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod composition;
|
||||
///
|
||||
pub mod models;
|
|
@ -1,19 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// #[derive(Debug, Serialize, Deserialize)]
|
||||
// struct Claims {
|
||||
// aud: String, // Optional. Audience
|
||||
// exp: usize, // Required (validate_exp defaults to true in validation). Expiration time (as UTC timestamp)
|
||||
// iat: usize, // Optional. Issued at (as UTC timestamp)
|
||||
// iss: String, // Optional. Issuer
|
||||
// nbf: usize, // Optional. Not Before (as UTC timestamp)
|
||||
// sub: String, // Optional. Subject (whom token refers to)
|
||||
// }
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Claims {
|
||||
pub iss: String,
|
||||
pub iat: i64,
|
||||
pub exp: i64,
|
||||
pub session_id: String,
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
pub mod identity;
|
||||
pub mod member;
|
||||
pub mod member_referrer;
|
||||
pub mod site;
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -43,10 +43,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
Some(v) => v.into_string().unwrap(),
|
||||
None => "".to_string(),
|
||||
};
|
||||
let jwt_secret = match env::var_os("JWT_SECRET") {
|
||||
Some(v) => v.into_string().unwrap(),
|
||||
None => "".to_string(),
|
||||
};
|
||||
|
||||
let manager = ConnectionManager::<PgConnection>::new(url_db);
|
||||
let pool = Pool::builder()
|
||||
|
@ -71,7 +67,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
pool.clone(),
|
||||
captcha_salt.clone(),
|
||||
password_salt.clone(),
|
||||
jwt_secret.clone(),
|
||||
);
|
||||
let member_service = services::member::service::Service::new(
|
||||
connection_server_broker.clone(),
|
||||
|
@ -115,6 +110,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
queue_server_broker.clone(),
|
||||
pool.clone(),
|
||||
);
|
||||
let member_session_service = services::member_session::service::Service::new(
|
||||
connection_server_broker.clone(),
|
||||
queue_server_broker.clone(),
|
||||
pool.clone(),
|
||||
);
|
||||
let member_settlement_setting_service =
|
||||
services::member_settlement_setting::service::Service::new(
|
||||
connection_server_broker.clone(),
|
||||
|
@ -145,6 +145,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
member_class_service.subscribe(),
|
||||
member_game_setting_service.subscribe(),
|
||||
member_level_service.subscribe(),
|
||||
member_session_service.subscribe(),
|
||||
member_referrer_service.subscribe(),
|
||||
member_settlement_setting_service.subscribe(),
|
||||
site_service.subscribe(),
|
||||
|
|
|
@ -72,7 +72,7 @@ pub struct FindAllSearch {
|
|||
pub struct FindAll {
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(banks::name.asc());
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(banks::name.desc());
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"username" => {
|
||||
q = q.order_by(dsl::username.asc());
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"username" => {
|
||||
q = q.order_by(dsl::username.desc());
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_accounts::name.asc());
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_accounts::name.desc());
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_deposits::name.asc());
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_bank_deposits::name.desc());
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_bank_withdraws::member_id.asc());
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_bank_withdraws::member_id.desc());
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_classes::name.asc());
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl Repository {
|
|||
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_classes::name.desc());
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"created_at" => {
|
||||
q = q.order_by(member_game_settings::created_at.asc());
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"created_at" => {
|
||||
q = q.order_by(member_game_settings::created_at.desc());
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_levels::name.asc());
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(member_levels::name.desc());
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"role_resource_action_id" => {
|
||||
q = q.order_by(member_permissions::role_resource_action_id.asc());
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"role_resource_action_id" => {
|
||||
q = q.order_by(member_permissions::role_resource_action_id.desc());
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_referrers::member_id.asc());
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_referrers::member_id.desc());
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"role_id" => {
|
||||
q = q.order_by(member_roles::role_id.asc());
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"role_id" => {
|
||||
q = q.order_by(member_roles::role_id.desc());
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_sessions::member_id.asc());
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"member_id" => {
|
||||
q = q.order_by(member_sessions::member_id.desc());
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"rate_casino" => {
|
||||
q = q.order_by(member_settlement_settings::rate_casino.asc());
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"rate_casino" => {
|
||||
q = q.order_by(member_settlement_settings::rate_casino.desc());
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(resources::name.asc());
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(resources::name.desc());
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(resource_actions::name.asc());
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(resource_actions::name.desc());
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(roles::name.asc());
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"name" => {
|
||||
q = q.order_by(roles::name.desc());
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"role_id" => {
|
||||
q = q.order_by(role_resource_actions::role_id.asc());
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"role_id" => {
|
||||
q = q.order_by(role_resource_actions::role_id.desc());
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ pub struct FindAll {
|
|||
///
|
||||
pub search: Option<FindAllSearch>,
|
||||
///
|
||||
pub pagination: Option<bcr::models::pagination::Pagination>,
|
||||
pub pagination: Option<bcr::pagination::Pagination>,
|
||||
///
|
||||
pub sorts: Option<Vec<bcr::models::pagination::Sort>>,
|
||||
pub sorts: Option<Vec<bcr::pagination::Sort>>,
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ impl Repository {
|
|||
if let Some(orderbys) = &find_all.sorts {
|
||||
for s in orderbys {
|
||||
match s {
|
||||
bcr::models::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::ASC(property) => match property.as_str() {
|
||||
"url" => {
|
||||
q = q.order_by(sites::url.asc());
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ impl Repository {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
bcr::models::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
bcr::pagination::Sort::DESC(property) => match property.as_str() {
|
||||
"url" => {
|
||||
q = q.order_by(sites::url.desc());
|
||||
}
|
||||
|
|
|
@ -283,12 +283,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -20,7 +20,6 @@ pub struct Service<'a> {
|
|||
member_session_repository: repositories::member_session::repository::Repository,
|
||||
site_repository: repositories::site::repository::Repository,
|
||||
site_composition: compositions::site::composition::Composition,
|
||||
identity_composition: compositions::identity::composition::Composition,
|
||||
argon2_config: argon2::Config<'a>,
|
||||
captcha_salt: String,
|
||||
password_salt: String,
|
||||
|
@ -41,7 +40,6 @@ impl Service<'_> {
|
|||
pool: Pool<ConnectionManager<PgConnection>>,
|
||||
captcha_salt: String,
|
||||
password_salt: String,
|
||||
jwt_secret: String,
|
||||
) -> Service<'static> {
|
||||
Service {
|
||||
connection_broker,
|
||||
|
@ -51,7 +49,6 @@ impl Service<'_> {
|
|||
member_session_repository: repositories::member_session::repository::Repository::new(),
|
||||
site_repository: repositories::site::repository::Repository::new(),
|
||||
site_composition: compositions::site::composition::Composition::new(),
|
||||
identity_composition: compositions::identity::composition::Composition::new(jwt_secret),
|
||||
argon2_config: argon2::Config::default(),
|
||||
captcha_salt,
|
||||
password_salt,
|
||||
|
@ -612,10 +609,8 @@ impl Service<'_> {
|
|||
})
|
||||
})?;
|
||||
|
||||
let access_token = self
|
||||
.identity_composition
|
||||
.get_token("Beteran".to_string(), session.id.to_string())
|
||||
.map_err(|e| {
|
||||
let access_token =
|
||||
bcr::jwt::encode("Beteran", session.id.to_string().as_str()).map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
|
@ -818,10 +813,8 @@ impl Service<'_> {
|
|||
})
|
||||
})?;
|
||||
|
||||
let access_token = self
|
||||
.identity_composition
|
||||
.get_token("Beteran".to_string(), session.id.to_string())
|
||||
.map_err(|e| {
|
||||
let access_token =
|
||||
bcr::jwt::encode("Beteran", session.id.to_string().as_str()).map_err(|e| {
|
||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||
message: format!("server {}", e),
|
||||
|
|
|
@ -737,12 +737,12 @@ impl Service<'_> {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
search,
|
||||
|
|
|
@ -369,12 +369,12 @@ impl Service<'_> {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -332,12 +332,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -335,12 +335,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -299,12 +299,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -326,12 +326,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -278,12 +278,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -490,12 +490,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
2
src/services/member_session/mod.rs
Normal file
2
src/services/member_session/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod models;
|
||||
pub mod service;
|
17
src/services/member_session/models.rs
Normal file
17
src/services/member_session/models.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use crate::repositories;
|
||||
use beteran_protobuf_rust as bpr;
|
||||
|
||||
impl From<&repositories::member_session::models::MemberSession>
|
||||
for bpr::models::member_session::MemberSession
|
||||
{
|
||||
fn from(d: &repositories::member_session::models::MemberSession) -> Self {
|
||||
bpr::models::member_session::MemberSession {
|
||||
id: d.id.to_string(),
|
||||
member_id: d.member_id.to_string(),
|
||||
ip: d.ip.clone(),
|
||||
last_accessed_at: d.last_accessed_at as u64,
|
||||
expires_at: d.expires_at as u64,
|
||||
created_at: d.created_at as u64,
|
||||
}
|
||||
}
|
||||
}
|
423
src/services/member_session/service.rs
Normal file
423
src/services/member_session/service.rs
Normal file
|
@ -0,0 +1,423 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::models;
|
||||
use crate::compositions;
|
||||
use crate::repositories;
|
||||
use beteran_common_rust as bcr;
|
||||
use beteran_protobuf_rust as bpr;
|
||||
use diesel::{
|
||||
r2d2::{ConnectionManager, Pool},
|
||||
PgConnection,
|
||||
};
|
||||
use prost::Message;
|
||||
|
||||
///
|
||||
pub struct Service {
|
||||
connection_broker: nats::asynk::Connection,
|
||||
queue_broker: String,
|
||||
pool: Pool<ConnectionManager<PgConnection>>,
|
||||
site_composition: compositions::site::composition::Composition,
|
||||
member_session_repository: repositories::member_session::repository::Repository,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Service {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Service of service.member.service.identity")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Service {
|
||||
///
|
||||
pub fn new(
|
||||
connection_broker: nats::asynk::Connection,
|
||||
queue_broker: String,
|
||||
pool: Pool<ConnectionManager<PgConnection>>,
|
||||
) -> Service {
|
||||
Service {
|
||||
connection_broker,
|
||||
queue_broker,
|
||||
pool,
|
||||
site_composition: compositions::site::composition::Composition::new(),
|
||||
member_session_repository: repositories::member_session::repository::Repository::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
||||
futures::try_join!(
|
||||
self.get_member_session(),
|
||||
self.get_member_session_with_renewal(),
|
||||
)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
fn check_site(
|
||||
&self,
|
||||
conn: &diesel::PgConnection,
|
||||
url: Option<String>,
|
||||
site_id: uuid::Uuid,
|
||||
) -> Result<repositories::site::models::Site, bcr::error::rpc::Error> {
|
||||
match self
|
||||
.site_composition
|
||||
.select_by_url(conn, url, site_id)
|
||||
.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,
|
||||
})
|
||||
})? {
|
||||
Some(s) => Ok(s),
|
||||
None => Err(bcr::error::rpc::Error::InvalidParams(
|
||||
bcr::error::rpc::InvalidParams {
|
||||
message: "invalid site_url information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client.site_url".to_string(),
|
||||
value: "".to_string(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::None,
|
||||
message: "".to_string(),
|
||||
},
|
||||
},
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_member_session(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let s = self
|
||||
.connection_broker
|
||||
.queue_subscribe(
|
||||
bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION,
|
||||
self.queue_broker.as_str(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
while let Some(message) = s.next().await {
|
||||
if let Err(e) = async {
|
||||
let req = bpr::ss::member_session::GetMemberSessionRequest::decode(message.data.as_slice())
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
|
||||
message: format!("invalid request: {}", e),
|
||||
})
|
||||
})?;
|
||||
let client = match req.client {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||
bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client".to_string(),
|
||||
value: "".to_string(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "".to_string(),
|
||||
},
|
||||
},
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let access_token = match client.access_token {
|
||||
Some(at) => at,
|
||||
None => {
|
||||
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||
bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client.access_token information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client.access_token".to_string(),
|
||||
value: "".to_string(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "".to_string(),
|
||||
},
|
||||
},
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let claims = bcr::jwt::decode(&access_token).map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client.access_token information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client.access_token".to_string(),
|
||||
value: access_token.clone(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "invalid access_token".to_string(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
|
||||
let request = match req.request {
|
||||
Some(r) => r,
|
||||
None => {
|
||||
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||
bcr::error::rpc::InvalidParams {
|
||||
message: "invalid request information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "request".to_string(),
|
||||
value: "".to_string(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "".to_string(),
|
||||
},
|
||||
},
|
||||
));
|
||||
}
|
||||
};
|
||||
let id = uuid::Uuid::from_str(claims.session_id.as_str()).map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client.access_token.session_id param".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client.access_token.session_id".to_string(),
|
||||
value: claims.session_id.clone(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: e.to_string(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
|
||||
let conn = self.pool.get().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 session = self
|
||||
.member_session_repository
|
||||
.select(&conn, id)
|
||||
.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,
|
||||
})
|
||||
})?;
|
||||
|
||||
message
|
||||
.respond(
|
||||
bpr::ss::member_session::GetMemberSessionResponse {
|
||||
error: None,
|
||||
result: Some(
|
||||
bpr::ss::member_session::get_member_session_response::Result {
|
||||
member_session: session
|
||||
.map(|d| bpr::models::member_session::MemberSession::from(&d)),
|
||||
},
|
||||
),
|
||||
}
|
||||
.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::ss::member_session::GetMemberSessionResponse {
|
||||
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||
result: None,
|
||||
}
|
||||
.encode_to_vec(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_member_session_with_renewal(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let s = self
|
||||
.connection_broker
|
||||
.queue_subscribe(
|
||||
bpr::ss::member_session::SUBJECT_GET_MEMBER_SESSION_WITH_RENEWAL,
|
||||
self.queue_broker.as_str(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
while let Some(message) = s.next().await {
|
||||
if let Err(e) = async {
|
||||
let req = bpr::ss::member_session::GetMemberSessionWithRenewalRequest::decode(
|
||||
message.data.as_slice(),
|
||||
)
|
||||
.map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
|
||||
message: format!("invalid request: {}", e),
|
||||
})
|
||||
})?;
|
||||
let client = match req.client {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||
bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client".to_string(),
|
||||
value: "".to_string(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "".to_string(),
|
||||
},
|
||||
},
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let access_token = match client.access_token {
|
||||
Some(at) => at,
|
||||
None => {
|
||||
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||
bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client.access_token information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client.access_token".to_string(),
|
||||
value: "".to_string(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "".to_string(),
|
||||
},
|
||||
},
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let claims = bcr::jwt::decode(&access_token).map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client.access_token information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client.access_token".to_string(),
|
||||
value: access_token.clone(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "invalid access_token".to_string(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
|
||||
let request = match req.request {
|
||||
Some(r) => r,
|
||||
None => {
|
||||
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||
bcr::error::rpc::InvalidParams {
|
||||
message: "invalid request information".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "request".to_string(),
|
||||
value: "".to_string(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: "".to_string(),
|
||||
},
|
||||
},
|
||||
));
|
||||
}
|
||||
};
|
||||
let id = uuid::Uuid::from_str(claims.session_id.as_str()).map_err(|e| {
|
||||
bcr::error::rpc::Error::InvalidParams(bcr::error::rpc::InvalidParams {
|
||||
message: "invalid client.access_token.session_id param".to_string(),
|
||||
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||
location: "request".to_string(),
|
||||
param: "client.access_token.session_id".to_string(),
|
||||
value: claims.session_id.clone(),
|
||||
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||
message: e.to_string(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
|
||||
let conn = self.pool.get().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 last_accessed_at = (chrono::Utc::now()).timestamp();
|
||||
let expires_at = (chrono::Utc::now() + chrono::Duration::minutes(30)).timestamp();
|
||||
|
||||
self
|
||||
.member_session_repository
|
||||
.update_last_access(
|
||||
&conn,
|
||||
id,
|
||||
&repositories::member_session::models::ModifyMemberSessionForLastAccess {
|
||||
last_accessed_at,
|
||||
expires_at,
|
||||
},
|
||||
)
|
||||
.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 session = self
|
||||
.member_session_repository
|
||||
.select(&conn, id)
|
||||
.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,
|
||||
})
|
||||
})?;
|
||||
|
||||
message
|
||||
.respond(
|
||||
bpr::ss::member_session::GetMemberSessionWithRenewalResponse {
|
||||
error: None,
|
||||
result: Some(
|
||||
bpr::ss::member_session::get_member_session_with_renewal_response::Result {
|
||||
member_session: session
|
||||
.map(|d| bpr::models::member_session::MemberSession::from(&d)),
|
||||
},
|
||||
),
|
||||
}
|
||||
.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::ss::member_session::GetMemberSessionWithRenewalResponse {
|
||||
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||
result: None,
|
||||
}
|
||||
.encode_to_vec(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -343,12 +343,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(bcr::models::pagination::Pagination::from),
|
||||
.map(bcr::pagination::Pagination::from),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||
.map(bcr::pagination::Sort::from)
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -8,5 +8,6 @@ pub mod member_class;
|
|||
pub mod member_game_setting;
|
||||
pub mod member_level;
|
||||
pub mod member_referrer;
|
||||
pub mod member_session;
|
||||
pub mod member_settlement_setting;
|
||||
pub mod site;
|
||||
|
|
|
@ -165,12 +165,12 @@ impl Service {
|
|||
pagination: request
|
||||
.pagination
|
||||
.as_ref()
|
||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||
.map(|d| bcr::pagination::Pagination::from(d)),
|
||||
sorts: Some(
|
||||
request
|
||||
.sorts
|
||||
.iter()
|
||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||
.map(|d| bcr::pagination::Sort::from(d))
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user