Skip to content

Commit bc69ae6

Browse files
committed
Updated project
1 parent fa82123 commit bc69ae6

21 files changed

+1534
-1107
lines changed

Cargo.lock

+1,348-933
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ repository = "https://github.com/hopfenspace/runciv"
1212
# Web framework
1313
actix-web = { version = "~4" }
1414
# Extensions for actix-web
15-
actix-toolbox = { version = "~0.11", features = ["logging", "ws", "session"] }
15+
actix-toolbox = { version = "~0.13", features = ["logging", "ws", "session-postgres-only"] }
1616

1717
# openapi swagger
18-
utoipa = { version = "~3", features = ["actix_extras", "repr", "chrono", "uuid", "openapi_extensions", "preserve_order"] }
18+
utoipa = { version = "~5", features = ["actix_extras", "repr", "chrono", "uuid", "openapi_extensions", "preserve_order"] }
1919
# openapi swagger boilerplat generation
20-
utoipa-swagger-ui = { version = "3", features = ["actix-web"] }
20+
utoipa-swagger-ui = { version = "8", features = ["actix-web"] }
2121

2222
# Hashing
2323
argon2 = { version = "~0.5" }
@@ -34,7 +34,7 @@ clap = { version = "~4", features = ["derive"] }
3434
serde = { version = "~1", features = ["derive"] }
3535
serde_repr = { version = "~0.1" }
3636
serde_json = { version = "~1", features = ["raw_value"] }
37-
toml = { version = "~0.7" }
37+
toml = { version = "~0.8" }
3838
# Time library
3939
chrono = { version = ">=0.4.20", default-features = false, features = ["serde"] }
4040
# Bytes abstractions for network usage
@@ -44,19 +44,19 @@ bytestring = { version = "~1" }
4444
# UUID generation
4545
uuid = { version = "~1", features = ["v4", "serde"] }
4646
# Base64 encoding and decoding library
47-
base64 = { version = "~0.21" }
47+
base64 = { version = "~0.22" }
4848

4949
# ORM
50-
rorm = { version = "~0.5", features = ["tokio-rustls", "cli", "uuid"] }
50+
rorm = { version = "~0.6", default-features = false, features = ["postgres-only", "time", "chrono", "cli", "uuid"] }
5151

5252
# Async runtime
53-
tokio = { version = ">=1.23.1", features = ["rt-multi-thread", "sync", "macros"] }
53+
tokio = { version = ">=1.23.1", features = ["rt-multi-thread", "sync", "macros", "fs"] }
5454
# Async abstractions
5555
futures = { version = "~0.3" }
5656
futures-util = "0.3"
5757

5858
# More iterators
59-
itertools = { version = "~0.11" }
59+
itertools = { version = "~0.13" }
6060

6161
# Lazy initialization
6262
once_cell = { version = "~1" }

