Skip to content
Snippets Groups Projects
Commit 8bc50911 authored by Jakub Drápalík's avatar Jakub Drápalík
Browse files

skeleton for authentication, base template

parent 347791d3
No related branches found
No related tags found
1 merge request!1Merge master do mainu - autentifikace, mazání X dat, filtrování dat
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="dc430dd6-7651-4a7f-96c1-6718ff6c20b9" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/drapajak-miniprojekt.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
<list default="true" id="dc430dd6-7651-4a7f-96c1-6718ff6c20b9" name="Changes" comment="1st commit">
<change afterPath="$PROJECT_DIR$/templates/base.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/templates/index.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/templates/login.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/templates/register.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/users.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -19,6 +22,7 @@
<option name="RECENT_TEMPLATES">
<list>
<option value="Flask Main" />
<option value="HTML File" />
</list>
</option>
</component>
......@@ -47,11 +51,17 @@
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"DefaultHtmlFileTemplate": "HTML File",
"Flask server.drapajak-miniprojekt.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.lookFeel",
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PythonContentEntriesConfigurable",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
......@@ -88,11 +98,27 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1709806296443</updated>
<workItem from="1709806303486" duration="60000" />
<workItem from="1709806303486" duration="4461000" />
</task>
<task id="LOCAL-00001" summary="1st commit">
<option name="closed" value="true" />
<created>1709806519109</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1709806519109</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="1st commit" />
<option name="LAST_COMMIT_MESSAGE" value="1st commit" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/drapajak_miniprojekt$drapajak_miniprojekt.coverage" NAME="drapajak-miniprojekt Coverage Results" MODIFIED="1709810579502" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
</component>
</project>
\ No newline at end of file
from flask import Flask
from flask import *
app = Flask(__name__)
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
def hello_world():
return render_template('index.html'), 200
@app.route('/register')
def register_user():
return
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
if add_user(username, password):
flash('Registration successful')
return redirect(url_for('login'))
else:
flash('Username already exists')
return render_template('register.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
if authenticate_user(username, password):
return redirect(url_for('home'))
else:
flash('Incorrect username/password')
return render_template('login.html')
def authenticate_user(username, password):
with open('users.json', 'r') as file:
data = json.load(file)
for user in data['users']:
if user['username'] == username and user['password'] == password:
return True
return False
def add_user(username, password):
with open('users.json', 'r') as file:
data = json.load(file)
for user in data['users']:
if user['username'] == username:
return False
data['users'].append({'username': username, 'password': password})
with open('users.json', 'w') as file:
json.dump(data, file, indent=4)
return True
if __name__ == '__main__':
app.run()
app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
{% block head %}
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<title>{% block title %}{% endblock title %} - NSI</title>
{% endblock head %}
</head>
<body>
{% block navbar %}
<div class="navbar bg-body-primary p-5">
<div class="nav justify-content-space-between container-fluid">
<div class="nav-item">
<a class="navlink" href="/">Home</a>
</div>
<div class="nav-item">
<button class="btn">{% block buttonText %}{% endblock buttonText %}</button>
</div>
</div>
</div>
{% endblock navbar %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Home{% endblock title %}
<body>
{% block buttonText %}Register{% endblock buttonText %}
{% block card %}
<div class="container-fluid">
<div class="card" style="width: 10rem;">
<div class="card-body">
<h2 class="card-title">Poslední naměřená hodnota</h2>
<p class="card-text">Lorem Ipsum blab la</p>
</div>
</div>
</div>
{% endblock card %}
</body>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Login{% endblock title %}
<body>
{% block buttonText %}Register{% endblock buttonText %}
</body>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Register{% endblock title %}
<body>
{% block buttonText %}Login{% endblock buttonText %}
</body>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment