Skip to content
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

Signup and login redirection is done #43

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name = "pypi"
pymongo = "*"
flask = "*"
python-dotenv = "*"
flask-login = "*"

[dev-packages]

Expand Down
19 changes: 10 additions & 9 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,26 @@
except Exception as e:
print("MongoDB connection error:", e)

@app.route("/")
@app.route("/", methods=["GET", "POST"])
def home():
# Note: (Ahmet) I will do these
# TODO: redirect to login
# TODO: redirect to sign up
if request.method == 'POST':
if 'login' in request.form:
return redirect('/login')
elif 'sign-up' in request.form:
return redirect('/signup')
elif 'play-as-guest' in request.form:
pass
# TODO: redirect to play as guest
return render_template('start.html')

# Handle authentication related stuff in authentication.py file
app.add_url_rule('/login', methods=["GET", "POST"], view_func=authentication.login)
app.add_url_rule('/signup', methods=["GET", "POST"], view_func=authentication.signup)
@app.route('/login', methods=["GET", "POST"])
def login():
return authentication.login(db)

@app.route('/signup', methods=["GET", "POST"])
def signup():
return authentication.signup(db)

@app.route("/<username>/decks")
def allDecks(username):
Expand Down
32 changes: 26 additions & 6 deletions authentication.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
from flask import render_template
from flask import render_template, request, redirect, url_for, session
from flask_login import LoginManager
import app

def login():
return render_template('login.html')

def signup():
return render_template('signup.html')
login_manager = LoginManager()

class User():
def __init__(self, is_authenticated, is_active, is_anonymous):
self.is_authenticated = is_authenticated
self.is_active = is_active
self.is_anonymous = is_anonymous


def login(db):
print(db)
if request.method == 'POST':
## TODO: Login
return "Someone pressed the login button huh, I better log you in."
else:
return render_template('login.html')

def signup(db):
if request.method == 'POST':
username = request.form["username"]
password = request.form["password"]
else:
return render_template('signup.html')

# TODO: Handle autehentication and session management with flask-login
4 changes: 2 additions & 2 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
{% block container %}

<div class="card">
<form class="vertical-align" action={{action}} method="post">
<form class="vertical-align" action={{url_for('login')}} method="post">
<input class="user-input" type="username" name="username" placeholder="Username" required>
<input class="user-input" type="password" name="password" placeholder="Password" required>
<input class="button" type="submit" value="Login">
</form>
</div>

{% endblock %}
{% endblock %}
12 changes: 6 additions & 6 deletions templates/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ <h3>build deeper connections with people.</h3>
</div>

<div class="card">
<div class="vertical-align">
<button class="button" type="submit">Login</button>
<button class="button" type="submit">Sign Up</button>
<button class="button" type="submit">Play As Guest</button>
</div>
<form class="vertical-align" method="post">
<button class="button" type="submit" name="login">Login</button>
<button class="button" type="submit" name="sign-up">Sign Up</button>
<button class="button" type="submit" name="play-as-guest">Play As Guest</button>
</form>
</div>

{% endblock %}
{% endblock %}
Loading