Skip to content

Menambahkan validasi login dan komentar #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions sequence-login.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@startuml sequence-login
actor User
participant "Login Page" as LoginPage
participant "routes.py" as Route
participant "models.py" as UserModel

User -> LoginPage : open form
User -> LoginPage : input username & password
LoginPage -> Route : POST /login
Route -> UserModel : validate_user()
UserModel --> Route : user exists or not
alt valid
Route --> LoginPage : redirect to dashboard
else invalid
Route --> LoginPage : show error
end
@enduml
Binary file added __pycache__/app.cpython-312.pyc
Binary file not shown.
49 changes: 41 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
import os
from flask import Flask
from flask import Flask, render_template, request, redirect, url_for, session

app = Flask(__name__)
app.secret_key = 'rahasia' # untuk session

# Data login dummy
USER_CREDENTIALS = {
'admin': 'admin'
}

@app.route("/")
def main():
return "Welcome!"
def index():
return render_template("login.html")

@app.route("/login", methods=["POST"])
def login():
username = request.form["username"]
password = request.form["password"]
if username in USER_CREDENTIALS and USER_CREDENTIALS[username] == password:
session['user'] = username
return redirect(url_for('dashboard'))
return "Login gagal! <a href='/'>Coba lagi</a>"

@app.route("/dashboard")
def dashboard():
if 'user' not in session:
return redirect(url_for('index'))
return render_template("dashboard.html")

@app.route("/create", methods=["GET", "POST"])
def create():
if 'user' not in session:
return redirect(url_for('index'))
if request.method == "POST":
nama = request.form["nama"]
jumlah = request.form["jumlah"]
print(f"Data disimpan: {nama}, jumlah: {jumlah}")
return render_template("success.html")
return render_template("create.html")

@app.route('/how are you')
def hello():
return 'I am good, how about you?'
@app.route("/logout")
def logout():
session.pop('user', None)
return render_template("logout.html")

if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
app.run(host="0.0.0.0", port=8080)
3 changes: 3 additions & 0 deletions classes_flask_app.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@startuml classes_flask_app
set namespaceSeparator none
@enduml
Empty file added filelist.txt
Empty file.
Binary file added out/ sequence-login/sequence-login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added out/classes_flask_app/classes_flask_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added out/sequence-create-item/sequence-create-item.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions sequence-create-item.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@startuml sequence-create-item
actor User
participant "Create Item Page" as ItemPage
participant "routes.py" as Route
participant "models.py" as ItemModel

User -> ItemPage : open form
User -> ItemPage : input item data
ItemPage -> Route : POST /create
Route -> ItemModel : save new item
ItemModel --> Route : success
Route --> ItemPage : show confirmation
@enduml
13 changes: 13 additions & 0 deletions templates/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head><title>Buat Item</title></head>
<body>
<h2>Form Buat Item</h2>
<form method="POST">
Nama: <input type="text" name="nama" required><br><br>
Jumlah: <input type="number" name="jumlah" required><br><br>
<input type="submit" value="Simpan">
</form>
<a href="{{ url_for('dashboard') }}">Kembali</a>
</body>
</html>
9 changes: 9 additions & 0 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head><title>Dashboard</title></head>
<body>
<h2>Selamat datang, {{ session['user'] }}</h2>
<a href="{{ url_for('create') }}">Tambah Item</a><br>
<a href="{{ url_for('logout') }}">Logout</a>
</body>
</html>
12 changes: 12 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head><title>Login</title></head>
<body>
<h2>Login</h2>
<form method="POST" action="{{ url_for('login') }}">
Username: <input type="text" name="username"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
8 changes: 8 additions & 0 deletions templates/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head><title>Logout</title></head>
<body>
<h2>Anda telah logout</h2>
<a href="{{ url_for('index') }}">Login kembali</a>
</body>
</html>
8 changes: 8 additions & 0 deletions templates/success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head><title>Berhasil</title></head>
<body>
<h2>Item berhasil disimpan!</h2>
<a href="{{ url_for('dashboard') }}">Kembali ke Dashboard</a>
</body>
</html>
Loading