change banned from bool to timestamp

This commit is contained in:
jake 2020-10-03 17:13:29 -06:00
parent aa08e67f6b
commit 17a8b288c1
4 changed files with 11 additions and 11 deletions
src

@ -56,9 +56,9 @@ fn main() {
password: bcrypt::hash("qwer", 5).unwrap(), password: bcrypt::hash("qwer", 5).unwrap(),
guildcard: i + 1, guildcard: i + 1,
team_id: None, team_id: None,
banned: false, banned_until: None,
muted_until: SystemTime::now(), muted_until: None,
created_at: SystemTime::now(), created_at: chrono::Utc::now(),
flags: 0, flags: 0,
}; };
let fake_user = entity_gateway.create_user(fake_user).await.unwrap(); let fake_user = entity_gateway.create_user(fake_user).await.unwrap();

@ -21,9 +21,9 @@ pub struct NewUserAccountEntity {
pub password: String, pub password: String,
pub guildcard: u32, pub guildcard: u32,
pub team_id: Option<u32>, pub team_id: Option<u32>,
pub banned: bool, pub banned_until: Option<chrono::DateTime<chrono::Utc>>,
pub muted_until: SystemTime, pub muted_until: Option<chrono::DateTime<chrono::Utc>>,
pub created_at: SystemTime, pub created_at: chrono::DateTime<chrono::Utc>,
pub flags: u32, pub flags: u32,
} }
@ -34,9 +34,9 @@ pub struct UserAccountEntity {
pub password: String, pub password: String,
pub guildcard: u32, pub guildcard: u32,
pub team_id: Option<u32>, pub team_id: Option<u32>,
pub banned: bool, pub banned_until: Option<chrono::DateTime<chrono::Utc>>,
pub muted_until: SystemTime, pub muted_until: Option<chrono::DateTime<chrono::Utc>>,
pub created_at: SystemTime, pub created_at: chrono::DateTime<chrono::Utc>,
pub flags: u32, // TODO: is this used for anything other than character creation? pub flags: u32, // TODO: is this used for anything other than character creation?
} }

@ -43,7 +43,7 @@ impl EntityGateway for InMemoryGateway {
password: user.password, password: user.password,
guildcard: user.guildcard, guildcard: user.guildcard,
team_id: user.team_id, team_id: user.team_id,
banned: user.banned, banned_until: user.banned_until,
muted_until: user.muted_until, muted_until: user.muted_until,
created_at: user.created_at, created_at: user.created_at,
flags: user.flags, flags: user.flags,

@ -63,7 +63,7 @@ pub async fn get_login_status(entity_gateway: &impl EntityGateway, pkt: &Login)
let user = entity_gateway.get_user_by_name(username).await.ok_or(AccountStatus::InvalidUser)?; let user = entity_gateway.get_user_by_name(username).await.ok_or(AccountStatus::InvalidUser)?;
let verified = bcrypt::verify(password, user.password.as_str()).map_err(|_err| AccountStatus::Error)?; let verified = bcrypt::verify(password, user.password.as_str()).map_err(|_err| AccountStatus::Error)?;
match verified { match verified {
true => if user.banned { true => if user.banned_until.map(|banned| banned > chrono::Utc::now()).unwrap_or(false) {
Err(AccountStatus::Banned) Err(AccountStatus::Banned)
} }
else { else {