added minimal webinterface

This commit is contained in:
2018-10-21 21:43:11 +02:00
parent 830e50d6f4
commit 86ad36a263
4 changed files with 71 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
{% extends "bootstrap/base.html" %}
{% block title %}Infomentor Notifier{% endblock %}
{% block content %}
<div class="container">
<h1>Infomentor notifier</h1>
<form action="{{ url_for('create') }}" method="post">
<div class="form-group">
<label for="accesscode">AccessCode</label>
<input type="text" class="form-control" name="accesscode" id="accesscode" placeholder="Enter Accesscode">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" id="username" placeholder="Enter username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" id="password" placeholder="Password">
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="notify" id="mail" value="mail" checked>
<label class="form-check-label" for="mail">
Mail
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="notify" id="pushover" value="pushover">
<label class="form-check-label" for="pushover">
Pushover
</label>
</div>
<div class="form-group">
<label for="info">Mail/Pushover Id</label>
<input type="text" class="form-control" id="info" name="info" placeholder="Enter mail/pushover">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
{% endblock %}

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title>Not Found</title>
</head>
<body>
Nothing here!
</body>
</html>

View File

@@ -1,5 +1,5 @@
from infomentor import models, db
from flask import Flask, render_template
from infomentor import model, db
from flask import Flask, render_template, redirect, url_for, request
from flask_bootstrap import Bootstrap
app = Flask(__name__)
@@ -9,10 +9,30 @@ Bootstrap(app)
def home():
return render_template('notfound.html')
@app.route('/addlogin/')
@app.route('/addlogin')
def extra():
return render_template('addlogin.html')
@app.route('/create', methods=['POST'])
def create():
if request.form['accesscode'] != 'fhKjzgV/BXWq4YRxUPO4qYlHWCDf':
return redirect(url_for('home'))
session = db.get_db()
username = request.form['username']
existing_user = session.query(model.User).filter(model.User.name == username).one_or_none()
if existing_user is not None:
return redirect(url_for('home'))
password = request.form['password']
user = model.User(name=username, password=password)
if request.form['notify'] == 'mail':
user.notification = [model.Notification(ntype=model.Notification.Types.EMAIL, info=request.form['info'])]
else:
user.notification = [model.Notification(ntype=model.Notification.Types.PUSHOVER, info=request.form['info'])]
session.add(user)
session.commit()
return "success"
if __name__ == '__main__':
app.run(debug=True)

View File

@@ -8,5 +8,5 @@ setup(
author_email = 'matthias@bilger.info',
description = 'grab infomentor news and push or mail them',
packages = find_packages(),
install_requires = ['pycrypto', 'request', 'sqlalchemy', 'dateparser', 'python-pushover' ],
install_requires = ['pycrypto', 'request', 'sqlalchemy', 'dateparser', 'python-pushover', 'flask', 'flask-bootstrap' ],
)