diff --git a/frontend/src/main.ts b/frontend/src/main.ts index c9e8692..9012ffb 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -2,7 +2,7 @@ import { createApp } from 'vue' import { registerPlugins } from '@/plugins' import App from './App.vue' -export const server = "http://flutter.localhost:8080"; +export const server = "http://fallacious-rooster.local:8080"; // Vuetify missing type export type InputValidationRule = (v: string) => string | boolean; diff --git a/frontend/src/scripts/core/fetch1.ts b/frontend/src/scripts/core/fetch1.ts index eaff816..b5debc3 100644 --- a/frontend/src/scripts/core/fetch1.ts +++ b/frontend/src/scripts/core/fetch1.ts @@ -4,9 +4,22 @@ import {ApiError} from "@/scripts/core/error"; export async function fetch1(input: RequestInfo | URL, init?: RequestInit): Promise> { if (init) { init.credentials = "include"; + if (init.headers) { + init.headers = { + ...init.headers, + 'Access-Control-Allow-Credentials': "true", + } + } else { + init.headers = { + 'Access-Control-Allow-Credentials': "true", + }; + } } else { init = { - credentials: "include" + credentials: "include", + headers: { + 'Access-Control-Allow-Credentials': "true", + }, }; } diff --git a/server/.gitignore b/server/.gitignore index 96ef862..3e70186 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,2 +1,4 @@ target/ .idea/ + +config.json \ No newline at end of file diff --git a/server/Cargo.toml b/server/Cargo.toml index e6bd3a0..e4e89c3 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -22,4 +22,4 @@ tracing-actix-web = "0.7.11" tracing-error = "0.2.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } clap = { version = "4.5.14", features = ["derive"] } -actix-route-config = "0.1.1" \ No newline at end of file +actix-route-config = "0.1.1" diff --git a/server/sample_config.json b/server/sample_config.json index 8032405..eb1a564 100644 --- a/server/sample_config.json +++ b/server/sample_config.json @@ -1,13 +1,13 @@ { "server": { "port": 8080, - "domain": "fallacious-rooster.localhost:8080" + "domain": "fallacious-rooster.local:8080" }, "koala": { "koala_host": "http://koala.rails.local:3000", "client_id": "", "client_secret": "", - "redirect_uri": "http://fallacious-rooster.localhost:8080/api/oauth/callback" + "redirect_uri": "http://fallacious-rooster.local:8080/api/oauth/callback" }, "email": { "from_email": "anoniem@svsticky.nl", @@ -15,8 +15,8 @@ "smtp_relay": "smtp-relay.gmail.com" }, "frontend": { - "home_page_url": "http://fallacious-rooster.localhost:3001/", - "domain": "fallacious-rooster.localhost:3001" + "home_page_url": "http://fallacious-rooster.local:3001/", + "domain": "fallacious-rooster.local:3001" }, "local_storage": "./storage.json" } \ No newline at end of file diff --git a/server/src/email/template.rs b/server/src/email/template.rs index d8c0548..df541ad 100644 --- a/server/src/email/template.rs +++ b/server/src/email/template.rs @@ -1,9 +1,9 @@ use handlebars::{Handlebars, RenderError}; use serde::Serialize; -pub const TEMPLATE_REPORT_BOARD: &str = include_str!("./templates/report_board.handlebars"); +pub const TEMPLATE_REPORT_BOARD: &str = include_str!("templates/report_board.hbs"); pub const TEMPLATE_CONFIDENTIAL_ADVISORS: &str = - include_str!("./templates/report_confidential_advisors.handlebars"); + include_str!("templates/report_confidential_advisors.hbs"); #[derive(Serialize)] pub struct ReportTemplate { diff --git a/server/src/email/templates/report_board.handlebars b/server/src/email/templates/report_board.handlebars deleted file mode 100644 index e69de29..0000000 diff --git a/server/src/email/templates/report_board.hbs b/server/src/email/templates/report_board.hbs new file mode 100644 index 0000000..079ac24 --- /dev/null +++ b/server/src/email/templates/report_board.hbs @@ -0,0 +1,51 @@ + + + + + + Sticky Anonymous Report + + + +
+
+

New anonymous report

+ +

+ Hi,
+
+ A new report has been submitted and sent to the board of Sticky. +