src/chan/ws_manager_chan.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::iter;
44
use actix_toolbox::ws;
55
use actix_toolbox::ws::{MailboxError, Message};
66
use log::{debug, error, info, warn};
7-
use rorm::{and, delete, query, Database, Model};
7+
use rorm::{and, delete, query, Database, FieldAccess, Model};
88
use serde::{Deserialize, Serialize};
99
use tokio::sync::mpsc::Sender;
1010
use tokio::sync::{mpsc, oneshot};
@@ -246,7 +246,7 @@ pub async fn start_ws_manager(db: Database) -> Result<WsManagerChan, String> {
246246

247247
let (username, display_name) =
248248
match query!(&mut tx, (Account::F.username, Account::F.display_name))
249-
.condition(Account::F.uuid.equals(uuid.as_ref()))
249+
.condition(Account::F.uuid.equals(uuid))
250250
.one()
251251
.await
252252
{
@@ -278,17 +278,15 @@ pub async fn start_ws_manager(db: Database) -> Result<WsManagerChan, String> {
278278
}
279279

280280
if let Err(err) = delete!(&mut tx, ChatRoom)
281-
.condition(
282-
ChatRoom::F.uuid.equals(lobby.chat_room.key().as_ref()),
283-
)
281+
.condition(ChatRoom::F.uuid.equals(*lobby.chat_room.key()))
284282
.await
285283
{
286284
error!("Database error: {err}");
287285
return;
288286
}
289287

290288
if let Err(err) = delete!(&mut tx, Lobby)
291-
.condition(Lobby::F.uuid.equals(lobby.uuid.as_ref()))
289+
.condition(Lobby::F.uuid.equals(lobby.uuid))
292290
.await
293291
{
294292
error!("Database error: {err}");
@@ -319,18 +317,14 @@ pub async fn start_ws_manager(db: Database) -> Result<WsManagerChan, String> {
319317
}
320318

321319
match query!(&mut tx, LobbyAccount)
322-
.condition(LobbyAccount::F.player.equals(uuid.as_ref()))
320+
.condition(LobbyAccount::F.player.equals(uuid))
323321
.all()
324322
.await
325323
{
326324
Ok(lobby_accounts) => {
327325
for lobby_account in lobby_accounts {
328326
let mut lobby = match query!(&mut tx, Lobby)
329-
.condition(
330-
Lobby::F
331-
.uuid
332-
.equals(lobby_account.lobby.key().as_ref()),
333-
)
327+
.condition(Lobby::F.uuid.equals(*lobby_account.lobby.key()))
334328
.one()
335329
.await
336330
{
@@ -350,10 +344,10 @@ pub async fn start_ws_manager(db: Database) -> Result<WsManagerChan, String> {
350344

351345
if let Err(err) = delete!(&mut tx, ChatRoomMember)
352346
.condition(and!(
353-
ChatRoomMember::F.member.equals(uuid.as_ref()),
347+
ChatRoomMember::F.member.equals(uuid),
354348
ChatRoomMember::F
355349
.chat_room
356-
.equals(lobby.chat_room.key().as_ref())
350+
.equals(lobby.chat_room.key())
357351
))
358352
.await
359353
{
@@ -363,8 +357,8 @@ pub async fn start_ws_manager(db: Database) -> Result<WsManagerChan, String> {
363357

364358
if let Err(err) = delete!(&mut tx, LobbyAccount)
365359
.condition(and!(
366-
LobbyAccount::F.player.equals(uuid.as_ref()),
367-
LobbyAccount::F.lobby.equals(lobby.uuid.as_ref())
360+
LobbyAccount::F.player.equals(uuid),
361+
LobbyAccount::F.lobby.equals(lobby.uuid)
368362
))
369363
.await
370364
{

src/models/account.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rorm::fields::BackRef;
1+
use rorm::fields::types::BackRef;
22
use rorm::{field, Model, Patch};
33
use uuid::Uuid;
44

src/models/chat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rorm::fields::{BackRef, ForeignModel};
1+
use rorm::fields::types::{BackRef, ForeignModel};
22
use rorm::{field, Model, Patch};
33
use uuid::Uuid;
44

src/models/friend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rorm::fields::ForeignModel;
1+
use rorm::fields::types::ForeignModel;
22
use rorm::{Model, Patch};
33
use uuid::Uuid;
44

src/models/game.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rorm::fields::{BackRef, ForeignModel};
1+
use rorm::fields::types::{BackRef, ForeignModel};
22
use rorm::{field, Model, Patch};
33
use uuid::Uuid;
44

src/models/invite.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rorm::fields::ForeignModel;
1+
use rorm::fields::types::ForeignModel;
22
use rorm::{Model, Patch};
33
use uuid::Uuid;
44

src/models/lobby.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rorm::fields::{BackRef, ForeignModel};
1+
use rorm::fields::types::{BackRef, ForeignModel};
22
use rorm::{field, Model, Patch};
33
use uuid::Uuid;
44

src/server/handler/accounts.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use argon2::password_hash::{Error, SaltString};
77
use argon2::{Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
88
use log::{error, warn};
99
use rand::thread_rng;
10-
use rorm::{insert, query, update, Database, Model};
10+
use rorm::{insert, query, update, Database, FieldAccess, Model};
1111
use serde::{Deserialize, Serialize};
1212
use utoipa::ToSchema;
1313
use uuid::Uuid;
1414

1515
use crate::chan::{WsManagerChan, WsManagerMessage, WsMessage};
1616
use crate::models::{Account, AccountInsert};
17-
use crate::server::handler::{ApiError, ApiResult, PathUuid};
17+
use crate::server::handler::{ApiError, ApiErrorResponse, ApiResult, PathUuid};
1818

1919
/// The content to register a new account
2020
#[derive(Debug, Deserialize, ToSchema)]
@@ -119,7 +119,7 @@ pub async fn get_me(db: Data<Database>, session: Session) -> ApiResult<Json<Acco
119119
let uuid: Uuid = session.get("uuid")?.ok_or(ApiError::SessionCorrupt)?;
120120

121121
let account = query!(db.as_ref(), Account)
122-
.condition(Account::F.uuid.equals(uuid.as_ref()))
122+
.condition(Account::F.uuid.equals(uuid))
123123
.optional()
124124
.await?
125125
.ok_or(ApiError::SessionCorrupt)?;
@@ -150,8 +150,10 @@ pub async fn delete_me(
150150
) -> ApiResult<HttpResponse> {
151151
let uuid: Uuid = session.get("uuid")?.ok_or(ApiError::SessionCorrupt)?;
152152

153-
rorm::delete!(db.as_ref(), Account)
154-
.condition(Account::F.uuid.equals(uuid.as_ref()))
153+
let db = db.into_inner();
154+
155+
rorm::delete!(&*db, Account)
156+
.condition(Account::F.uuid.equals(uuid))
155157
.await?;
156158

157159
// Clear the current session
@@ -206,7 +208,7 @@ pub async fn set_password(
206208
let mut tx = db.start_transaction().await?;
207209

208210
let (pw_hash,) = query!(&mut tx, (Account::F.password_hash,))
209-
.condition(Account::F.uuid.equals(uuid.as_ref()))
211+
.condition(Account::F.uuid.equals(uuid))
210212
.optional()
211213
.await?
212214
.ok_or(ApiError::SessionCorrupt)?;
@@ -224,8 +226,8 @@ pub async fn set_password(
224226
.to_string();
225227

226228
update!(&mut tx, Account)
227-
.condition(Account::F.uuid.equals(uuid.as_ref()))
228-
.set(Account::F.password_hash, &password_hash)
229+
.condition(Account::F.uuid.equals(uuid))
230+
.set(Account::F.password_hash, password_hash)
229231
.exec()
230232
.await?;
231233

@@ -264,7 +266,10 @@ pub struct UpdateAccountRequest {
264266
)]
265267
#[put("/accounts/me")]
266268
pub async fn update_me(
267-
req: Json<UpdateAccountRequest>,
269+
Json(UpdateAccountRequest {
270+
username,
271+
display_name,
272+
}): Json<UpdateAccountRequest>,
268273
db: Data<Database>,
269274
session: Session,
270275
ws_manager_chan: Data<WsManagerChan>,
@@ -273,7 +278,7 @@ pub async fn update_me(
273278

274279
let mut tx = db.start_transaction().await?;
275280

276-
if let Some(username) = &req.username {
281+
if let Some(username) = &username {
277282
if username.is_empty() {
278283
return Err(ApiError::InvalidUsername);
279284
}
@@ -288,17 +293,17 @@ pub async fn update_me(
288293
}
289294
}
290295

291-
if let Some(display_name) = &req.display_name {
296+
if let Some(display_name) = &display_name {
292297
if display_name.is_empty() {
293298
return Err(ApiError::InvalidDisplayName);
294299
}
295300
}
296301

297302
update!(&mut tx, Account)
298-
.condition(Account::F.uuid.equals(uuid.as_ref()))
303+
.condition(Account::F.uuid.equals(uuid))
299304
.begin_dyn_set()
300-
.set_if(Account::F.username, req.username.as_ref())
301-
.set_if(Account::F.display_name, req.display_name.as_ref())
305+
.set_if(Account::F.username, username)
306+
.set_if(Account::F.display_name, display_name)
302307
.finish_dyn_set()
303308
.map_err(|_| ApiError::EmptyJson)?
304309
.exec()
@@ -312,7 +317,7 @@ pub async fn update_me(
312317
Account::F.display_name
313318
)
314319
)
315-
.condition(Account::F.uuid.equals(uuid.as_ref()))
320+
.condition(Account::F.uuid.equals(uuid))
316321
.optional()
317322
.await?
318323
.ok_or(ApiError::SessionCorrupt)?;
@@ -359,8 +364,8 @@ pub async fn lookup_account_by_uuid(
359364
req: Path<PathUuid>,
360365
db: Data<Database>,
361366
) -> ApiResult<Json<AccountResponse>> {
362-
let account = query!(db.as_ref(), Account)
363-
.condition(Account::F.uuid.equals(req.uuid.as_ref()))
367+
let account = query!(&**db, Account)
368+
.condition(Account::F.uuid.equals(req.uuid))
364369
.optional()
365370
.await?
366371
.ok_or(ApiError::InvalidUuid)?;
@@ -404,7 +409,7 @@ pub async fn lookup_account_by_username(
404409
req: Json<LookupAccountUsernameRequest>,
405410
db: Data<Database>,
406411
) -> ApiResult<Json<AccountResponse>> {
407-
let account = query!(db.as_ref(), Account)
412+
let account = query!(&**db, Account)
408413
.condition(Account::F.username.equals(&req.username))
409414
.optional()
410415
.await?

src/server/handler/auth.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use argon2::password_hash::Error;
77
use argon2::{Argon2, PasswordHash, PasswordVerifier};
88
use chrono::Utc;
99
use log::error;
10-
use rorm::{query, update, Database, Model};
10+
use rorm::{query, update, Database, FieldAccess, Model};
1111
use serde::Deserialize;
1212
use utoipa::ToSchema;
1313
use uuid::Uuid;
1414

1515
use crate::chan::{WsManagerChan, WsManagerMessage};
1616
use crate::models::Account;
17-
use crate::server::handler::{ApiError, ApiResult};
17+
use crate::server::handler::{ApiError, ApiErrorResponse, ApiResult};
1818

1919
/// The request data of a login request
2020
#[derive(ToSchema, Deserialize)]
@@ -63,7 +63,7 @@ pub(crate) async fn login(
6363
})?;
6464

6565
update!(&mut tx, Account)
66-
.condition(Account::F.uuid.equals(user.uuid.as_ref()))
66+
.condition(Account::F.uuid.equals(user.uuid))
6767
.set(Account::F.last_login, Some(Utc::now().naive_utc()))
6868
.exec()
6969
.await?;

0 commit comments

Comments
 (0)