-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
555d768
commit 22267da
Showing
14 changed files
with
333 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ Flask==2.3.3 | |
psutil==5.9.5 | ||
gunicorn | ||
speetest-cli | ||
flask-sqlalchemy | ||
flask-sqlalchemy | ||
flask-login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from flask import Flask, render_template, redirect, url_for, request, blueprints, flash | ||
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user | ||
from flask_sqlalchemy import SQLAlchemy | ||
from werkzeug.security import generate_password_hash, check_password_hash | ||
|
||
from src.config import app, db | ||
from src.models import User | ||
|
||
auth_bp = blueprints.Blueprint('auth', __name__) | ||
|
||
# Configure Flask-Login | ||
login_manager = LoginManager() | ||
login_manager.init_app(app) | ||
login_manager.login_view = 'login' | ||
|
||
# Define the User model | ||
|
||
@login_manager.user_loader | ||
def load_user(user_id): | ||
return User.query.get(int(user_id)) | ||
|
||
@app.route('/login', methods=['GET', 'POST']) | ||
def login(): | ||
if request.method == 'POST': | ||
username = request.form['username'] | ||
password = request.form['password'] | ||
user = User.query.filter_by(username=username).first() | ||
if user and check_password_hash(user.password, password): | ||
login_user(user) | ||
return redirect(url_for('dashboard')) | ||
flash('Invalid username or password') | ||
return render_template('login.html') | ||
|
||
@app.route('/signup', methods=['GET', 'POST']) | ||
def signup(): | ||
if request.method == 'POST': | ||
username = request.form['username'] | ||
password = request.form['password'] | ||
confirm_password = request.form['confirm_password'] | ||
|
||
if password != confirm_password: | ||
flash('Passwords do not match') | ||
return redirect(url_for('signup')) | ||
|
||
existing_user = User.query.filter_by(username=username).first() | ||
if existing_user: | ||
flash('Username already exists') | ||
return redirect(url_for('signup')) | ||
|
||
hashed_password = generate_password_hash(password) | ||
new_user = User(username=username, password=hashed_password) | ||
db.session.add(new_user) | ||
db.session.commit() | ||
flash('Account created successfully, please log in.') | ||
return redirect(url_for('login')) | ||
|
||
return render_template('signup.html') | ||
|
||
@app.route('/protected') | ||
@login_required | ||
def protected(): | ||
if current_user.user_level == 'admin': | ||
return f'Hello, Admin {current_user.username}! This is a protected page.' | ||
return f'Hello, {current_user.username}! This is a protected page.' | ||
|
||
@app.route('/logout') | ||
def logout(): | ||
logout_user() | ||
return redirect(url_for('login')) | ||
|
||
|
||
# def admin_required(f): | ||
# """Decorator to ensure the current user is an admin.""" | ||
# @wraps(f) | ||
# def decorated_function(*args, **kwargs): | ||
# if not current_user.is_authenticated or current_user.user_level != 'admin': | ||
# flash('Access denied. Admins only.') | ||
# return redirect(url_for('login')) | ||
# return f(*args, **kwargs) | ||
# return decorated_function | ||
|
||
# def user_required(f): | ||
# """Decorator to ensure the current user is a regular user.""" | ||
# @wraps(f) | ||
# def decorated_function(*args, **kwargs): | ||
# if not current_user.is_authenticated or current_user.user_level != 'user': | ||
# flash('Access denied. Users only.') | ||
# return redirect(url_for('login')) | ||
# return f(*args, **kwargs) | ||
# return decorated_function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* static/css/login.css */ | ||
|
||
|
||
h2 { | ||
color: #333; | ||
} | ||
|
||
form { | ||
background: #fff; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
max-width: 400px; | ||
width: 100%; | ||
} | ||
|
||
label { | ||
display: block; | ||
margin: 10px 0 5px; | ||
} | ||
|
||
input[type="text"], | ||
input[type="password"] { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 10px; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
} | ||
|
||
input[type="submit"] { | ||
background-color: #28a745; | ||
color: #fff; | ||
border: none; | ||
padding: 10px; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
} | ||
|
||
input[type="submit"]:hover { | ||
background-color: #218838; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* static/css/signup.css */ | ||
|
||
|
||
|
||
h2 { | ||
color: #333; | ||
} | ||
|
||
form { | ||
background: #fff; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
max-width: 400px; | ||
width: 100%; | ||
} | ||
|
||
label { | ||
display: block; | ||
margin: 10px 0 5px; | ||
} | ||
|
||
input[type="text"], | ||
input[type="password"] { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 10px; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
} | ||
|
||
input[type="submit"] { | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
padding: 10px; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
} | ||
|
||
input[type="submit"]:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
p { | ||
margin-top: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
{% extends 'base.html' %}{% block title %}Server Dashboard{% endblock %}{% block content %}<div class="container mt-4"><div class="row">{% include 'dasbhboard_comp/other/username.html' %} {% include 'dasbhboard_comp/other/boot_time.html' %} {% include 'dasbhboard_comp/battery/percentage.html' %} {% include 'dasbhboard_comp/cpu/core.html' %} {% include 'dasbhboard_comp/cpu/usages.html' %} {% include 'dasbhboard_comp/cpu/current_temp.html' %} {% include 'dasbhboard_comp/memory/dashboard_memory.html' %} {% include 'dasbhboard_comp/memory/usage.html' %} {% include 'dasbhboard_comp/disk/usage.html' %} {% include 'dasbhboard_comp/other/uptime.html' %} {% include 'dasbhboard_comp/network/stats.html' %} {% include 'dasbhboard_comp/other/speedtest.html' %} </div></div>{% endblock %} | ||
{% extends 'base.html' %}{% block title %}Server Dashboard{% endblock %}{% block content %}<div class="container mt-4"> | ||
<div class="row">{% include 'dasbhboard_comp/other/username.html' %}{% include | ||
'dasbhboard_comp/other/boot_time.html' %}{% include 'dasbhboard_comp/battery/percentage.html' %}{% include | ||
'dasbhboard_comp/cpu/core.html' %}{% include 'dasbhboard_comp/cpu/usages.html' %}{% include | ||
'dasbhboard_comp/cpu/current_temp.html' %}{% include 'dasbhboard_comp/memory/dashboard_memory.html' %}{% include | ||
'dasbhboard_comp/memory/usage.html' %}{% include 'dasbhboard_comp/disk/usage.html' %}{% include | ||
'dasbhboard_comp/other/uptime.html' %}{% include 'dasbhboard_comp/network/stats.html' %}{% include | ||
'dasbhboard_comp/other/speedtest.html' %} </div> | ||
</div>{% endblock %} |
Oops, something went wrong.