simar007 commited on
Commit
1106e39
·
verified ·
1 Parent(s): fa06e71

Upload 9 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for, session, flash
2
+ from werkzeug.security import generate_password_hash, check_password_hash
3
+
4
+ app = Flask(__name__)
5
+ app.secret_key = "supersecretkey" # change this in production!
6
+
7
+ # Simple in-memory "database"
8
+ users = {}
9
+
10
+ @app.route("/")
11
+ def home():
12
+ if "user" in session:
13
+ return redirect(url_for("dashboard"))
14
+ return redirect(url_for("login"))
15
+
16
+ @app.route("/signup", methods=["GET", "POST"])
17
+ def signup():
18
+ if request.method == "POST":
19
+ username = request.form["username"]
20
+ password = request.form["password"]
21
+ confirm_password = request.form.get("confirmPassword")
22
+
23
+ if password != confirm_password:
24
+ flash("Passwords do not match.", "danger")
25
+ return redirect(url_for("signup"))
26
+
27
+ if username in users:
28
+ flash("Username already exists!", "danger")
29
+ return redirect(url_for("signup"))
30
+
31
+ users[username] = generate_password_hash(password)
32
+ flash("Signup successful! Please login.", "success")
33
+ return redirect(url_for("login"))
34
+
35
+ return render_template("signup.html")
36
+
37
+ @app.route("/login", methods=["GET", "POST"])
38
+ def login():
39
+ if request.method == "POST":
40
+ username = request.form["username"]
41
+ password = request.form["password"]
42
+
43
+ if username in users and check_password_hash(users[username], password):
44
+ session["user"] = username
45
+ return redirect(url_for("dashboard"))
46
+ else:
47
+ flash("Invalid username or password", "danger")
48
+
49
+ return render_template("login.html")
50
+
51
+ @app.route("/dashboard")
52
+ def dashboard():
53
+ if "user" not in session:
54
+ return redirect(url_for("login"))
55
+ return render_template("dashboard.html", username=session["user"])
56
+
57
+ @app.route("/portfolio")
58
+ def portfolio():
59
+ if "user" not in session:
60
+ return redirect(url_for("login"))
61
+ return render_template("portfolio.html")
62
+
63
+ @app.route("/logout")
64
+ def logout():
65
+ session.pop("user", None)
66
+ flash("Logged out successfully.", "info")
67
+ return redirect(url_for("login"))
68
+
69
+ if __name__ == "__main__":
70
+ app.run(host="0.0.0.0", port=7860, debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ flask
2
+ werkzeug
static/style.css ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Basic reset */
2
+ * {
3
+ box-sizing: border-box;
4
+ }
5
+
6
+ body {
7
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
8
+ background: linear-gradient(135deg, #6b73ff, #000dff);
9
+ height: 100vh;
10
+ margin: 0;
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ color: #fff;
15
+ }
16
+
17
+ .container {
18
+ background: rgba(255, 255, 255, 0.1);
19
+ padding: 30px 40px;
20
+ border-radius: 15px;
21
+ width: 100%;
22
+ max-width: 400px;
23
+ box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
24
+ backdrop-filter: blur(8px);
25
+ -webkit-backdrop-filter: blur(8px);
26
+ border: 1px solid rgba(255, 255, 255, 0.18);
27
+ text-align: center;
28
+ }
29
+
30
+ h2 {
31
+ margin-bottom: 25px;
32
+ font-weight: 700;
33
+ letter-spacing: 1px;
34
+ }
35
+
36
+ input {
37
+ width: 100%;
38
+ padding: 12px 15px;
39
+ margin: 10px 0;
40
+ border-radius: 8px;
41
+ border: none;
42
+ outline: none;
43
+ font-size: 16px;
44
+ transition: background-color 0.3s ease;
45
+ }
46
+
47
+ input:focus {
48
+ background-color: rgba(255, 255, 255, 0.2);
49
+ }
50
+
51
+ button {
52
+ width: 100%;
53
+ padding: 12px 15px;
54
+ margin-top: 15px;
55
+ background-color: #3a3cff;
56
+ border: none;
57
+ border-radius: 8px;
58
+ color: white;
59
+ font-weight: 600;
60
+ font-size: 18px;
61
+ cursor: pointer;
62
+ transition: background-color 0.3s ease;
63
+ }
64
+
65
+ button:hover {
66
+ background-color: #2222ff;
67
+ }
68
+
69
+ #signupMessage, #loginMessage {
70
+ margin-top: 15px;
71
+ font-weight: 600;
72
+ }
73
+
74
+ .switch-page {
75
+ margin-top: 20px;
76
+ font-size: 14px;
77
+ color: #ddd;
78
+ }
79
+
80
+ .switch-page a {
81
+ color: #a6c1ff;
82
+ text-decoration: none;
83
+ font-weight: 600;
84
+ }
85
+
86
+ .switch-page a:hover {
87
+ text-decoration: underline;
88
+ }
templates/base.html ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Flask Auth + Portfolio</title>
7
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
8
+ </head>
9
+ <body>
10
+ {% block content %}{% endblock %}
11
+ </body>
12
+ </html>
templates/dashboard.html ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {% extends "base.html" %}
2
+ {% block content %}
3
+ <div class="container">
4
+ <h2>Welcome, {{ username }}!</h2>
5
+ <p>This is your dashboard.</p>
6
+ <a href="{{ url_for('portfolio') }}">Go to Portfolio</a>
7
+ </div>
8
+ {% endblock %}
templates/login.html ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends "base.html" %}
2
+ {% block content %}
3
+ <div class="container">
4
+ <h2>Sign In</h2>
5
+ <form method="POST" id="loginForm">
6
+ <input type="text" name="username" id="loginUsername" placeholder="Username" required />
7
+ <input type="password" name="password" id="loginPassword" placeholder="Password" required />
8
+ <button type="submit">Login</button>
9
+ </form>
10
+ <p id="loginMessage"></p>
11
+ <p class="switch-page">
12
+ Don't have an account? <a href="{{ url_for('signup') }}">Sign up here</a>
13
+ </p>
14
+ </div>
15
+ {% endblock %}
templates/portfolio.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends "base.html" %}
2
+ {% block content %}
3
+ <div class="container">
4
+ <h2>My Portfolio</h2>
5
+ <p>Here you can showcase your projects, images, or links.</p>
6
+ <ul>
7
+ <li><a href="https://github.com/yourname" target="_blank">GitHub</a></li>
8
+ <li><a href="https://linkedin.com/in/yourname" target="_blank">LinkedIn</a></li>
9
+ </ul>
10
+ </div>
11
+ {% endblock %}
templates/signup.html ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends "base.html" %}
2
+ {% block content %}
3
+ <div class="container">
4
+ <h2>Create Account</h2>
5
+ <form method="POST" id="signupForm">
6
+ <input type="text" name="username" id="newUsername" placeholder="Username" required />
7
+ <input type="password" name="password" id="newPassword" placeholder="Password" required />
8
+ <input type="password" name="confirmPassword" id="confirmPassword" placeholder="Confirm Password" required />
9
+ <button type="submit">Sign Up</button>
10
+ </form>
11
+ <p id="signupMessage"></p>
12
+ <p class="switch-page">
13
+ Already have an account? <a href="{{ url_for('login') }}">Login here</a>
14
+ </p>
15
+ </div>
16
+ {% endblock %}