Commit 25639f08 authored by Mathis Dedial's avatar Mathis Dedial
Browse files

Merge

parents 2c60a20c 75eec6dd
Pipeline #2676 skipped with stage
stages:
- deploy
dev_deploy:
stage: deploy
image: alpine:latest
when: manual
before_script:
- 'which ssh-agent || ( apk update -y && apk add openssh-client -y )'
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- echo "$DEPLOY_PRIVATE_KEY" | ssh-add -
- 'which rsync || ( apk add rsync -y )'
script:
- ssh -p22 amivburger@login.ee.ethz.ch "mkdir -p ~/app_tmp/"
- rsync -rav -e ssh --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded ./ amivburger@login.ee.ethz.ch:~/app_tmp
- ssh -p22 amivburger@login.ee.ethz.ch "cp ~/app/app/config.py ~/app_tmp/app/"
- ssh -p22 amivburger@login.ee.ethz.ch "mv ~/app ~/app_old && mv ~/app_tmp ~/app && chmod -R 700 ~/app"
- ssh -p22 amivburger@login.ee.ethz.ch "touch ~/app-touch-reload.gg"
- ssh -p22 amivburger@login.ee.ethz.ch "rm -rf ~/app_old"
environment:
name: production
url: https://burger.amiv.ethz.ch
# Burger-Tool (AMIV Anniversary 125 years) # Burger-Tool (AMIV Anniversary 125 years)
A Webapp to select the most popular burger as AMIVs 125 year anniversary burger.
## Setup
### Virtualenv
The website runs using flask, and we recommend running it in a virtual
environment. To do this, you first need to initialise it:
```bash
\$ virtualenv venv
```
This will initialise the virtual environment in the `venv` directory. To
activate it, source the following script:
```bash
\$ source venv/bin/activate
```
If that was successful, your `$PS1` should start with `(venv)`.
### Dependencies
Now you need to install the dependencies listed in `requirements.txt`.
```bash
\$ pip install -r requirements.txt
```
### Database & Admin User
To create the database structure and add an admin user, run
```bash
\$ ./create_schema.py <admin_username> <admin_password>
```
## Run
After that, you can run the website by executing `amiv-anniversary125-burger-tool.py`. The website is
served at `127.0.0.1:5000` by default.
...@@ -47,7 +47,8 @@ section .container { ...@@ -47,7 +47,8 @@ section .container {
cursor: pointer; cursor: pointer;
} }
#creator input { #creator input,
.login input {
max-width: 400px; max-width: 400px;
text-align: center; text-align: center;
display: inline-block; display: inline-block;
......
{% extends 'base.html' %}
{% block title %} AMIV Burger Login {% endblock %}
{% block content %}
<header class="masthead bg-primary text-white text-center">
<div class="container login">
<h2 class="text-center text-uppercase text-white">Login required</h2>
<div class="text-center">
<p>You need to log in with your nethz credentials to create or vote on any burger.</p>
</div>
<hr class="star-light">
<form method="POST" action="/login">
<input class="form-control" id="input_user" name="user" type="text" placeholder="nethz username"/><br/>
<input class="form-control" id="input_passwd" name="passwd" type="password" placeholder="Password"/><br/>
<input class="btn btn-primary" type="submit" value="sign in"/>
</form>
</div>
</header>
{% endblock %}
\ No newline at end of file
''' '''
Contains all views Contains all views
''' '''
from app import app from app import app, ldap
from datetime import datetime from datetime import datetime
from flask import flash, g, redirect, render_template, request, url_for from flask import flash, g, redirect, render_template, request, session, url_for
from sqlalchemy.sql import text from sqlalchemy.sql import text
from .mappings import BREAD, PATTY, TOPPINGS, SIDE from .mappings import BREAD, PATTY, TOPPINGS, SIDE
from .models import db, Burger, Vote from .models import db, Burger, Vote
@app.route('/') @app.route('/')
def list(): def index():
''' '''
Front page. Shows a list of all burgers Front page. Shows a list of all burgers
''' '''
...@@ -31,6 +31,7 @@ def list(): ...@@ -31,6 +31,7 @@ def list():
@app.route('/vote', methods=['POST']) @app.route('/vote', methods=['POST'])
# @ldap.login_required
def vote(): def vote():
''' '''
Handles POST requests for voting Handles POST requests for voting
...@@ -40,7 +41,7 @@ def vote(): ...@@ -40,7 +41,7 @@ def vote():
Display an error-level flash message and return Display an error-level flash message and return
''' '''
flash(message, 'error') flash(message, 'error')
return redirect(url_for('list')) return redirect(url_for('index'))
# Check if the burger_id is valid # Check if the burger_id is valid
burger_id = request.form.get('burger_id') burger_id = request.form.get('burger_id')
...@@ -74,10 +75,55 @@ def vote(): ...@@ -74,10 +75,55 @@ def vote():
flash('Your like has been removed.', 'success') flash('Your like has been removed.', 'success')
return redirect(url_for('list')) return redirect(url_for('index'))
@app.before_request
def load_user():
'''
Load user data before any request processing
'''
try:
if session['nethz']:
g.user = session['nethz']
return
except KeyError:
pass
g.user = None
@app.route('/login', methods=['GET', 'POST'])
def login():
'''
Login page. LDAP-Login only.
'''
if g.user:
return redirect(url_for('index'))
if request.method == 'POST':
user = request.form['user']
passwd = request.form['passwd']
test = ldap.bind_user(user, passwd)
if test is None or passwd == '':
flash('Invalid credentials', 'error')
else:
g.user = session['nethz'] = user
return redirect(url_for('index'))
return render_template('login.html')
@app.route('/logout')
def logout():
'''
Logout page
'''
session.pop('nethz', None)
g.user = None
flash('Successfully logged out.')
return redirect(url_for('index'))
@app.route('/new', methods=['GET', 'POST']) @app.route('/new', methods=['GET', 'POST'])
# @ldap.login_required
def create(): def create():
''' '''
Burger creator Burger creator
...@@ -137,6 +183,6 @@ def create(): ...@@ -137,6 +183,6 @@ def create():
db.session.commit() db.session.commit()
flash('Congrats on your new burger!', 'success') flash('Congrats on your new burger!', 'success')
return redirect(url_for('list')) return redirect(url_for('index'))
return render_template('creator.html') return render_template('creator.html')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment