2013-09-23 16:37:40 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from flask import (Flask, make_response, request, abort, render_template,
|
|
|
|
redirect, url_for)
|
2013-09-20 22:38:17 +00:00
|
|
|
from flask.ext.principal import Principal
|
2013-09-23 16:37:40 +00:00
|
|
|
from flask.ext.login import login_user, LoginManager
|
|
|
|
|
|
|
|
import model
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2013-09-23 16:37:40 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-09-20 22:38:17 +00:00
|
|
|
Principal(app, use_sessions=False)
|
|
|
|
|
2013-09-23 16:37:40 +00:00
|
|
|
app.secret_key = '1cb18882-6d12-440d-a4cc-b7430fb5f884'
|
|
|
|
|
|
|
|
login_manager = LoginManager()
|
|
|
|
login_manager.init_app(app)
|
|
|
|
login_manager.login_view = 'signin'
|
|
|
|
|
|
|
|
|
|
|
|
@login_manager.user_loader
|
|
|
|
def load_user(username):
|
|
|
|
return model.get_user(username)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/', methods=['GET'])
|
|
|
|
def index():
|
|
|
|
return render_template('index.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/signin', methods=['POST'])
|
|
|
|
def signin():
|
|
|
|
username = request.form['username']
|
|
|
|
password = request.form['password']
|
|
|
|
|
|
|
|
#TODO Allow email login
|
|
|
|
verified = model.verify_user(username, password)
|
|
|
|
if verified:
|
|
|
|
logger.debug('Successfully signed in as: %s' % username)
|
|
|
|
|
|
|
|
login_user(verified)
|
|
|
|
return redirect(request.args.get('next') or url_for('index'))
|
|
|
|
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/signin', methods=['GET'])
|
|
|
|
def render_signin_page():
|
|
|
|
return render_template('signin.html')
|
|
|
|
|
|
|
|
|
2013-09-20 15:55:44 +00:00
|
|
|
@app.route('/_ping')
|
|
|
|
@app.route('/v1/_ping')
|
|
|
|
def ping():
|
2013-09-20 22:38:17 +00:00
|
|
|
response = make_response('true', 200)
|
2013-09-20 15:55:44 +00:00
|
|
|
response.headers['X-Docker-Registry-Version'] = '0.6.0'
|
2013-09-20 22:38:17 +00:00
|
|
|
return response
|