53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
|
import logging
|
||
|
import requests
|
||
|
import stripe
|
||
|
|
||
|
from flask import (abort, redirect, request, url_for, render_template,
|
||
|
make_response, Response)
|
||
|
from flask.ext.login import login_user, UserMixin, current_user
|
||
|
from flask.ext.principal import identity_changed
|
||
|
from urlparse import urlparse
|
||
|
|
||
|
from data import model
|
||
|
from app import app, login_manager
|
||
|
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
|
||
|
@login_manager.user_loader
|
||
|
def load_user(username):
|
||
|
logger.debug('Loading user: %s' % username)
|
||
|
return _LoginWrappedDBUser(username)
|
||
|
|
||
|
class _LoginWrappedDBUser(UserMixin):
|
||
|
def __init__(self, db_username, db_user=None):
|
||
|
|
||
|
self._db_username = db_username
|
||
|
self._db_user = db_user
|
||
|
|
||
|
def db_user(self):
|
||
|
if not self._db_user:
|
||
|
self._db_user = model.get_user(self._db_username)
|
||
|
return self._db_user
|
||
|
|
||
|
def is_authenticated(self):
|
||
|
return self.db_user() is not None
|
||
|
|
||
|
def is_active(self):
|
||
|
return self.db_user().verified
|
||
|
|
||
|
def get_id(self):
|
||
|
return unicode(self._db_username)
|
||
|
|
||
|
|
||
|
def common_login(db_user):
|
||
|
if login_user(_LoginWrappedDBUser(db_user.username, db_user)):
|
||
|
logger.debug('Successfully signed in as: %s' % db_user.username)
|
||
|
new_identity = QuayDeferredPermissionUser(db_user.username, 'username')
|
||
|
identity_changed.send(app, identity=new_identity)
|
||
|
return True
|
||
|
else:
|
||
|
logger.debug('User could not be logged in, inactive?.')
|
||
|
return False
|