Claiming, redeeming and changing a password count as a last seen
Browse files at this commitfa7b98e9c94b775a47341c4097c6e6451c887886Parent: faea59e- fix
- claiming, redeeming and changing a password count as a last seen
2 changed files +39 -0
crates/izlek-core/src/accounts.rsmodified+17 -0
| @@ -127,6 +127,16 @@ impl Accounts { | |||
| 127 | Err(StoreError::AlreadyClaimed) => return Err(AccountError::AlreadyClaimed), | 127 | Err(StoreError::AlreadyClaimed) => return Err(AccountError::AlreadyClaimed), |
| 128 | Err(e) => return Err(e.into()), | 128 | Err(e) => return Err(e.into()), |
| 129 | }; | 129 | }; |
| 130 | + // The claim is the admin's first arrival; it counts as their last | ||
| 131 | + // seen, or their own page reads "active" under "last seen". | ||
| 132 | + self.store | ||
| 133 | + .mark_signed_in(&admin.id, OffsetDateTime::now_utc()) | ||
| 134 | + .await?; | ||
| 135 | + let admin = self | ||
| 136 | + .store | ||
| 137 | + .user(&admin.id) | ||
| 138 | + .await? | ||
| 139 | + .ok_or(StoreError::NotFound)?; | ||
| 130 | let signed_in = self.start_session(admin).await?; | 140 | let signed_in = self.start_session(admin).await?; |
| 131 | Ok((workspace, signed_in)) | 141 | Ok((workspace, signed_in)) |
| 132 | } | 142 | } |
| @@ -297,6 +307,9 @@ impl Accounts { | |||
| 297 | } | 307 | } |
| 298 | 308 | ||
| 299 | self.store.set_password_hash(&user.id, &hash).await?; | 309 | self.store.set_password_hash(&user.id, &hash).await?; |
| 310 | + // Choosing the password is their first arrival; it counts as their | ||
| 311 | + // last seen, or their own page reads "active" under "last seen". | ||
| 312 | + self.store.mark_signed_in(&user.id, now).await?; | ||
| 300 | self.store.clear_auth_attempts(&client_bucket).await?; | 313 | self.store.clear_auth_attempts(&client_bucket).await?; |
| 301 | let user = self | 314 | let user = self |
| 302 | .store | 315 | .store |
| @@ -395,6 +408,10 @@ impl Accounts { | |||
| 395 | auth::check_password(new, &user.email, &user.display_name)?; | 408 | auth::check_password(new, &user.email, &user.display_name)?; |
| 396 | let hash = hash_password(new)?; | 409 | let hash = hash_password(new)?; |
| 397 | self.store.set_password_hash(&user.id, &hash).await?; | 410 | self.store.set_password_hash(&user.id, &hash).await?; |
| 411 | + // Changing the password is presence; it counts as their last seen. | ||
| 412 | + self.store | ||
| 413 | + .mark_signed_in(&user.id, OffsetDateTime::now_utc()) | ||
| 414 | + .await?; | ||
| 398 | self.store.clear_auth_attempts(&client_bucket).await?; | 415 | self.store.clear_auth_attempts(&client_bucket).await?; |
| 399 | // "Signs out your other devices", as the pane promises. | 416 | // "Signs out your other devices", as the pane promises. |
| 400 | self.store | 417 | self.store |
crates/izlek-core/tests/store.rsmodified+22 -0
| @@ -1685,6 +1685,10 @@ async fn claiming_makes_an_admin_and_signs_them_in() { | |||
| 1685 | .unwrap(); | 1685 | .unwrap(); |
| 1686 | assert_eq!(workspace.name, "İzlek"); | 1686 | assert_eq!(workspace.name, "İzlek"); |
| 1687 | assert_eq!(signed_in.user.role, Role::Admin); | 1687 | assert_eq!(signed_in.user.role, Role::Admin); |
| 1688 | + assert!( | ||
| 1689 | + signed_in.user.last_signed_in_at.is_some(), | ||
| 1690 | + "the claim is their first arrival" | ||
| 1691 | + ); | ||
| 1688 | 1692 | ||
| 1689 | // The cookie value works and is not what is stored. | 1693 | // The cookie value works and is not what is stored. |
| 1690 | let who = accounts | 1694 | let who = accounts |
| @@ -1759,6 +1763,10 @@ async fn an_invited_member_chooses_their_own_password() { | |||
| 1759 | .unwrap(); | 1763 | .unwrap(); |
| 1760 | assert_eq!(signed_in.user.id, invitation.user.id); | 1764 | assert_eq!(signed_in.user.id, invitation.user.id); |
| 1761 | assert!(signed_in.user.has_signed_in()); | 1765 | assert!(signed_in.user.has_signed_in()); |
| 1766 | + assert!( | ||
| 1767 | + signed_in.user.last_signed_in_at.is_some(), | ||
| 1768 | + "redeeming the link is their first arrival" | ||
| 1769 | + ); | ||
| 1762 | 1770 | ||
| 1763 | // And now the password they chose works, and only that one. | 1771 | // And now the password they chose works, and only that one. |
| 1764 | accounts | 1772 | accounts |
| @@ -2224,6 +2232,16 @@ async fn changing_a_password_signs_out_every_device() { | |||
| 2224 | .is_some() | 2232 | .is_some() |
| 2225 | ); | 2233 | ); |
| 2226 | 2234 | ||
| 2235 | + // The baseline is read from the store, not from `second`: sign_in hands | ||
| 2236 | + // back the user it fetched before marking, one arrival stale. | ||
| 2237 | + let seen = accounts | ||
| 2238 | + .store() | ||
| 2239 | + .user(&admin.id) | ||
| 2240 | + .await | ||
| 2241 | + .unwrap() | ||
| 2242 | + .unwrap() | ||
| 2243 | + .last_signed_in_at | ||
| 2244 | + .unwrap(); | ||
| 2227 | let fresh = accounts | 2245 | let fresh = accounts |
| 2228 | .change_password( | 2246 | .change_password( |
| 2229 | &admin.id, | 2247 | &admin.id, |
| @@ -2233,6 +2251,10 @@ async fn changing_a_password_signs_out_every_device() { | |||
| 2233 | ) | 2251 | ) |
| 2234 | .await | 2252 | .await |
| 2235 | .unwrap(); | 2253 | .unwrap(); |
| 2254 | + assert!( | ||
| 2255 | + fresh.user.last_signed_in_at.unwrap() > seen, | ||
| 2256 | + "changing the password is presence" | ||
| 2257 | + ); | ||
| 2236 | 2258 | ||
| 2237 | for old in [&first, &second] { | 2259 | for old in [&first, &second] { |
| 2238 | assert!( | 2260 | assert!( |