CoolFace
Apppublic

gcoder824/subdocflow-smooth-document-request-system

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
login.php101 linesDownload Raw Back to root
1```php2<?php3session_start();4require_once 'config.php';5 6if (isset($_SESSION['user_id'])) {7    header("Location: " . ($_SESSION['role'] == 'admin' ? 'admin_dashboard.php' : 'user_dashboard.php'));8    exit;9}10 11$error = '';12if ($_SERVER['REQUEST_METHOD'] == 'POST') {13    $username = trim($_POST['username']);14    $password = trim($_POST['password']);15 16    if (empty($username) || empty($password)) {17        $error = 'Please enter both username and password';18    } else {19        $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");20        $stmt->execute([$username]);21        $user = $stmt->fetch();22 23        if ($user && password_verify($password, $user['password'])) {24            $_SESSION['user_id'] = $user['id'];25            $_SESSION['username'] = $user['username'];26            $_SESSION['role'] = $user['role'];27            $_SESSION['name'] = $user['first_name'] . ' ' . $user['last_name'];28            29            header("Location: " . ($user['role'] == 'admin' ? 'admin_dashboard.php' : 'user_dashboard.php'));30            exit;31        } else {32            $error = 'Invalid username or password';33        }34    }35}36?>37<!DOCTYPE html>38<html lang="en">39<head>40    <meta charset="UTF-8">41    <meta name="viewport" content="width=device-width, initial-scale=1.0">42    <title>Login - SubDocFlow</title>43    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">44    <script src="https://cdn.tailwindcss.com"></script>45    <script src="https://unpkg.com/feather-icons"></script>46</head>47<body class="bg-gray-50">48    <div class="min-h-screen flex items-center justify-center">49        <div class="bg-white p-8 rounded-lg shadow-md w-full max-w-md">50            <div class="text-center mb-8">51                <i data-feather="file-text" class="mx-auto text-indigo-600 h-10 w-10"></i>52                <h1 class="text-2xl font-bold text-gray-900 mt-2">Welcome back</h1>53                <p class="text-gray-600">Sign in to your account</p>54            </div>55            56            <?php if ($error): ?>57                <div class="mb-4 p-4 bg-red-50 text-red-600 rounded-md">58                    <?php echo htmlspecialchars($error); ?>59                </div>60            <?php endif; ?>61 62            <form method="POST" class="space-y-6">63                <div>64                    <label for="username" class="block text-sm font-medium text-gray-700">Username</label>65                    <input type="text" id="username" name="username" required66                        class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">67                </div>68                <div>69                    <label for="password" class="block text-sm font-medium text-gray-700">Password</label>70                    <input type="password" id="password" name="password" required71                        class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">72                </div>73                <div class="flex items-center justify-between">74                    <div class="flex items-center">75                        <input id="remember-me" name="remember-me" type="checkbox"76                            class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">77                        <label for="remember-me" class="ml-2 block text-sm text-gray-700">Remember me</label>78                    </div>79                    <div class="text-sm">80                        <a href="forgot_password.php" class="font-medium text-indigo-600 hover:text-indigo-500">Forgot password?</a>81                    </div>82                </div>83                <div>84                    <button type="submit"85                        class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">86                        Sign in87                    </button>88                </div>89                <div class="text-center text-sm">90                    <span class="text-gray-600">Don't have an account? </span>91                    <a href="register.php" class="font-medium text-indigo-600 hover:text-indigo-500">Sign up</a>92                </div>93            </form>94        </div>95    </div>96    <script>97        feather.replace();98    </script>99</body>100</html>101```