Burathar
4 years ago
9 changed files with 173 additions and 28 deletions
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
from flask_wtf import FlaskForm |
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField, TextAreaField |
||||
from wtforms.validators import DataRequired, EqualTo, ValidationError, Length |
||||
from app.models import Player |
||||
|
||||
class LoginForm(FlaskForm): |
||||
username = StringField('Username', validators=[DataRequired()]) |
||||
password = PasswordField('Password', validators=[DataRequired()]) |
||||
remember_me = BooleanField('Remember Me', default=True) |
||||
submit = SubmitField('Sign In') |
||||
|
||||
class RegistrationForm(FlaskForm): |
||||
username = StringField('Username', validators=[DataRequired(), Length(min=0, max=64)]) |
||||
password = PasswordField('Password', validators=[DataRequired(), Length(min=0, max=128)]) |
||||
password2 = PasswordField( |
||||
'Repeat Password', validators=[DataRequired(), EqualTo('password')]) |
||||
submit = SubmitField('Register') |
||||
|
||||
def validate_username(self, username): |
||||
player = Player.query.filter_by(name=username.data).first() |
||||
if player is not None: |
||||
raise ValidationError('Please use a different username.') |
@ -1,11 +1,45 @@
@@ -1,11 +1,45 @@
|
||||
from flask import render_template, flash, redirect, url_for, request |
||||
from flask_login import login_user, logout_user, current_user, login_required |
||||
from app import app, db |
||||
#from app.forms import - |
||||
from app.models import Player, Game |
||||
from app.forms import LoginForm, RegistrationForm |
||||
|
||||
@app.route('/', methods=['GET']) |
||||
@app.route('/index', methods=['GET']) |
||||
@login_required |
||||
def index(): |
||||
message="Hello, World" |
||||
return render_template("index.html", title='Home', message=message) |
||||
|
||||
#@app.route('/game/<game_name>/leader') |
||||
@app.route('/login', methods=['GET', 'POST']) |
||||
def login(): |
||||
if current_user.is_authenticated: |
||||
return redirect(url_for('index')) |
||||
form = LoginForm() |
||||
if form.validate_on_submit(): |
||||
player = Player.query.filter_by(name=form.username.data).first() |
||||
if player is None or not player.check_password(form.password.data): |
||||
flash('Invalid username or password') |
||||
return redirect(url_for('login')) |
||||
login_user(player, remember=form.remember_me.data) |
||||
return redirect(url_for('index')) |
||||
return render_template('login.html', title='Sign In', form=form) |
||||
|
||||
@app.route('/logout') |
||||
def logout(): |
||||
logout_user() |
||||
return redirect(url_for('index')) |
||||
|
||||
@app.route('/register', methods=['GET', 'POST']) |
||||
def register(): |
||||
if current_user.is_authenticated: |
||||
return redirect(url_for('index')) |
||||
form = RegistrationForm() |
||||
if form.validate_on_submit(): |
||||
player = Player(name=form.username.data) |
||||
player.set_password(form.password.data) |
||||
db.session.add(player) |
||||
db.session.commit() |
||||
flash('Congratulations, you are now a registered user!') |
||||
return redirect(url_for('login')) |
||||
return render_template('register.html', title='Register', form=form) |
@ -1,8 +1,40 @@
@@ -1,8 +1,40 @@
|
||||
{% extends 'base.html' %} |
||||
|
||||
{% block app_content %} |
||||
|
||||
<h1>Welcome!</h1> |
||||
<h1>Hi, {{ current_user.name }}!</h1> |
||||
<h2>{{ message }}</h2> |
||||
|
||||
<h2>My games:</h2> |
||||
<div class="table-responsive"> |
||||
<table class="table"> |
||||
<thead> |
||||
<tr> |
||||
<th scope="col">Name</th> |
||||
<th scope="col">State</th> |
||||
<th scope="col">Start Time</th> |
||||
<th scope="col">End Time</th> |
||||
<th scope="col">My Role</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr> |
||||
<td>Gamename</td> |
||||
<td>Running</td> |
||||
<td>yesterday</td> |
||||
<td>tomorrow</td> |
||||
<td>bitch</td> |
||||
</tr> |
||||
{% for game in current_user.games %} |
||||
<tr> |
||||
<td>{{ game.name }}</td> |
||||
<td>{{ game.state }}</td> |
||||
<td>{{ game.start_time }}</td> |
||||
<td>{{ game.end_time }}</td> |
||||
<td>bitch</td> |
||||
</tr> |
||||
{% endfor %} |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
|
||||
{% endblock %} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
|
||||
{% extends 'base.html' %} |
||||
{% import 'bootstrap/wtf.html' as wtf %} |
||||
|
||||
{% block app_content %} |
||||
<h1>Sign In</h1> |
||||
<div class="row"> |
||||
<div class="col-md-4"> |
||||
{{ wtf.quick_form(form) }} |
||||
</div> |
||||
</div> |
||||
<br> |
||||
<p>New User? <a href="{{ url_for('register') }}">Click to Register!</a></p> |
||||
{% endblock %} |
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
{% extends "base.html" %} |
||||
{% import 'bootstrap/wtf.html' as wtf %} |
||||
|
||||
{% block app_content %} |
||||
<h1>Register</h1> |
||||
<div class="row"> |
||||
<div class="col-md-4"> |
||||
{{ wtf.quick_form(form) }} |
||||
</div> |
||||
</div> |
||||
{% endblock %} |
Loading…
Reference in new issue