diff --git a/infomentor/templates/addlogin.html b/infomentor/templates/addlogin.html new file mode 100644 index 0000000..3cb2bf1 --- /dev/null +++ b/infomentor/templates/addlogin.html @@ -0,0 +1,39 @@ +{% extends "bootstrap/base.html" %} +{% block title %}Infomentor Notifier{% endblock %} + +{% block content %} +
+

Infomentor notifier

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+{% endblock %} diff --git a/infomentor/templates/notfound.html b/infomentor/templates/notfound.html new file mode 100644 index 0000000..3dc3f5f --- /dev/null +++ b/infomentor/templates/notfound.html @@ -0,0 +1,8 @@ + + + Not Found + + + Nothing here! + + diff --git a/infomentor/web.py b/infomentor/web.py index 1b6c66b..a60b512 100644 --- a/infomentor/web.py +++ b/infomentor/web.py @@ -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) diff --git a/setup.py b/setup.py index 347a495..4834b97 100644 --- a/setup.py +++ b/setup.py @@ -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' ], )