Initial commit

This commit is contained in:
fabolous005 2024-11-12 15:04:05 +01:00
parent 1946a2ca96
commit 8ee1039de9
4 changed files with 80 additions and 0 deletions

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "samba-login"
version = "0.1.0"
edition = "2021"
[dependencies]
rocket = "0.5.1"
rocket_dyn_templates = { version = "0.2.0", features = ["tera"] }
serde = { version = "1.0.215", features = ["derive"] }

41
src/main.rs Normal file
View File

@ -0,0 +1,41 @@
#[macro_use] extern crate rocket;
use rocket::form::Form;
use rocket::form::FromForm;
use rocket_dyn_templates::{Template, context};
#[derive(FromForm)]
struct LoginData {
username: String,
password: String,
}
#[post("/login", data = "<login_data>")]
fn login(login_data: Form<LoginData>) -> Template {
let correct_username = "user";
let correct_password = "password";
let message = if login_data.username == correct_username && login_data.password == correct_password {
// On successful login, you can perform actions here like creating directories.
println!("Login successful: performing server-side actions.");
"Login successful! Directories have been created."
} else {
"Invalid username or password."
};
Template::render("result", context! { message })
}
#[get("/")]
fn index() -> Template {
Template::render("index", context! {})
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![index, login])
.attach(Template::fairing())
}

20
templates/index.html.tera Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form action="/login" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br>
<input type="submit" value="Login">
</form>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Result</title>
</head>
<body>
<h1>{{ message }}</h1>
</body>
</html>