Add personal page
Dependencies
- [2]
LTQCLSBUSplit database usage in pages - [3]
FUCFD4UVAdd log in and log out support - [4]
H6GGDVHWShow auth info in reset password page - [5]
WW3KRXX6Add page for reset game password - [6]
WEVOADLSRequire to accept cookies policy for log in - [7]
WVHXYKCVAdd postgresql pools - [8]
HZDCKIXQUse constants for templates - [9]
6CFNBL5LAdd headers for better security - [10]
YDWTHWAIShow form to revoke delegation - [11]
AAUEQMCPAdd common header block - [*]
65A3LIWUUse handlebars to render index - [*]
EVP2FSBHSplit index page - [*]
4MZ4VIR7Initial commit - [*]
WLWTNO4YCreate form to request game password change link - [*]
DNFB7TNIAdd new pages and links to slow games and reset game password
Change contents
- replacement in src/templates/sub/header.html at line 6
Hello, {{ common_auth_info.user }}Hello, <a href="my.html">{{ common_auth_info.user }}</a> - file addition: my.html[13.12]
<!DOCTYPE html><html><head><meta charset="UTF-8"><link rel="alternate" type="application/rss+xml" href="static/rss.xml" title="Multiplayer FreeOrion server news" /><link rel="stylesheet" type="text/css" href="static/style.css" /><title>Welcome to public multiplayer FreeOrion server!</title></head><body>{{> header}}<div class="content"><p>Your games:<ul>{{#each games as |game|}}<li class={{#if game.status}}{{#if (eq game.status "started")}}"game-status-started"{{else}}"game-status-finished"{{/if}}{{else}}"game-status-prepared"{{/if}}><a href="slow-game-{{ game.gameuidenc }}.html">{{ game.gameuid }}</a></li>{{/each}}</ul></p></div>{{> footer}}</body></html> - edit in src/pages/reset_game_pwd.rs at line 4
use crate::pages::{insert_security_headers, request_to_jar, CommonAuthInfo}; - edit in src/pages/reset_game_pwd.rs at line 5
use crate::pages::{insert_security_headers, request_to_jar, CommonAuthInfo}; - file addition: my.rs[14.17]
use actix_web::http::header;use actix_web::{web, HttpRequest, HttpResponse};use crate::pages::templates::MY;use crate::pages::{insert_security_headers, request_to_jar, CommonAuthInfo};use crate::{DataBaseRo, WebData};#[derive(serde_derive::Serialize)]struct PageData {common_auth_info: CommonAuthInfo,games: Vec<GameData>,}#[derive(serde_derive::Serialize)]struct GameData {gameuid: String,gameuidenc: String,status: Option<String>,}pub async fn my(request: HttpRequest,data: web::Data<WebData<'_>>,data_ro: web::Data<DataBaseRo>,) -> HttpResponse {let jar = request_to_jar(request);let u = jar.private(&data.cookies_key).get("auth").map(|x| x.value().to_string());if let Some(user) = u {let dbclient = match data_ro.0.get().await {Ok(client) => client,Err(e) => {log::error!("{}", e);return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());}};let stmt = match dbclient.prepare("select g.game_uid, g.status::text from games.games g inner join games.players p on g.game_uid = p.game_uid where p.player_name = $1 order by g.game_uid;").await{Ok(stmt) => stmt,Err(e) => {log::error!("{}", e);return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());}};let rows = match dbclient.query(&stmt, &[&user]).await {Ok(rows) => rows,Err(e) => {log::error!("{}", e);return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());}};let mut games = Vec::with_capacity(rows.len());for row in rows {let gameuid = row.get::<_, &str>(0);let status = row.get::<_, Option<&str>>(1);games.push(GameData {gameuid: gameuid.to_string(),gameuidenc: pct_str::PctString::encode(gameuid.chars(), pct_str::URIReserved).into_string(),status: status.map(str::to_string),});}let body = match data.handlebars.render(MY,&PageData {common_auth_info: CommonAuthInfo { user: Some(user) },games,},) {Ok(b) => b,Err(e) => {log::error!("Render index error: {}", e);return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());}};insert_security_headers(HttpResponse::Ok()).body(body)} else {HttpResponse::Found().append_header((header::LOCATION, "login.html")).finish()}} - edit in src/pages/mod.rs at line 12
pub mod my; - edit in src/pages/mod.rs at line 21
pub const MY: &str = "my"; - replacement in src/pages/log_in.rs at line 128
.append_header((header::LOCATION, "index.html")).append_header((header::LOCATION, "my.html")) - edit in src/main.rs at line 18
use pages::my::my; - edit in src/main.rs at line 157[17.2294][17.2294]
.register_template_string(templates::MY, include_str!("templates/my.html")).expect("my template");handlebars - edit in src/main.rs at line 278[5.1429][17.2470]
.route("/my.html", web::get().to(my))