refactor: clean up unused code

This commit is contained in:
Max Hohlfeld 2024-06-06 22:21:04 +02:00
parent 87fc7e29d8
commit 8bf606b4d7
7 changed files with 0 additions and 110 deletions

View File

@ -1,4 +1,2 @@
pub mod routes;
pub mod utils;
pub use routes::init;

View File

@ -1,18 +0,0 @@
use actix_web::{web, HttpResponse, Responder};
use askama::Template;
use sqlx::PgPool;
#[derive(Template)]
#[template(path = "register.html")]
struct RegisterTemplate {
// roles: Vec<Role>,
}
#[actix_web::get("/register")]
async fn route(pool: web::Data<PgPool>) -> impl Responder {
let bla = RegisterTemplate { };
HttpResponse::Ok().body(bla.render().unwrap())
}

View File

@ -1,9 +0,0 @@
mod get_register;
mod post_register;
use actix_web::web;
pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(self::get_register::route);
cfg.service(self::post_register::route);
}

View File

@ -1,54 +0,0 @@
use actix_web::{http::header::LOCATION, web, HttpResponse, Responder};
use serde::Deserialize;
use sqlx::PgPool;
use crate::{auth::utils::generate_salt_and_hash_plain_password, models::User};
#[derive(Deserialize)]
struct RegisterForm {
pub name: String,
pub email: String,
pub password: String,
pub role_id: u8,
pub function_id: u8,
pub area_id: i32,
}
#[actix_web::post("/register")]
async fn route(
web::Form(form): web::Form<RegisterForm>,
pool: web::Data<PgPool>,
) -> impl Responder {
let (hash, salt) = generate_salt_and_hash_plain_password(&form.password).unwrap();
let role = match form.role_id.try_into() {
Ok(role) => role,
Err(_) => return HttpResponse::BadRequest().body("fsdf"),
};
let function = match form.function_id.try_into() {
Ok(function) => function,
Err(_) => return HttpResponse::BadRequest().body("fsdf"),
};
let result = User::create(
pool.get_ref(),
&form.name,
&form.email,
&hash,
&salt,
role,
function,
form.area_id,
)
.await;
match result {
Ok(_) => {
return HttpResponse::PermanentRedirect()
.insert_header((LOCATION, "/"))
.finish()
}
Err(err) => return HttpResponse::BadRequest().body(err.to_string()),
}
}

View File

@ -1,4 +1,3 @@
use actix_identity::Identity;
use actix_web::{web, HttpResponse, Responder};
use askama::Template;
use chrono::{NaiveDate, Utc};

View File

@ -116,7 +116,6 @@ async fn main() -> anyhow::Result<()> {
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone()))
.configure(auth::init)
.configure(calendar::init)
.configure(endpoints::init)
.wrap(middleware::RedirectToLogin)

View File

@ -1,25 +0,0 @@
<html>
<head>
<title>Brass - Register</title>
</head>
<body>
<h1>Brass - Registrierung</h1>
<p>Gib dein Nutzernamen und das Passwort ein:</p>
<form>
<label for="name">Nutzername:</label>
<input name="name" type="text">
<label for="password">Passwort:</label>
<input name="password" type="password">
<label for="role">Rolle:</label>
<select name="role">
<option value="1">Staff</option>
<option value="10">AreaManager</option>
<option value="100">Admin</option>
</select>
<input type="submit" formmethod="post">
</form>
</body>
</html>