Register application on Mastodon domain
Dependencies
- [2]
BUW254XBUpdate toml dependency - [3]
WM64YAQLFix warnings - [4]
BCMU6UYKStart login mastodon form - [5]
ZQIIC7C3Add field to store timestamp of joining game - [6]
MUTHALNPDetect user and domain in Mastodon fediverse - [7]
G4JCZ5F7Store try to register on Mastodon domain - [*]
FUCFD4UVAdd log in and log out support - [*]
IXY6NZLMStart to use migrations files for PostgreSQL database - [*]
4MZ4VIR7Initial commit - [*]
BCXEUKX6Add config, static files and web server - [*]
FVYTV3D2Add custom notes to new games feed
Change contents
- edit in src/pages/log_in.rs at line 143
async fn register_in_mastodon(domain: &str,reg_sess_id: &Uuid,data: &web::Data<WebData<'_>>,) -> Result<(String, String), ()> {log::info!("Mastodon domain {} registration session {} started",domain,reg_sess_id); - edit in src/pages/log_in.rs at line 155
let client = awc::Client::default();let website = format!("{}://{}/", data.base_proto, data.base_domain);match client.post(format!("https://{}/api/v1/apps", domain)).content_type("application/x-www-form-urlencoded").send_body(format!("client_name=FreeOrion%20Test%20Web&redirect_uris={}&scopes=read:accounts&website={}",pct_str::PctString::encode(website.chars(), pct_str::URIReserved).as_str(),pct_str::PctString::encode(website.chars(), pct_str::URIReserved).as_str())).await{Ok(mut resp) => match resp.json::<serde_json::Value>().await {Ok(serde_json::Value::Object(resp_value_obj)) => {let client_id_value = resp_value_obj.get("client_id");let client_secret_value = resp_value_obj.get("client_secret");if let (Some(serde_json::Value::String(client_id)),Some(serde_json::Value::String(client_secret)),) = (client_id_value, client_secret_value){Ok((client_id.clone(), client_secret.clone()))} else {log::error!("Mastodon domain {} registration session {} missing fields JSON {:?}",domain,reg_sess_id,resp_value_obj);Err(())}}Ok(resp_value) => {log::error!("Mastodon domain {} registration session {} non-object JSON {:?}",domain,reg_sess_id,resp_value);Err(())}Err(err) => {log::error!("Mastodon domain {} registration session {} failed JSON {:?}",domain,reg_sess_id,err);Err(())}},Err(err) => {log::error!("Mastodon domain {} registration session {} failed {:?}",domain,reg_sess_id,err);Err(())}}} - replacement in src/pages/log_in.rs at line 287
"INSERT INTO auth.mastodon_apps (domain, refresh_ts) VALUES ($1, $2)"INSERT INTO auth.mastodon_apps (domain, refresh_ts, reg_sess_id) VALUES ($1, $2, $3) - replacement in src/pages/log_in.rs at line 289
RETURNING client_id, client_secret;",RETURNING client_id, client_secret, reg_sess_id;", - replacement in src/pages/log_in.rs at line 300
let rows = match dbclient_rw.query_opt(&stmt, &[&domain, &ts]).await {let reg_sess_id = Uuid::new_v4();log::info!("Mastodon domain {} registration session {} created",domain,reg_sess_id);let rows = match dbclient_rw.query_opt(&stmt, &[&domain, &ts, ®_sess_id]).await{ - edit in src/pages/log_in.rs at line 323
let opt_client_id = row.get::<_, Option<String>>(0);let opt_client_secret = row.get::<_, Option<String>>(1);let old_reg_sess_id = row.get::<_, uuid::Uuid>(2); - replacement in src/pages/log_in.rs at line 328
let _opt_client_id = row.get::<_, Option<&str>>(0);let _opt_client_secret = row.get::<_, Option<&str>>(1);let (client_id, _client_secret) =if let (Some(client_id), Some(client_secret)) = (opt_client_id, opt_client_secret) {(client_id, client_secret)} else {if reg_sess_id != old_reg_sess_id {// Some one else registering same domain, try again laterlog::warn!("Mastodon domain {} registration session {} conflict with {}",domain,reg_sess_id,old_reg_sess_id);return HttpResponse::Found().append_header((header::LOCATION, "index.html")).finish();}// Try to register on Mastodon domainmatch register_in_mastodon(&domain, ®_sess_id, &data).await {Ok(res) => res,Err(_) => {return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());}}}; - replacement in src/pages/log_in.rs at line 354
// Try to register on Mastodon domainlog::info!("Mastodon domain {} registration session {} completed with client_id {}",domain,reg_sess_id,client_id); - file addition: 20240731_0_mastodon-apps-uuid.sql[10.15]
-- Create field to store registartion session on MastodonDO $$BEGINIF NOT EXISTS (SELECT 1 FROM pg_class cINNER JOIN pg_namespace n ON n.oid = c.relnamespaceINNER JOIN pg_attribute a ON a.attrelid = c.oidWHERE c.relname = 'mastodon_apps' AND n.nspname = 'auth' AND a.attname = 'reg_sess_id') THENALTER TABLE auth.mastodon_apps ADD COLUMN reg_sess_id UUID NOT NULL;END IF;END$$; - edit in Cargo.toml at line 15
serde_json = "1.0" - edit in Cargo.lock at line 859[12.20545][13.1353]
"serde_json",