diff --git a/app-code/api/login/redirect.php b/app-code/api/login/redirect.php new file mode 100644 index 0000000..3a318d1 --- /dev/null +++ b/app-code/api/login/redirect.php @@ -0,0 +1,21 @@ + true, + 'message' => 'fully_logged_in', + 'redirect' => $send_to + ]; + echo(json_encode($data)); +}else{ + //we have to send the user around :) + //load his auth methods. then send the first one. if he auths there he will be send back here and we can send him to the next auth method + $username=$_SESSION["username"]; +} + + +?> diff --git a/app-code/api/login/set_username.php b/app-code/api/login/set_username.php new file mode 100644 index 0000000..eb8c546 --- /dev/null +++ b/app-code/api/login/set_username.php @@ -0,0 +1,4 @@ + diff --git a/app-code/api/register/register_user.php b/app-code/api/register/register_user.php new file mode 100644 index 0000000..53bde20 --- /dev/null +++ b/app-code/api/register/register_user.php @@ -0,0 +1,111 @@ + false, + 'message' => 'Database connection failed: ' . mysqli_connect_error() + ]); + exit; +} + +// Check if the request method is POST +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // Get the JSON input + $input = file_get_contents('php://input'); + $data = json_decode($input, true); + + // Validate input + if (!isset($data['username']) || !isset($data['password'])) { + echo json_encode([ + 'success' => false, + 'message' => 'Invalid input. Username and password are required.' + ]); + exit; + } + + $username = trim($data['username']); + $email = trim($data['email']); + $password = trim($data['password']); + $telegram_id = trim($data['telegram']); + + // Check for empty fields + if (empty($username) || empty($password)) { + echo json_encode([ + 'success' => false, + 'message' => 'Username and password are required.' + ]); + exit; + } + + // Check if the username already exists + $sql = "SELECT id FROM users WHERE username = ?"; + $stmt = mysqli_prepare($conn, $sql); + mysqli_stmt_bind_param($stmt, 's', $username); + mysqli_stmt_execute($stmt); + mysqli_stmt_store_result($stmt); + + if (mysqli_stmt_num_rows($stmt) > 0) { + echo json_encode([ + 'success' => false, + 'message' => 'Username already taken.' + ]); + mysqli_stmt_close($stmt); + exit; + } + mysqli_stmt_close($stmt); + + // Check if the email already exists + $sql = "SELECT id FROM users WHERE email = ?"; + $stmt = mysqli_prepare($conn, $sql); + mysqli_stmt_bind_param($stmt, 's', $email); + mysqli_stmt_execute($stmt); + mysqli_stmt_store_result($stmt); + + if (mysqli_stmt_num_rows($stmt) > 0 && $email!="") { + echo json_encode([ + 'success' => false, + 'message' => 'Email already registered.' + ]); + mysqli_stmt_close($stmt); + exit; + } + mysqli_stmt_close($stmt); + + $pepper=bin2hex(random_bytes(32)); + // Hash the password / a salt is added automaticly + $hashedPassword = password_hash($password.$pepper, PASSWORD_BCRYPT); + + // Insert the user into the database + $sql = "INSERT INTO users (username, email, password, telegram_id, pepper, auth_method_enabled_pw, auth_method_required_pw, auth_method_enabled_passkey, auth_method_required_passkey, auth_method_enabled_2fa, auth_method_required_2fa,auth_method_keepmeloggedin_enabled) VALUES (?, ?, ?, ?, ?, 1, 1,0,0,0,0,0)"; + $stmt = mysqli_prepare($conn, $sql); + mysqli_stmt_bind_param($stmt, 'sssss', $username, $email, $hashedPassword, $telegram_id, $pepper); + if (mysqli_stmt_execute($stmt)) { + echo json_encode([ + 'success' => true, + 'message' => 'Registration successful!' + ]); + } else { + echo json_encode([ + 'success' => false, + 'message' => 'Registration failed. Please try again later.' + ]); + } + mysqli_stmt_close($stmt); +} else { + // Invalid request method + echo json_encode([ + 'success' => false, + 'message' => 'Invalid request method. Only POST is allowed.' + ]); +} + +// Close the database connection +mysqli_close($conn); +?> diff --git a/app-code/assets/components.php b/app-code/assets/components.php new file mode 100644 index 0000000..8fabadb --- /dev/null +++ b/app-code/assets/components.php @@ -0,0 +1,9 @@ + + + + + + +'); +?> diff --git a/app-code/index.php b/app-code/index.php new file mode 100644 index 0000000..fcb9e66 --- /dev/null +++ b/app-code/index.php @@ -0,0 +1,89 @@ + + + + + + + + Jakach Login + + + +
+
+
+ +
+
+

Jakach Login

+ +
+ +
+ +
+ +
+ + + + Account Erstellen +
+
+
+
+
+
+
+ + + + + diff --git a/app-code/install/create_db.php b/app-code/install/create_db.php new file mode 100644 index 0000000..da9313a --- /dev/null +++ b/app-code/install/create_db.php @@ -0,0 +1,115 @@ + + + + + + + Jakach-Login install + + + +
+
+
+
+
+

We are creating the databases used in jakach-login, please stand by

+
+
+

If the creation fails, please wait a minute and try again. The database server might still be starting at the time.

+
+
+ connect_error) { + $success=0; + die("Connection failed: " . $conn->connect_error); + } + + // Create database + $sql = "CREATE DATABASE IF NOT EXISTS $DB_DATABASE"; + if ($conn->query($sql) === TRUE) { + echo '
'; + } else { + $success=0; + echo '
'; + } + + $conn->close(); + + // Connect to the new database + $conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD,$DB_DATABASE); + + // Check connection + if ($conn->connect_error) { + $success=0; + die("Connection failed: " . $conn->connect_error); + } + + // Create user table + $sql="CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(255) NOT NULL UNIQUE, + public_key TEXT DEFAULT '', + credential_id TEXT DEFAULT '', + counter INT DEFAULT 0, + 2fa VARCHAR(255), + email VARCHAR(255), + password VARCHAR(500), + pepper VARCHAR(255), + telegram_id VARCHAR(255), + permissions VARCHAR(255), + color_profile INT, + auth_key VARCHAR(255), + keepmeloggedin_token VARCHAR(255), + auth_method_keepmeloggedin_enabled INT, + auth_method_enabled_2fa INT, + auth_method_enabled_pw INT, + auth_method_enabled_passkey INT, + auth_method_required_2fa INT, + auth_method_required_pw INT, + auth_method_required_passkey INT + );"; + + + if ($conn->query($sql) === TRUE) { + echo '
'; + } else { + $success=0; + echo '
'; + } + + + + if($success!==1){ + echo '
'; + }else{ + echo '
'; + } + + $conn->close(); + ?> +
+
+
+
+ + diff --git a/app-code/login/index.php b/app-code/login/index.php new file mode 100644 index 0000000..4dffda2 --- /dev/null +++ b/app-code/login/index.php @@ -0,0 +1,55 @@ + + + + + + + Jakach Login + + + +
+ +
+ Loading... +
+ +

Redirecting...

+
+ + + diff --git a/app-code/register/index.php b/app-code/register/index.php new file mode 100644 index 0000000..9b34990 --- /dev/null +++ b/app-code/register/index.php @@ -0,0 +1,156 @@ + + + + + + + Jakach Login + + + +
+
+
+
+
+

Register

+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+ +
+
+
+
+ + + +