Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arihant2math committed Nov 5, 2023
1 parent e6a9dd4 commit 2679ed7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions website/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def get_session():
if session["username"] is not None:
if "username" in session:
user = db.session.query(Token).filter_by(active=True, username=session["username"]).first()
if user is None:
user = db.session.query(Token, username=session["username"]).first()
Expand All @@ -19,7 +19,7 @@ def get_session():


def get_user():
if session["username"] is not None:
if "username" in session:
user = db.session.query(Token).filter_by(username=session["username"]).first()
return user
else:
Expand Down
10 changes: 5 additions & 5 deletions website/templates/auth/login.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{% extends 'base.html' %}
{% block title %}
Register
Login
{% endblock %}
{% block body %}
<div class="row justify-content-center text-center">
<h1>Register</h1>
<h1>Login</h1>
</div>
<form class="form p-3">
<label class="label" for="username">Username:</label>
<input id="username" class="form-control" required>
<label class="label" for="password">Password:</label>
<input id="password" class="form-control" type="password" required>
<button class="btn btn-primary" type="button" onclick="register()">Register</button>
<button class="btn btn-primary" type="button" onclick="register()">Login</button>
</form>
<script>
function register() {
$.post("/register-api/", {"username": $("#username").val(), "password": $("#password").val()}).then(function () {
$.post("/login-api/", {"username": $("#username").val(), "password": $("#password").val()}).then(function () {
window.location.href = "/"
});
}
</script>
{% endblock %}
{% block navid %}register{% endblock %}
{% block navid %}login{% endblock %}
24 changes: 24 additions & 0 deletions website/templates/auth/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'base.html' %}
{% block title %}
Register
{% endblock %}
{% block body %}
<div class="row justify-content-center text-center">
<h1>Register</h1>
</div>
<form class="form p-3">
<label class="label" for="username">Username:</label>
<input id="username" class="form-control" required>
<label class="label" for="password">Password:</label>
<input id="password" class="form-control" type="password" required>
<button class="btn btn-primary" type="button" onclick="register()">Register</button>
</form>
<script>
function register() {
$.post("/register-api/", {"username": $("#username").val(), "password": $("#password").val()}).then(function () {
window.location.href = "/"
});
}
</script>
{% endblock %}
{% block navid %}register{% endblock %}
2 changes: 1 addition & 1 deletion website/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def wrap(*args, **kwargs):

def login_required(func):
def wrap(*args, **kwargs):
if session["username"] is None:
if "username" not in session:
flash("Not logged in", "danger")
return redirect(url_for("auth.login"))
result = func(*args, **kwargs, user=get_user())
Expand Down

0 comments on commit 2679ed7

Please sign in to comment.