This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/app.py

74 lines
1.6 KiB
Python
Raw Normal View History

2013-09-23 16:37:40 +00:00
import logging
from flask import (Flask, make_response, request, abort, send_file,
2013-09-23 16:37:40 +00:00
redirect, url_for)
from flask.ext.principal import Principal
from flask.ext.login import login_user, LoginManager, UserMixin
2013-09-23 16:37:40 +00:00
import model
app = Flask(__name__)
2013-09-23 16:37:40 +00:00
logger = logging.getLogger(__name__)
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'
class _LoginWrappedDBUser(UserMixin):
def __init__(self, db_user):
self.db_user = db_user
def is_active(self):
return self.db_user.verified
def get_id(self):
return unicode(self.db_user.username)
2013-09-23 16:37:40 +00:00
@login_manager.user_loader
def load_user(username):
db_user = model.get_user(username)
if db_user:
return _LoginWrappedDBUser(db_user)
else:
return None
2013-09-23 16:37:40 +00:00
@app.route('/', methods=['GET'])
def index():
return send_file('templates/index.html')
2013-09-23 16:37:40 +00:00
@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(_LoginWrappedDBUser(verified))
2013-09-23 16:37:40 +00:00
return redirect(request.args.get('next') or url_for('index'))
abort(403)
@app.route('/signin', methods=['GET'])
def render_signin_page():
return send_file('templates/signin.html')
2013-09-23 16:37:40 +00:00
@app.route('/_ping')
@app.route('/v1/_ping')
def ping():
response = make_response('true', 200)
response.headers['X-Docker-Registry-Version'] = '0.6.0'
return response