1- use chrono:: { NaiveDateTime , Utc } ;
1+ use chrono:: Utc ;
22use num_traits:: FromPrimitive ;
33use rocket:: {
44 form:: { Form , FromForm } ,
@@ -148,7 +148,7 @@ async fn _refresh_login(data: ConnectData, conn: &DbConn, ip: &ClientIp) -> Json
148148 }
149149 Ok ( ( mut device, auth_tokens) ) => {
150150 // Save to update `device.updated_at` to track usage and toggle new status
151- device. save ( conn) . await ?;
151+ device. save ( true , conn) . await ?;
152152
153153 let result = json ! ( {
154154 "refresh_token" : auth_tokens. refresh_token( ) ,
@@ -274,6 +274,7 @@ async fn _sso_login(
274274 }
275275 Some ( ( mut user, sso_user) ) => {
276276 let mut device = get_device ( & data, conn, & user) . await ?;
277+
277278 let twofactor_token = twofactor_auth ( & mut user, & data, & mut device, ip, client_version, conn) . await ?;
278279
279280 if user. private_key . is_none ( ) {
@@ -303,7 +304,7 @@ async fn _sso_login(
303304 // We passed 2FA get auth tokens
304305 let auth_tokens = sso:: redeem ( & device, & user, data. client_id , sso_user, sso_auth, user_infos, conn) . await ?;
305306
306- authenticated_response ( & user, & mut device, auth_tokens, twofactor_token, & now , conn, ip) . await
307+ authenticated_response ( & user, & mut device, auth_tokens, twofactor_token, conn, ip) . await
307308}
308309
309310async fn _password_login (
@@ -425,20 +426,20 @@ async fn _password_login(
425426
426427 let auth_tokens = auth:: AuthTokens :: new ( & device, & user, AuthMethod :: Password , data. client_id ) ;
427428
428- authenticated_response ( & user, & mut device, auth_tokens, twofactor_token, & now , conn, ip) . await
429+ authenticated_response ( & user, & mut device, auth_tokens, twofactor_token, conn, ip) . await
429430}
430431
431432async fn authenticated_response (
432433 user : & User ,
433434 device : & mut Device ,
434435 auth_tokens : auth:: AuthTokens ,
435436 twofactor_token : Option < String > ,
436- now : & NaiveDateTime ,
437437 conn : & DbConn ,
438438 ip : & ClientIp ,
439439) -> JsonResult {
440440 if CONFIG . mail_enabled ( ) && device. is_new ( ) {
441- if let Err ( e) = mail:: send_new_device_logged_in ( & user. email , & ip. ip . to_string ( ) , now, device) . await {
441+ let now = Utc :: now ( ) . naive_utc ( ) ;
442+ if let Err ( e) = mail:: send_new_device_logged_in ( & user. email , & ip. ip . to_string ( ) , & now, device) . await {
442443 error ! ( "Error sending new device email: {e:#?}" ) ;
443444
444445 if CONFIG . require_device_email ( ) {
@@ -458,7 +459,7 @@ async fn authenticated_response(
458459 }
459460
460461 // Save to update `device.updated_at` to track usage and toggle new status
461- device. save ( conn) . await ?;
462+ device. save ( true , conn) . await ?;
462463
463464 let master_password_policy = master_password_policy ( user, conn) . await ;
464465
@@ -575,7 +576,7 @@ async fn _user_api_key_login(
575576 let access_claims = auth:: LoginJwtClaims :: default ( & device, & user, & AuthMethod :: UserApiKey , data. client_id ) ;
576577
577578 // Save to update `device.updated_at` to track usage and toggle new status
578- device. save ( conn) . await ?;
579+ device. save ( true , conn) . await ?;
579580
580581 info ! ( "User {} logged in successfully via API key. IP: {}" , user. email, ip. ip) ;
581582
@@ -638,7 +639,12 @@ async fn get_device(data: &ConnectData, conn: &DbConn, user: &User) -> ApiResult
638639 // Find device or create new
639640 match Device :: find_by_uuid_and_user ( & device_id, & user. uuid , conn) . await {
640641 Some ( device) => Ok ( device) ,
641- None => Device :: new ( device_id, user. uuid . clone ( ) , device_name, device_type, conn) . await ,
642+ None => {
643+ let mut device = Device :: new ( device_id, user. uuid . clone ( ) , device_name, device_type) ;
644+ // save device without updating `device.updated_at`
645+ device. save ( false , conn) . await ?;
646+ Ok ( device)
647+ }
642648 }
643649}
644650
0 commit comments