Simrandhiman commited on
Commit
62b7733
·
verified ·
1 Parent(s): b14b782

Upload 8 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -1,11 +1,11 @@
1
- ---
2
- title: Flaskportfolio
3
- emoji: 😻
4
- colorFrom: blue
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
8
- license: apache-2.0
9
- ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
1
+ # Flask Login & Signup Page
 
 
 
 
 
 
 
 
2
 
3
+ Simple login/signup system with Flask, styled with CSS.
4
+
5
+ ## Run Locally
6
+ ```bash
7
+ docker build -t flask-login-signup .
8
+ docker run -p 7860:7860 flask-login-signup
9
+ ```
10
+
11
+ Open: [http://localhost:7860](http://localhost:7860)
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for, session
2
+
3
+ app = Flask(__name__)
4
+ app.secret_key = "supersecretkey" # replace with env var in production
5
+
6
+ # Simple in-memory user store (replace with DB in production)
7
+ users = {"admin": "password123"}
8
+
9
+ @app.route("/", methods=["GET", "POST"])
10
+ def login():
11
+ if request.method == "POST":
12
+ username = request.form["username"]
13
+ password = request.form["password"]
14
+
15
+ if username in users and users[username] == password:
16
+ session["user"] = username
17
+ return redirect(url_for("dashboard"))
18
+ else:
19
+ return render_template("login.html", error="Invalid credentials")
20
+
21
+ return render_template("login.html")
22
+
23
+
24
+ @app.route("/signup", methods=["GET", "POST"])
25
+ def signup():
26
+ if request.method == "POST":
27
+ username = request.form["username"]
28
+ password = request.form["password"]
29
+
30
+ if username in users:
31
+ return render_template("signup.html", error="User already exists")
32
+ else:
33
+ users[username] = password
34
+ session["user"] = username
35
+ return redirect(url_for("dashboard"))
36
+
37
+ return render_template("signup.html")
38
+
39
+
40
+ @app.route("/dashboard")
41
+ def dashboard():
42
+ if "user" not in session:
43
+ return redirect(url_for("login"))
44
+ return render_template("dashboard.html", user=session["user"])
45
+
46
+
47
+ @app.route("/logout")
48
+ def logout():
49
+ session.pop("user", None)
50
+ return redirect(url_for("login"))
51
+
52
+
53
+ if __name__ == "__main__":
54
+ app.run(host="0.0.0.0", port=7860)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ flask
static/css/style.css ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: Arial, sans-serif;
3
+ background: #f2f2f2;
4
+ display: flex;
5
+ justify-content: center;
6
+ align-items: center;
7
+ height: 100vh;
8
+ margin: 0;
9
+ }
10
+
11
+ .container {
12
+ background: white;
13
+ padding: 2rem;
14
+ border-radius: 10px;
15
+ box-shadow: 0 4px 8px rgba(0,0,0,0.1);
16
+ width: 300px;
17
+ text-align: center;
18
+ }
19
+
20
+ input {
21
+ width: 90%;
22
+ padding: 10px;
23
+ margin: 10px 0;
24
+ border: 1px solid #ccc;
25
+ border-radius: 5px;
26
+ }
27
+
28
+ button {
29
+ background: #007BFF;
30
+ color: white;
31
+ border: none;
32
+ padding: 10px;
33
+ width: 100%;
34
+ border-radius: 5px;
35
+ cursor: pointer;
36
+ }
37
+
38
+ button:hover {
39
+ background: #0056b3;
40
+ }
41
+
42
+ .error {
43
+ color: red;
44
+ font-size: 0.9em;
45
+ }
46
+
47
+ .logout {
48
+ display: inline-block;
49
+ margin-top: 15px;
50
+ color: #007BFF;
51
+ text-decoration: none;
52
+ }
53
+
54
+ .logout:hover {
55
+ text-decoration: underline;
56
+ }
templates/dashboard.html ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dashboard</title>
5
+ <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
6
+ </head>
7
+ <body>
8
+ <div class="container">
9
+ <h2>Welcome, {{ user }}!</h2>
10
+ <a class="logout" href="{{ url_for('logout') }}">Logout</a>
11
+ </div>
12
+ </body>
13
+ </html>
templates/login.html ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Login</title>
5
+ <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
6
+ </head>
7
+ <body>
8
+ <div class="container">
9
+ <h2>Login</h2>
10
+ {% if error %}
11
+ <p class="error">{{ error }}</p>
12
+ {% endif %}
13
+ <form method="POST">
14
+ <input type="text" name="username" placeholder="Username" required><br>
15
+ <input type="password" name="password" placeholder="Password" required><br>
16
+ <button type="submit">Login</button>
17
+ </form>
18
+ <p>Don't have an account? <a href="{{ url_for('signup') }}">Sign up</a></p>
19
+ </div>
20
+ </body>
21
+ </html>
templates/signup.html ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Signup</title>
5
+ <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
6
+ </head>
7
+ <body>
8
+ <div class="container">
9
+ <h2>Signup</h2>
10
+ {% if error %}
11
+ <p class="error">{{ error }}</p>
12
+ {% endif %}
13
+ <form method="POST">
14
+ <input type="text" name="username" placeholder="Choose a username" required><br>
15
+ <input type="password" name="password" placeholder="Choose a password" required><br>
16
+ <button type="submit">Sign Up</button>
17
+ </form>
18
+ <p>Already have an account? <a href="{{ url_for('login') }}">Login</a></p>
19
+ </div>
20
+ </body>
21
+ </html>