Skip to content
Open
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ build/
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
/.idea/.gitignore
/.idea/examplesite.iml
/.idea/misc.xml
/.idea/modules.xml
/.idea/inspectionProfiles/profiles_settings.xml
/.idea/vcs.xml
25 changes: 18 additions & 7 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
from flask import Flask
from flask_login import LogInManager
from flask import Flask, render_template
from flask_login import LoginManager
from app.views.loginHandler import loginHandler
from app.views.account import account

# The WSGI configuration on Elastic Beanstalk requires
# the callable be named 'application' by default.
app = Flask(__name__)

app.register_blueprint(loginHandler)
# app.register_blueprint(account)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = "login"
login_manager.login_view = "loginHandler.login"


@login_manager.user_loader
def load_user(user_id):
return User.get(user_id)

# Import the views
from app.views import main

@app.route('/')
@app.route('/index')
def index():
return render_template('index.html', title='Home')


if __name__ == '__main__':
app.run()
26 changes: 13 additions & 13 deletions app/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {box-sizing: border-box;}
body {

body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}

#navbar {
overflow: hidden;
background-color: #f1f1f1;
Expand All @@ -21,38 +21,38 @@
top: 0;
z-index: 99;
}

#navbar a {
float: left;
color: black;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}

#navbar #logo {
font-size: 35px;
font-weight: bold;
transition: 0.4s;
}

#navbar a:hover {
background-color: #ddd;
color: black;
}

#navbar a.active {
background-color: dodgerblue;
color: white;
}

#navbar-right {
float: right;
}

@media screen and (max-width: 580px) {
#navbar {
padding: 20px 10px !important;
Expand All @@ -75,16 +75,16 @@
<div id="navbar-right">
<a class="active" href="#home">Home</a>
<a href="#contact">Contact</a>
<a href="signin.html>Sign In</a>
<a href="{{ url_for('loginHandler.login') }}">Sign In</a>
</div>
</div>

<div id="content" style="margin-top:210px;padding:15px 15px 2500px;font-size:30px">{% block content %}{% endblock %}</div>

<script>
// When the user scrolls down 80px from the top of the document, resize the navbar's padding and the logo's font size
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 80) {
document.getElementById("navbar").style.padding = "30px 10px";
Expand Down
2 changes: 0 additions & 2 deletions app/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@
<input type="submit" value="Log In">
</form>
{% endblock %}

{% endblock %}
11 changes: 11 additions & 0 deletions app/views/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import render_template, Blueprint
from flask_login import login_required

account = Blueprint('account', __name__, template_folder='templates')


@account.route('/account/')
@account.route('/account/<name>')
@login_required
def account(name):
return render_template('account.html')
47 changes: 47 additions & 0 deletions app/views/loginHandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import flask
from flask import Blueprint, request, render_template, redirect
from flask_login import login_user, login_required, logout_user
from is_safe_url import is_safe_url
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField

loginHandler = Blueprint('loginHandler', __name__, template_folder='templates')


class LoginForm(FlaskForm):
username = StringField('Username')
password = PasswordField('Password')
submit = SubmitField('Submit')


@loginHandler.route('/login', methods=['GET', 'POST'])
def login():
# Here we use a class of some kind to represent and validate our
# client-side form data. For example, WTForms is a library that will
# handle this for us, and we use a custom LoginForm to validate.
if request.method == 'POST':
form = LoginForm()
if form.validate_on_submit():
# Login and validate the user.
# user should be an instance of your `User` class
login_user(user)

flask.flash('Logged in successfully.')

# TODO: Don't use the variable next here it shadows built in variable
next = flask.request.args.get('next')
# is_safe_url should check if the url is safe for redirects.
# See http://flask.pocoo.org/snippets/62/ for an example.
if not is_safe_url(next):
return flask.abort(400)

return flask.redirect(next or flask.url_for('account'))

return render_template('login.html')


@loginHandler.route("/logout")
@login_required
def logout():
logout_user()
return redirect("url_for('index')")
43 changes: 0 additions & 43 deletions app/views/main.py
Original file line number Diff line number Diff line change
@@ -1,43 +0,0 @@
from flask import render_template
from app import app



@app.route('/')
@app.route('/index')
def index():
return render_template('index.html', title='Home')

@app.route('/account/')
@app.route('/account/<name>')
@login_required
def account():
return render_template('account.html')

@app.route('/login', methods=['GET', 'POST'])
def login():
# Here we use a class of some kind to represent and validate our
# client-side form data. For example, WTForms is a library that will
# handle this for us, and we use a custom LoginForm to validate.
form = LoginForm()
if form.validate_on_submit():
# Login and validate the user.
# user should be an instance of your `User` class
login_user(user)

flask.flash('Logged in successfully.')

next = flask.request.args.get('next')
# is_safe_url should check if the url is safe for redirects.
# See http://flask.pocoo.org/snippets/62/ for an example.
if not is_safe_url(next):
return flask.abort(400)

return flask.redirect(next or flask.url_for('account'))
return flask.render_template('login.html', form=form)

@app.route("/logout")
@login_required
def logout():
logout_user()
return redirect('url_for('index'))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
wtforms
Flask==1.1.1
flask-login==0.5.0