Start leave game form

O01eg
Oct 22, 2022, 9:09 AM
5RQCVFRHI353OFKZPVCNJLJLQPEKJVNEDCTM2224U4WABT2YLMQQC

Dependencies

  • [2] H7NQUYI6 Record join to the game
  • [3] 6TPV5GQ3 Show delegates in player table
  • [4] WW3KRXX6 Add page for reset game password
  • [5] EVP2FSBH Split index page
  • [6] HZDCKIXQ Use constants for templates
  • [7] GUAEZDLE Add turns info to slow game's page
  • [8] LTQCLSBU Split database usage in pages
  • [9] DNFB7TNI Add new pages and links to slow games and reset game password
  • [10] NY766BOQ Accept form to add player
  • [11] AEWYJHUD Start to show player list
  • [12] LOFH5LIA Make bold player name
  • [13] WVHXYKCV Add postgresql pools
  • [14] TEB4R7OU Add form to join game
  • [15] A2LJT7TT Show duration in turns
  • [16] XKG2L3QB Show label if player could join the game
  • [17] OJO4B4QO Add login form and empty handler
  • [18] 6NYILMKI Add page for slow game
  • [*] 3HT5CE6S Manage TTL duration in config
  • [*] 4MZ4VIR7 Initial commit

Change contents

  • edit in src/templates/slow-game.html at line 75
    [4.212]
    [4.212]
    </fieldset>
    </form>
    {{/if}}
    {{#if leave_data}}
    <form id="leave-game" action="lave-game.do" method="post">
    <fieldset>
    <input name="csrf" type="hidden" value="{{ leave_data.csrf }}">
    <input name="submit" type="submit" value="Leave Game">
  • replacement in src/pages/slow_game.rs at line 18
    [4.92][4.92:114]()
    pub struct JoinData {
    [4.92]
    [4.269]
    pub struct JoinLeaveData {
  • replacement in src/pages/slow_game.rs at line 35
    [4.366][4.366:399]()
    join_data: Option<JoinData>,
    [4.366]
    [4.0]
    join_data: Option<JoinLeaveData>,
    leave_data: Option<JoinLeaveData>,
  • replacement in src/pages/slow_game.rs at line 126
    [4.449][4.449:515]()
    let (player_list, join_data) = if let Some(ref user) = user {
    [4.449]
    [3.151]
    let (player_list, join_data, leave_data) = if let Some(ref user) = user {
  • replacement in src/pages/slow_game.rs at line 161
    [4.869][4.869:905]()
    Some(JoinData { csrf })
    [4.869]
    [4.905]
    Some(JoinLeaveData { csrf })
  • replacement in src/pages/slow_game.rs at line 166
    [4.951][4.951:984]()
    (Some(users), join_data)
    [4.951]
    [4.1059]
    (Some(users), join_data, None)
  • replacement in src/pages/slow_game.rs at line 168
    [4.1072][4.985:1006]()
    (None, None)
    [4.1072]
    [4.1085]
    (None, None, None)
  • edit in src/pages/slow_game.rs at line 187
    [4.1055]
    [4.2642]
    leave_data,
  • replacement in src/pages/slow_game.rs at line 201
    [4.230][4.230:261]()
    form: web::Form<JoinData>,
    [4.230]
    [4.261]
    form: web::Form<JoinLeaveData>,
  • edit in src/pages/slow_game.rs at line 257
    [2.1233]
    [2.1233]
    }
    HttpResponse::Found()
    .append_header((
    header::LOCATION,
    format!("slow-game-{}.html", cached_data.0),
    ))
    .finish()
    }
    pub async fn post_leave_game(
    request: HttpRequest,
    form: web::Form<JoinLeaveData>,
    data: web::Data<WebData<'_>>,
    _data_rw: web::Data<DataBaseRw>,
    ) -> HttpResponse {
    let cached_data = {
    let mut cache = data.cache_leave_game.lock().await;
    cache.remove(&form.csrf)
    };
    let cached_data = if let Some(cd) = cached_data {
    cd
    } else {
    log::warn!("Unknown data for CSRF: {}", form.csrf);
    return HttpResponse::BadRequest().body("Incorrect");
    };
    let jar = request_to_jar(request);
    if jar
    .private(&data.cookies_key)
    .get("auth")
    .map_or(true, |x| x.value().to_lowercase() != cached_data.1)
    {
    log::warn!("Incorrect user");
    return HttpResponse::BadRequest().body("Incorrect");
  • edit in src/pages/mod.rs at line 48
    [4.1122]
    [20.140]
    pub cache_leave_game: Mutex<TtlCache<Uuid, (String, String)>>,
  • replacement in src/main.rs at line 22
    [4.1187][4.1102:1153]()
    use pages::slow_game::{post_join_game, slow_game};
    [4.1187]
    [4.2243]
    use pages::slow_game::{post_join_game, post_leave_game, slow_game};
  • edit in src/main.rs at line 219
    [4.1215]
    [20.203]
    cache_leave_game: tokio::sync::Mutex::new(ttl_cache::TtlCache::new(cache_capacity)),
  • edit in src/main.rs at line 269
    [4.1222]
    [4.2328]
    .route("/leave-game.do", web::post().to(post_leave_game))