Message

+ {{ message }} + +

Contact

+ {{#if contact_address }} + The user has given the following email address if you want to contact them: {{ contact_address }}. + {{else}} + The user has not given a contact address. + {{/if}} +
+
+ Thanks,
+ Sticky +

+
+
+ + \ No newline at end of file diff --git a/server/src/email/templates/report_confidential_advisors.handlebars b/server/src/email/templates/report_confidential_advisors.handlebars deleted file mode 100644 index e69de29..0000000 diff --git a/server/src/email/templates/report_confidential_advisors.hbs b/server/src/email/templates/report_confidential_advisors.hbs new file mode 100644 index 0000000..224c9fd --- /dev/null +++ b/server/src/email/templates/report_confidential_advisors.hbs @@ -0,0 +1,51 @@ + + + + + + Sticky Anonymous Report + + + +
+
+

New anonymous report

+ +

+ Hi,
+
+ A new report has been submitted and sent to the confidential advisor. +

Message

+ {{ message }} + +

Contact

+ {{#if contact_address }} + The user has given the following email address if you want to contact them: {{ contact_address }}. + {{else}} + The user has not given a contact address. + {{/if}} +
+
+ Thanks,
+ Sticky +

+
+
+ + \ No newline at end of file diff --git a/server/src/file/config.rs b/server/src/file/config.rs index 5cfd363..162c77b 100644 --- a/server/src/file/config.rs +++ b/server/src/file/config.rs @@ -21,6 +21,7 @@ pub struct FrontendConfig { pub struct ServerConfig { #[serde(default = "default_port")] pub port: u16, + pub domain: String, } #[derive(Debug, Default, Clone, Deserialize, Serialize)] @@ -48,6 +49,7 @@ impl Default for ServerConfig { fn default() -> Self { Self { port: default_port(), + domain: String::default(), } } } diff --git a/server/src/server/mod.rs b/server/src/server/mod.rs index 6fe7f7d..7c626f4 100644 --- a/server/src/server/mod.rs +++ b/server/src/server/mod.rs @@ -18,6 +18,7 @@ pub async fn run_server( let port = config.server.port; let storage = WStorage::new(MutAppStorage(RwLock::new(storage))); + let host = config.server.domain.clone(); HttpServer::new(move || { App::new() .wrap(Cors::permissive()) @@ -28,6 +29,7 @@ pub async fn run_server( .configure(routes::Router::configure) }) .bind(format!("0.0.0.0:{port}"))? + .server_hostname(&host) .run() .await?; diff --git a/server/src/server/types/redirect.rs b/server/src/server/types/redirect.rs index 3daac14..88891f9 100644 --- a/server/src/server/types/redirect.rs +++ b/server/src/server/types/redirect.rs @@ -28,7 +28,7 @@ impl Responder for Redirect { type Body = BoxBody; fn respond_to(self, _: &HttpRequest) -> HttpResponse { - let mut builder = HttpResponse::TemporaryRedirect(); + let mut builder = HttpResponse::Found(); builder.append_header(( HeaderName::from_static("location"), HeaderValue::from_str(&self.to).unwrap(), diff --git a/server/src/server/types/set_cookie.rs b/server/src/server/types/set_cookie.rs index a5b2c9a..6d38880 100644 --- a/server/src/server/types/set_cookie.rs +++ b/server/src/server/types/set_cookie.rs @@ -1,4 +1,4 @@ -use actix_web::cookie::Cookie; +use actix_web::cookie::{Cookie, Expiration, SameSite}; use actix_web::{HttpRequest, HttpResponse, Responder}; pub struct SetCookie { @@ -24,8 +24,17 @@ impl Responder for SetCookie { let mut response = self.inner.respond_to(req); let mut cookie = Cookie::new(self.cookie_name, self.cookie_value); cookie.set_path("/"); - response.add_cookie(&cookie).unwrap(); + cookie.set_http_only(true); + cookie.set_expires(Expiration::Session); + + if cfg!(debug_assertions) { + cookie.set_same_site(Some(SameSite::Lax)); + } else { + cookie.set_same_site(Some(SameSite::None)); + cookie.set_secure(false); + } + response.add_cookie(&cookie).unwrap(); response } }