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 @@ + + +
+ + + + +If the creation fails, please wait a minute and try again. The database server might still be starting at the time.
+Redirecting...
+