--- a/mouchak/classes/field.py +++ b/mouchak/classes/field.py @@ -8,8 +8,8 @@ def __init__(self): """@todo: to be defined1 """ - self.id = object.id - self.tags = object.tags - self.type = object.type - self.body = object.body + self.id = object.id + self.tags = object.tags + self.type = object.type + self.body = object.body --- a/mouchak/sampleConf.py +++ b/mouchak/sampleConf.py @@ -7,4 +7,7 @@ ''' HOST = '0.0.0.0' PORT = 5000 +SECRET_KEY = 'a-uuid-string-see-python-uuid' +ADMIN_USERNAME = 'youradminusername' +ADMIN_PASSWORD = 'youradminpassword' --- a/mouchak/server.py +++ b/mouchak/server.py @@ -49,8 +49,12 @@ @app.route('/edit', methods=['GET']) def edit(): - return flask.render_template('editor.html', content=getContent(), - title=conf.SITE_TITLE) + if "logged_in" in flask.session: + flask.session['key'] = conf.SECRET_KEY + return flask.render_template('editor.html', content=getContent(), + title=conf.SITE_TITLE) + else: + return flask.redirect(flask.url_for('login')) @app.route('/page', methods=['POST']) @@ -104,6 +108,7 @@ def updateMenu(_id): if flask.request.method == 'PUT': changedMenu = flask.request.json + print "changed menu:" print changedMenu res = siteMenu.update({'_id': bson.ObjId(_id)}, changedMenu) print res @@ -117,6 +122,36 @@ # return flask.jsonify(status='deleted') +# Basic login for one single admin user whose credentials are in conf.py +@app.route('/login', methods=['GET', 'POST']) +def login(): + error = None + if flask.request.method == 'POST': + print flask.request.form + if flask.request.form['username'] != conf.ADMIN_USERNAME: + error = 'Invalid username' + elif flask.request.form['password'] != conf.ADMIN_PASSWORD: + error = 'Invaid password' + else: + flask.session['logged_in'] = True + flask.session['key'] = conf.SECRET_KEY + flask.flash('You were logged in') + return flask.redirect(flask.url_for('edit')) + return flask.render_template('login.html', error=error) + +@app.route('/logout') +def logout(): + flask.session.pop('logged_in', None) + flask.flash('You were logged out') + return flask.redirect(flask.url_for('login')) + +@app.route('/robots.txt') +@app.route('/crossdomain.xml') +def static_from_root(): + return flask.send_from_directory(app.static_folder, request.path[1:]) + + +app.config.from_object(conf) if __name__ == "__main__": app.run(debug=True, host=conf.HOST, port=conf.PORT) --- a/mouchak/templates/editor.html +++ b/mouchak/templates/editor.html @@ -23,8 +23,14 @@
--- /dev/null +++ b/mouchak/templates/login.html @@ -1 +1,65 @@ + + + + + + + + +Please enter admin credentials to login
+ +