Skip to content

Commit

Permalink
setup login route
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-kedis committed Sep 4, 2022
1 parent ca09e03 commit 0a0c7fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ A website to help you keep track of all the video media that you watched, are wa
- [X] design the database
- [X] connect data base
- [X] error page
- [ ] require login wrapper
- [X] require login wrapper
- [ ] login page
- [ ] logout page
- [ ] register page design
32 changes: 30 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# ----------------------------------
# ------: import libs and functions
# ----------------------------------

# import libs
from crypt import methods
import os
from flask import Flask, render_template, session, request, redirect, jsonify
from flask_session import Session
Expand All @@ -7,6 +12,10 @@
from werkzeug.security import check_password_hash, generate_password_hash
from functools import wraps

# ----------------------------------
# ------: configurations
# ----------------------------------

# init main app
app = Flask(__name__)

Expand All @@ -30,6 +39,10 @@ def after_request(response):
# connect media database
db = SQL("sqlite:///media.db")

# ----------------------------------
# ------: Helper functions
# ----------------------------------

# error page
def apology(message, code=400):
return render_template("error.html", code=code, msg=message)
Expand All @@ -45,6 +58,10 @@ def decorated_function(*args, **kwargs):
return f(*args, **kwargs)
return decorated_function

# ----------------------------------
# ------: Routes
# ----------------------------------

# index route
@app.route("/")
@login_required
Expand All @@ -57,9 +74,20 @@ def register():
return render_template("TODO.html")

# login route
@app.route("/login")
@app.route("/login", methods=["GET", "POST"])
def login():
return render_template("TODO.html")
"""Log user in"""

# Forget any user_id
session.clear()

# User reached route via GET (as by clicking a link or via redirect)
if request.method == "GET":
return render_template("login.html")

# User reached route via POST (as by submitting a form via POST)
else:
return render_template("TODO.html")

# logout route
@app.route("/logout")
Expand Down
2 changes: 1 addition & 1 deletion templates/error.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "layout.html" %}
{% block title %} TODO {% endblock %}
{% block title %} ERROR {% endblock %}
{% block body %}
<div class="error">
<div class="error__code">
Expand Down
7 changes: 7 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "layout.html" %}
{% block title %} Login {% endblock %}
{% block body %}
<div class="login">
<h1 class="login__heading">LOGIN</h1>
</div>
{% endblock %}

0 comments on commit 0a0c7fa

Please sign in to comment.