from flask import Flask, render_template, request, redirect, url_for
from rcblog import utils


app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/posts/<int:post_id>')
def post(post_id):
    return utils.md_to_html(open('rcblog/templates/test.md').read())


@app.route('/posts/add')
def add_post():
    return render_template('add_post.html')


@app.route('/posts')
def posts_list():
    return render_template('posts.html', posts=utils.get_posts_list())


@app.route('/posts', methods=['POST'])
def commit_post():
    title = request.form['title']
    md = request.form['post']
    with open('/home/sanchopanca/src/rcblog/rcblog/posts_repository/{}.md'.format(title), 'w') as f:
        f.write(md)
    return redirect(url_for('index'))

@@ -1,12 +1,41 @@
+from functools import wraps%0A%0A
 from flask i
@@ -90,16 +90,26 @@
  url_for
+, Response
 %0Afrom rc
@@ -127,17 +127,16 @@
  utils%0A%0A
-%0A
 app = Fl
@@ -147,24 +147,766 @@
 __name__)%0A%0A%0A
+def check_auth(username, password):%0A    %22%22%22This function is called to check if a username /%0A    password combination is valid.%0A    %22%22%22%0A    return username == 'admin' and password == 'secret'%0A%0A%0Adef authenticate():%0A    %22%22%22Sends a 401 response that enables basic auth%22%22%22%0A    return Response(%0A        'Could not verify your access level for that URL.%5Cn'%0A        'You have to login with proper credentials', 401,%0A        %7B'WWW-Authenticate': 'Basic realm=%22Login Required%22'%7D)%0A%0A%0Adef requires_auth(f):%0A    @wraps(f)%0A    def decorated(*args, **kwargs):%0A        auth = request.authorization%0A        if not auth or not check_auth(auth.username, auth.password):%0A            return authenticate()%0A        return f(*args, **kwargs)%0A%0A    return decorated%0A%0A%0A
 @app.route('
@@ -1115,16 +1115,31 @@
 s/add')%0A
+@requires_auth%0A
 def add_

Add basic auth