Merge commit '311153d96b68116a5a7dcafc40e368f88021a695'

This commit is contained in:
Marie Birner 2023-04-10 15:04:38 +02:00
commit 1b7ce91d80
8 changed files with 79 additions and 170 deletions

10
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,10 @@
stages:
- build
rust-latest:
stage: build
image: rust:latest
script:
- apt update && apt install -y sqlite3 && ./test_db.sh
- cargo build --verbose
- cargo test --verbose

14
Cargo.lock generated
View File

@ -330,9 +330,9 @@ checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484"
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.7" version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"crossbeam-utils", "crossbeam-utils",
@ -507,13 +507,13 @@ dependencies = [
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.0" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a"
dependencies = [ dependencies = [
"errno-dragonfly", "errno-dragonfly",
"libc", "libc",
"windows-sys 0.45.0", "windows-sys 0.48.0",
] ]
[[package]] [[package]]
@ -1826,9 +1826,9 @@ dependencies = [
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.37.8" version = "0.37.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aef160324be24d31a62147fae491c14d2204a3865c7ca8c3b0d7f7bcb3ea635" checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"errno", "errno",

View File

@ -2,7 +2,8 @@
- [ ] Allow sign-outs only >2h before event - [ ] Allow sign-outs only >2h before event
# Notes / Bugfixes # Notes / Bugfixes
[] filter conflict month and coxneeded - [] filter conflict month and coxneeded
- [] max_people = 0 -> Rot hervorheben, dass Ausfahrt abgesagt wurde?
# Frontend Process # Frontend Process
´cd frontend´ ´cd frontend´

113
seeds.sql
View File

@ -1,108 +1,5 @@
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Daniela Allmeier', false, true); INSERT INTO "user" (name, is_cox, is_admin, is_guest, pw) VALUES('admin', false, true, false, '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$4P4NCw4Ukhv80/eQYTsarHhnw61JuL1KMx/L9dm82YM');
INSERT INTO "user" (name, is_guest) VALUES ('Doris Allmeier', false); INSERT INTO "user" (name, is_cox, is_admin, is_guest, pw) VALUES('rower', false, false, false, '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$jWKzDmI0jqT2dqINFt6/1NjVF4Dx15n07PL1ZMBmFsY');
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Karl Allmeier', false, true); INSERT INTO "user" (name, is_cox, is_admin, is_guest, pw) VALUES('guest', false, false, true, '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$GF6gizbI79Bh0zA9its8S0gram956v+YIV8w8VpwJnQ');
INSERT INTO "user" (name, is_guest) VALUES ('Alaa Almousa', false); INSERT INTO "user" (name, is_cox, is_admin, is_guest, pw) VALUES('cox', true, false, false, '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$lnWzHx3DdqS9GQyWYel82kIotZuK2wk9EyfhPFtjNzs');
INSERT INTO "user" (name, is_guest) VALUES ('Elke Atzgerstorfer', false); INSERT INTO "user" (name) VALUES('new');
INSERT INTO "user" (name, is_guest) VALUES ('Eva Atzgerstorfer', false);
INSERT INTO "user" (name, is_guest) VALUES ('Philip Baillon', false);
INSERT INTO "user" (name, is_guest) VALUES ('Elfriede Baminger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Alexandra Binder', false);
INSERT INTO "user" (name, is_guest) VALUES ('Gerald Binder', false);
INSERT INTO "user" (name, is_guest, is_cox, is_admin) VALUES ('Marie Birner', false, true, true);
INSERT INTO "user" (name, is_guest) VALUES ('Richard Bogdan', false);
INSERT INTO "user" (name, is_guest) VALUES ('Mara Brandstetter', false);
INSERT INTO "user" (name, is_guest) VALUES ('Christian Commenda', false);
INSERT INTO "user" (name, is_guest) VALUES ('Goran DAgosto', false);
INSERT INTO "user" (name, is_guest) VALUES ('Daria Danner', false);
INSERT INTO "user" (name, is_guest) VALUES ('Silvia Demmig', false);
INSERT INTO "user" (name, is_guest) VALUES ('Daniela Dieplinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Herbert Dieplinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Sylvia Ecker', false);
INSERT INTO "user" (name, is_guest) VALUES ('Raphael Eichhorn', false);
INSERT INTO "user" (name, is_guest) VALUES ('Geza Eisserer', false);
INSERT INTO "user" (name, is_guest) VALUES ('Helga Engelbrechtslehner', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Manuela Firmötz', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Maj-Britt Fobian', false);
INSERT INTO "user" (name, is_guest) VALUES ('Elisabeth Fölser', false);
INSERT INTO "user" (name, is_guest) VALUES ('Larissa Freimuth', false);
INSERT INTO "user" (name, is_guest) VALUES ('Nina Füreder', false);
INSERT INTO "user" (name, is_guest) VALUES ('Bettina Fürlinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Heinz Gessl', false);
INSERT INTO "user" (name, is_guest) VALUES ('Helmut Gidl', false);
INSERT INTO "user" (name, is_guest) VALUES ('Eva-Maria Gruber', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Christian Gusenbauer', false, true);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Adolf Hainschink', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Maria Hainschink', false);
INSERT INTO "user" (name, is_guest) VALUES ('Leon Hattmannsdorfer', false);
INSERT INTO "user" (name, is_guest) VALUES ('Andrea Heinemann', false);
INSERT INTO "user" (name, is_guest) VALUES ('Bernhard Heinemann', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Matthias Höfer', false, true);
INSERT INTO "user" (name, is_guest, is_cox, is_admin) VALUES ('Philipp Hofer', false, true, true);
INSERT INTO "user" (name, is_guest) VALUES ('Thomas Hoffelner', false);
INSERT INTO "user" (name, is_guest) VALUES ('Inge Höllersberger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Harald Iro', false);
INSERT INTO "user" (name, is_guest) VALUES ('Claudia Jagersberger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Melanie Keplinger', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Ernst Klima', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Herta Klima', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Thomas Klima', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Margit Bencic', false);
INSERT INTO "user" (name, is_guest) VALUES ('Ingrid Klug', false);
INSERT INTO "user" (name, is_guest) VALUES ('Max Knauseder', false);
INSERT INTO "user" (name, is_guest) VALUES ('Paul Knauseder', false);
INSERT INTO "user" (name, is_guest) VALUES ('Harald Koch', false);
INSERT INTO "user" (name, is_guest) VALUES ('Johann Koci', false);
INSERT INTO "user" (name, is_guest) VALUES ('Alexander Koll', false);
INSERT INTO "user" (name, is_guest) VALUES ('Gudrun Koppauer', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Daniel Kortschak', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Manfred Krausbar', false);
INSERT INTO "user" (name, is_guest) VALUES ('Verena Kriechbaum', false);
INSERT INTO "user" (name, is_guest) VALUES ('Martin Kugler', false);
INSERT INTO "user" (name, is_guest) VALUES ('Fabian Kunz', false);
INSERT INTO "user" (name, is_guest) VALUES ('Heinrich Kupka', false);
INSERT INTO "user" (name, is_guest) VALUES ('Anna Kuthan', false);
INSERT INTO "user" (name, is_guest) VALUES ('Moritz Lach', false);
INSERT INTO "user" (name, is_guest) VALUES ('Claudia Lackinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Erich Lehner', false);
INSERT INTO "user" (name, is_guest) VALUES ('Roland Lehner', false);
INSERT INTO "user" (name, is_guest) VALUES ('Matthias List', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Manfred Meindl', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Michael Messner', false);
INSERT INTO "user" (name, is_guest) VALUES ('Iris Pfoser', false);
INSERT INTO "user" (name, is_guest) VALUES ('Franz Poddemski', false);
INSERT INTO "user" (name, is_guest) VALUES ('Laurent Pramhas', false);
INSERT INTO "user" (name, is_guest) VALUES ('Carmen Pusch', false);
INSERT INTO "user" (name, is_guest) VALUES ('Heinz Radinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Franz Reisinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Hermann Remplbauer', false);
INSERT INTO "user" (name, is_guest) VALUES ('Burkhard Riss', false);
INSERT INTO "user" (name, is_guest) VALUES ('Julius Riss', false);
INSERT INTO "user" (name, is_guest) VALUES ('Christiane Rückerl', false);
INSERT INTO "user" (name, is_guest) VALUES ('Andrea Sageder', false);
INSERT INTO "user" (name, is_guest) VALUES ('Birgit Sageder', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Michael Sageder', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Niklas Sageder', false);
INSERT INTO "user" (name, is_guest) VALUES ('Sebastian Sageder', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Siegfried Sageder', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Lisa-Maria Schedlberger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Max Schellenbacher', false);
INSERT INTO "user" (name, is_guest) VALUES ('Klaus Schlögl', false);
INSERT INTO "user" (name, is_guest) VALUES ('Wolfgang Schlögl', false);
INSERT INTO "user" (name, is_guest) VALUES ('Gabriele Schwarz', false);
INSERT INTO "user" (name, is_guest) VALUES ('Caroline Schwendinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Kristina Schwendinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Martina Schwendinger', false);
INSERT INTO "user" (name, is_guest) VALUES ('Stephan Siegl', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Sandra Sollberger', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Michael Stadler', false);
INSERT INTO "user" (name, is_guest) VALUES ('Edith Steinacker', false);
INSERT INTO "user" (name, is_guest) VALUES ('Ignaz Alois Stütz', false);
INSERT INTO "user" (name, is_guest) VALUES ('Ilona Stütz', false);
INSERT INTO "user" (name, is_guest) VALUES ('Elisabeth Totschnig', false);
INSERT INTO "user" (name, is_guest) VALUES ('Atharva Tyagi', false);
INSERT INTO "user" (name, is_guest) VALUES ('Friedrich Weber', false);
INSERT INTO "user" (name, is_guest) VALUES ('Isabella Wessely', false);
INSERT INTO "user" (name, is_guest, is_cox) VALUES ('Lukas Wessely', false, true);
INSERT INTO "user" (name, is_guest) VALUES ('Erich Zauner', false);
INSERT INTO "user" (name, is_guest) VALUES ('Renate Zehetner', false);
INSERT INTO "user" (name, is_guest) VALUES ('Augustin Zuljevic', false);

View File

@ -22,7 +22,6 @@ pub struct User {
#[derive(Debug)] #[derive(Debug)]
pub enum LoginError { pub enum LoginError {
SqlxError(sqlx::Error),
InvalidAuthenticationCombo, InvalidAuthenticationCombo,
NotLoggedIn, NotLoggedIn,
NotAnAdmin, NotAnAdmin,
@ -30,11 +29,6 @@ pub enum LoginError {
NoPasswordSet(User), NoPasswordSet(User),
} }
impl From<sqlx::Error> for LoginError {
fn from(sqlx_error: sqlx::Error) -> Self {
Self::SqlxError(sqlx_error)
}
}
impl User { impl User {
pub async fn update(&self, db: &SqlitePool, is_cox: bool, is_admin: bool, is_guest: bool) { pub async fn update(&self, db: &SqlitePool, is_cox: bool, is_admin: bool, is_guest: bool) {
sqlx::query!( sqlx::query!(
@ -60,36 +54,38 @@ impl User {
.is_ok() .is_ok()
} }
pub async fn find_by_id(db: &SqlitePool, id: i32) -> Result<Self, sqlx::Error> { pub async fn find_by_id(db: &SqlitePool, id: i32) -> Option<Self> {
let user: User = sqlx::query_as!( Some(
User, sqlx::query_as!(
" User,
"
SELECT id, name, pw, is_cox, is_admin, is_guest SELECT id, name, pw, is_cox, is_admin, is_guest
FROM user FROM user
WHERE id like ? WHERE id like ?
", ",
id id
)
.fetch_one(db)
.await
.ok()?,
) )
.fetch_one(db)
.await?;
Ok(user)
} }
async fn find_by_name(db: &SqlitePool, name: String) -> Result<Self, sqlx::Error> { async fn find_by_name(db: &SqlitePool, name: String) -> Option<Self> {
let user: User = sqlx::query_as!( Some(
User, sqlx::query_as!(
" User,
"
SELECT id, name, pw, is_cox, is_admin, is_guest SELECT id, name, pw, is_cox, is_admin, is_guest
FROM user FROM user
WHERE name like ? WHERE name like ?
", ",
name name
)
.fetch_one(db)
.await
.ok()?,
) )
.fetch_one(db)
.await?;
Ok(user)
} }
fn get_hashed_pw(pw: &str) -> String { fn get_hashed_pw(pw: &str) -> String {
@ -102,7 +98,12 @@ WHERE name like ?
} }
pub async fn login(db: &SqlitePool, name: String, pw: String) -> Result<Self, LoginError> { pub async fn login(db: &SqlitePool, name: String, pw: String) -> Result<Self, LoginError> {
let user = User::find_by_name(db, name).await?; let user = match User::find_by_name(db, name).await {
Some(user) => user,
None => {
return Err(LoginError::InvalidAuthenticationCombo); // Username not found
}
};
match user.pw.clone() { match user.pw.clone() {
Some(user_pw) => { Some(user_pw) => {

View File

@ -21,14 +21,14 @@ async fn index(db: &State<SqlitePool>, admin: AdminUser) -> Template {
async fn resetpw(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<Redirect> { async fn resetpw(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<Redirect> {
let user = User::find_by_id(db, user).await; let user = User::find_by_id(db, user).await;
match user { match user {
Ok(user) => { Some(user) => {
user.reset_pw(db).await; user.reset_pw(db).await;
Flash::success( Flash::success(
Redirect::to("/admin/user"), Redirect::to("/admin/user"),
format!("Successfully reset pw of {}", user.name), format!("Successfully reset pw of {}", user.name),
) )
} }
Err(_) => Flash::error(Redirect::to("/admin/user"), "User does not exist"), None => Flash::error(Redirect::to("/admin/user"), "User does not exist"),
} }
} }
@ -47,7 +47,7 @@ async fn update(
_admin: AdminUser, _admin: AdminUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
let user = User::find_by_id(db, data.id).await; let user = User::find_by_id(db, data.id).await;
let Ok(user) = user else { let Some(user) = user else {
return Flash::error( return Flash::error(
Redirect::to("/admin/user"), Redirect::to("/admin/user"),
format!("User with ID {} does not exist!", data.id), format!("User with ID {} does not exist!", data.id),

View File

@ -77,7 +77,7 @@ async fn updatepw(
cookies: &CookieJar<'_>, cookies: &CookieJar<'_>,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
let user = User::find_by_id(db, updatepw.userid).await; let user = User::find_by_id(db, updatepw.userid).await;
let Ok(user) = user else{ let Some(user) = user else{
return Flash::error( return Flash::error(
Redirect::to("/auth"), Redirect::to("/auth"),
format!("User with ID {} does not exist!", updatepw.userid), format!("User with ID {} does not exist!", updatepw.userid),

View File

@ -83,32 +83,32 @@ pub fn start(db: SqlitePool) -> Rocket<Build> {
.mount("/auth", auth::routes()) .mount("/auth", auth::routes())
.mount("/cox", cox::routes()) .mount("/cox", cox::routes())
.mount("/admin", admin::routes()) .mount("/admin", admin::routes())
.mount("/public", FileServer::from("static/")) .mount("/public", FileServer::from("./static/"))
.register("/", catchers![unauthorized_error]) .register("/", catchers![unauthorized_error])
.attach(Template::fairing()) .attach(Template::fairing())
} }
//#[cfg(test)] #[cfg(test)]
//mod test { mod test {
// use crate::testdb; use crate::testdb;
//
// use super::start; use super::start;
// use rocket::http::Status; use rocket::http::Status;
// use rocket::local::asynchronous::Client; use rocket::local::asynchronous::Client;
// use rocket::uri; use rocket::uri;
// use sqlx::SqlitePool; use sqlx::SqlitePool;
//
// #[sqlx::test] #[sqlx::test]
// fn test_not_logged_in() { fn test_not_logged_in() {
// let pool = testdb!(); let pool = testdb!();
//
// let client = Client::tracked(start(pool)) let client = Client::tracked(start(pool))
// .await .await
// .expect("valid rocket instance"); .expect("valid rocket instance");
// let response = client.get(uri!(super::index)).dispatch().await; let response = client.get(uri!(super::index)).dispatch().await;
//
// assert_eq!(response.status(), Status::SeeOther); assert_eq!(response.status(), Status::SeeOther);
// let location = response.headers().get("Location").next().unwrap(); let location = response.headers().get("Location").next().unwrap();
// assert_eq!(location, "/auth"); assert_eq!(location, "/auth");
// } }
//} }