Created Administrative Sign in screen

This commit is contained in:
Samuel Walker 2024-07-12 21:11:52 -06:00
parent 2c082627e2
commit 8b88dffd84
14 changed files with 221 additions and 7 deletions

View File

@ -21,11 +21,8 @@ zip-extract = "0.1.3"
dirs = "5.0.1"
gethostname = "0.4.3"
self_update = "0.40.0"
parking_lot = "0.12.3"
[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
[[bin]]
name = "FCLauncher"
path = "src/main.rs"

View File

@ -0,0 +1,15 @@
use crate::ftp::{self, test_cred};
static USERNAME: parking_lot::Mutex<String> = parking_lot::const_mutex(String::new());
static PASSWORD: parking_lot::Mutex<String> = parking_lot::const_mutex(String::new());
#[tauri::command]
pub fn login(username: String, password: String, window: tauri::Window) {
if(test_cred(username.as_str(), password.as_str())){
*USERNAME.lock() = username;
*PASSWORD.lock() = password;
window.emit("Login_Success", {});
}else{
window.emit("Login_Failed", {});
}
}

View File

@ -12,6 +12,10 @@ fn ftp_connection_anonymous() -> Result<NativeTlsFtpStream, FtpError>{
ftp_connection("anonymous", "anonymous@")
}
pub fn test_cred(username: &str, password: &str) -> bool{
return ftp_connection(username, password).is_ok();
}
fn ftp_connection(username: &str, password: &str) -> Result<NativeTlsFtpStream, FtpError>{
let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21").unwrap_or_else(|err|
@ -20,10 +24,13 @@ fn ftp_connection(username: &str, password: &str) -> Result<NativeTlsFtpStream,
let cert = include_bytes!("../res/vsftpd.crt");
let cert = Certificate::from_pem(cert).unwrap();
let mut ftp_stream = ftp_stream.into_secure(NativeTlsConnector::from(TlsConnector::builder().add_root_certificate(cert).build().unwrap()), "gitea.piwalker.net").unwrap();
ftp_stream.login("anonymous", "anonymous@").map(|_| Ok(ftp_stream)).unwrap()
let result = ftp_stream.login(username, password);
if result.is_ok() {
return Ok(ftp_stream);
}
Err(result.unwrap_err())
}
pub fn ftp_retr(window: Option<tauri::Window>, file: PathBuf , mut writer: impl Write, mut callback: impl FnMut(Option<tauri::Window>, usize, usize)) -> Result<bool, FtpError> {
let mut ftp_stream = ftp_connection_anonymous().unwrap();
let file = file.to_str().unwrap().replace("\\", "/");

View File

@ -15,6 +15,7 @@ mod prism;
mod system_dirs;
mod util;
mod modpack;
mod admin;
#[derive(Serialize, Deserialize)]
struct ModpackEntry{
@ -33,7 +34,7 @@ fn main() {
modpack::get_modpacks();
//prism::install_prism();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, modpack::get_modpacks, modpack::launch_modpack, prism::launch_prism, prism::install_prism])
.invoke_handler(tauri::generate_handler![greet, modpack::get_modpacks, modpack::launch_modpack, prism::launch_prism, prism::install_prism, admin::login])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

30
FCLauncher/src/Admin.html Normal file
View File

@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-width=cover" />
<title>Tauri App</title>
<script type="module" src="/admin.js" defer></script>
</head>
<body>
<div class="Logo">
<button id="back"></button>
<img src="assets/Title.png" alt="Title" id="Title">
</div>
<div class="progress">
<div class="progressFinished"></div>
</div>
<div class="container" data-bs-theme="dark">
<h1>Administration</h1>
</div>
</body>
</html>

33
FCLauncher/src/Login.html Normal file
View File

@ -0,0 +1,33 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-width=cover" />
<title>Tauri App</title>
<script type="module" src="/login.js" defer></script>
</head>
<body>
<div class="Logo">
<button id="back"></button>
<img src="assets/Title.png" alt="Title" id="Title">
</div>
<div class="container" data-bs-theme="dark">
<p class="Error" id="Incorrect">Username or Password is incorrect!</p>
<input id="Username" placeholder="Username" />
<input id="Password" placeholder="Password" type="password" />
<div class="loginButtons">
<button id="Cancel">Cancel</button>
<button id="Login">Login</button>
</div>
</div>
</body>
</html>

36
FCLauncher/src/admin.js Normal file
View File

@ -0,0 +1,36 @@
const { invoke } = window.__TAURI__.tauri;
const { listen } = window.__TAURI__.event;
const { ask } = window.__TAURI__.dialog;
const downBar = document.querySelector(".progressFinished");
//import { listen } from '@tauri-apps/api';
const download_progress = listen("download_progress", (progress) => {
console.log("Downloading");
//console.log("Downloaded "+progress.payload.downloaded/(1024*1024) +"MB / " + progress.payload.total/(1024*1024) + "MB");
let downProgress = (progress.payload.downloaded/(1024*1024)).toFixed(2);
let downTotal = (progress.payload.total/(1024*1024)).toFixed(2);
document.getElementById("download_name").textContent = "Downloading "+progress.payload.download_name;
document.getElementById("download_progress").textContent = downProgress + "MB / "+downTotal+"MB";
document.getElementById("launchGame").disabled = true;
downBar.style.width = `${(progress.payload.downloaded / progress.payload.total) * 100}%`;
document.querySelector(".progress").style.visibility = "visible";
});
const download_finished = listen("download_finished", (event) => {
document.getElementById("download_name").textContent = "";
document.getElementById("download_progress").textContent = "";
document.getElementById("launchGame").disabled = false;
document.getElementById("launchGame").textContent ="Launch Minecraft";
downBar.style.width = 0;
document.querySelector(".progress").style.visibility = "hidden";
});
window.addEventListener("DOMContentLoaded", () => {
document.getElementById("back").addEventListener("click", back);
});
function back(){
window.location.href = "index.html";
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -15,6 +15,7 @@
<body>
<div class="Logo">
<button id="settings"></button>
<img src="assets/Title.png" alt="Title" id="Title">
</div>
<div class="progress">

37
FCLauncher/src/login.js Normal file
View File

@ -0,0 +1,37 @@
const { invoke } = window.__TAURI__.tauri;
const { listen } = window.__TAURI__.event;
const { ask } = window.__TAURI__.dialog;
const downBar = document.querySelector(".progressFinished");
//import { listen } from '@tauri-apps/api';
window.addEventListener("DOMContentLoaded", () => {
document.getElementById("back").addEventListener("click", back);
document.getElementById("Cancel").addEventListener("click", back);
document.getElementById("Login").addEventListener("click", login);
document.getElementById("Password").addEventListener("keypress", keypress);
});
function back(){
window.location.href = "index.html";
}
function login(){
invoke("login", { username: document.getElementById("Username").value, password: document.getElementById("Password").value});
}
function keypress(e){
if(e.keyCode === 13){
e.preventDefault();
login();
}
}
const failed = listen("Login_Failed", (event) => {
document.getElementById("Incorrect").style.visibility = "visible";
})
const success = listen("Login_Success", (event) => {
window.location.href = "Admin.html";
})

View File

@ -33,6 +33,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("launchGame").addEventListener("click", gameLaunch);
document.getElementById("prism").addEventListener("click", prism);
document.getElementById("settings").addEventListener("click", login);
document.getElementById("back").addEventListener("click", back);
});
function packSelect() {
@ -40,6 +42,15 @@ function packSelect() {
}
function login(){
window.location.href = "Login.html";
}
function back(){
console.log("test");
window.location.href = "index.html";
}
function load() {
console.log("loading");
var dropdown = document.getElementById("Modpacks");

View File

@ -228,3 +228,49 @@ button {
display: block;
margin: 0.5em;
}
#settings{
width: 2em;
height: 2.5em;
top: 5px;
left: 5px;
float: right;
position: absolute;
background-image: url('assets/settings.png');
background-size:cover;
background-repeat: no-repeat;
}
#back{
width: 2em;
height: 2.5em;
top: 5px;
left: 5px;
float: right;
position: absolute;
background-image: url('assets/back.png');
background-size:cover;
background-repeat: no-repeat;
}
.container input{
margin: 0.5em;
width: 45%
}
.loginButtons{
display: flex;
margin: 0.5em;
flex-direction: row;
margin-left: auto;
margin-right: auto;
width: 50%;
gap: .5em;
}
.Error{
color: black;
background-color: red;
margin: 0;
visibility: hidden;
}