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


parents 2c60a20c 75eec6dd
Pipeline #2676 skipped with stage
- deploy
stage: deploy
image: alpine:latest
when: manual
- '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 )'
- ssh -p22 "mkdir -p ~/app_tmp/"
- rsync -rav -e ssh --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded ./
- ssh -p22 "cp ~/app/app/ ~/app_tmp/app/"
- ssh -p22 "mv ~/app ~/app_old && mv ~/app_tmp ~/app && chmod -R 700 ~/app"
- ssh -p22 "touch ~/"
- ssh -p22 "rm -rf ~/app_old"
name: production
# 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:
\$ virtualenv venv
This will initialise the virtual environment in the `venv` directory. To
activate it, source the following script:
\$ 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`.
\$ pip install -r requirements.txt
### Database & Admin User
To create the database structure and add an admin user, run
\$ ./ <admin_username> <admin_password>
## Run
After that, you can run the website by executing ``. The website is
served at `` by default.
......@@ -47,7 +47,8 @@ section .container {
cursor: pointer;
#creator input {
#creator input,
.login input {
max-width: 400px;
text-align: center;
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>
<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"/>
{% endblock %}
\ No newline at end of file
Contains all views
from app import app
from app import app, ldap
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 .mappings import BREAD, PATTY, TOPPINGS, SIDE
from .models import db, Burger, Vote
def list():
def index():
Front page. Shows a list of all burgers
......@@ -31,6 +31,7 @@ def list():
@app.route('/vote', methods=['POST'])
# @ldap.login_required
def vote():
Handles POST requests for voting
......@@ -40,7 +41,7 @@ def vote():
Display an error-level flash message and return
flash(message, 'error')
return redirect(url_for('list'))
return redirect(url_for('index'))
# Check if the burger_id is valid
burger_id = request.form.get('burger_id')
......@@ -74,10 +75,55 @@ def vote():
flash('Your like has been removed.', 'success')
return redirect(url_for('list'))
return redirect(url_for('index'))
def load_user():
Load user data before any request processing
if session['nethz']:
g.user = session['nethz']
except KeyError:
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')
g.user = session['nethz'] = user
return redirect(url_for('index'))
return render_template('login.html')
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'])
# @ldap.login_required
def create():
Burger creator
......@@ -137,6 +183,6 @@ def create():
flash('Congrats on your new burger!', 'success')
return redirect(url_for('list'))
return redirect(url_for('index'))
return render_template('creator.html')
Markdown is supported
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