Compare commits

..

No commits in common. "ebbd9215ea912435791c974ac52f5b1c26f3d4c1" and "f58d0d010eebf9c372791c116175c84bed0dba31" have entirely different histories.

5 changed files with 19 additions and 30 deletions

View File

@ -11,7 +11,7 @@ env:
jobs: jobs:
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215 container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240118
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Run Test DB Script - name: Run Test DB Script
@ -46,7 +46,7 @@ jobs:
deploy-staging: deploy-staging:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215 container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240118
needs: [test] needs: [test]
if: github.ref == 'refs/heads/staging' if: github.ref == 'refs/heads/staging'
steps: steps:
@ -97,7 +97,7 @@ jobs:
deploy-main: deploy-main:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215 container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240118
needs: [test] needs: [test]
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
steps: steps:

View File

@ -5,7 +5,7 @@
# 2. Tag the image: `docker tag <id> git.hofer.link/ruderverein-donau-linz/rowing-ci:<date>` # 2. Tag the image: `docker tag <id> git.hofer.link/ruderverein-donau-linz/rowing-ci:<date>`
# 3. Push the image: `docker push git.hofer.link/ruderverein-donau-linz/rowing-ci:<date>` # 3. Push the image: `docker push git.hofer.link/ruderverein-donau-linz/rowing-ci:<date>`
FROM rust:1.76 FROM rust:1.75.0
RUN apt-get update && apt-get install -y sqlite3 RUN apt-get update && apt-get install -y sqlite3

View File

@ -1,9 +1,8 @@
use std::{error::Error, fs}; use std::error::Error;
use lettre::{ use lettre::{
message::{header::ContentType, Attachment, MultiPart, SinglePart}, message::header::ContentType, transport::smtp::authentication::Credentials, Message,
transport::smtp::authentication::Credentials, SmtpTransport, Transport,
Message, SmtpTransport, Transport,
}; };
use sqlx::SqlitePool; use sqlx::SqlitePool;
@ -14,7 +13,7 @@ use super::{family::Family, log::Log, role::Role, user::User};
pub struct Mail {} pub struct Mail {}
impl Mail { impl Mail {
pub async fn send(db: &SqlitePool, data: MailToSend<'_>, smtp_pw: String) -> bool { pub async fn send(db: &SqlitePool, data: MailToSend, smtp_pw: String) -> bool {
let mut email = Message::builder() let mut email = Message::builder()
.from( .from(
"ASKÖ Ruderverein Donau Linz <no-reply@rudernlinz.at>" "ASKÖ Ruderverein Donau Linz <no-reply@rudernlinz.at>"
@ -46,23 +45,13 @@ impl Mail {
} }
} }
let mut multipart = MultiPart::mixed().singlepart(SinglePart::plain(data.body)); // TODO: handle attachments
for temp_file in &data.files { let email = email
let content = fs::read(temp_file.path().unwrap()).unwrap(); .subject(data.subject)
let media_type = format!("{}", temp_file.content_type().unwrap().media_type()); .header(ContentType::TEXT_PLAIN)
let content_type = ContentType::parse(&media_type).unwrap(); .body(String::from(data.body))
let attachment = Attachment::new(format!( .unwrap();
"{}.{}",
temp_file.name().unwrap(),
temp_file.content_type().unwrap().extension().unwrap()
))
.body(content, content_type);
multipart = multipart.singlepart(attachment);
}
let email = email.subject(data.subject).multipart(multipart).unwrap();
let creds = Credentials::new("no-reply@rudernlinz.at".to_owned(), smtp_pw); let creds = Credentials::new("no-reply@rudernlinz.at".to_owned(), smtp_pw);

View File

@ -51,7 +51,7 @@ WHERE name like ?
FROM user u FROM user u
JOIN user_role ur ON u.id = ur.user_id JOIN user_role ur ON u.id = ur.user_id
JOIN role r ON ur.role_id = r.id JOIN role r ON ur.role_id = r.id
WHERE r.id = {} AND deleted=0;", WHERE r.id = {}",
self.id self.id
); );

View File

@ -1,5 +1,4 @@
use rocket::form::Form; use rocket::form::Form;
use rocket::fs::TempFile;
use rocket::response::{Flash, Redirect}; use rocket::response::{Flash, Redirect};
use rocket::{get, request::FlashMessage, routes, Route, State}; use rocket::{get, request::FlashMessage, routes, Route, State};
use rocket::{post, FromForm}; use rocket::{post, FromForm};
@ -40,17 +39,18 @@ async fn fee(db: &State<SqlitePool>, _admin: AdminUser, config: &State<Config>)
} }
#[derive(FromForm, Debug)] #[derive(FromForm, Debug)]
pub struct MailToSend<'a> { pub struct MailToSend {
//<'a> {
pub(crate) role_id: i32, pub(crate) role_id: i32,
pub(crate) subject: String, pub(crate) subject: String,
pub(crate) body: String, pub(crate) body: String,
pub(crate) files: Vec<TempFile<'a>>, //pub(crate) files: Vec<TempFile<'a>>,
} }
#[post("/mail", data = "<data>")] #[post("/mail", data = "<data>")]
async fn update( async fn update(
db: &State<SqlitePool>, db: &State<SqlitePool>,
data: Form<MailToSend<'_>>, data: Form<MailToSend>,
config: &State<Config>, config: &State<Config>,
_admin: AdminUser, _admin: AdminUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {