def init_app(self, app):
        if app is None:
            return

        blueprint = Blueprint(AUTH_CONFIG_KEY.lower(), __name__)

        config = default_config.copy()
        try:
            config.update(app.config.get(AUTH_CONFIG_KEY, {}))
        except:
            pass
        app.config[AUTH_CONFIG_KEY] = config

        app.logger.debug("Auth Configuration: %s" % config)

        # setup the login manager extension
        login_manager = LoginManager()
        login_manager.anonymous_user = Anonymous
        login_manager.login_view = config[LOGIN_VIEW_KEY]
        login_manager.setup_app(app)

        # get some things form the config
        Provider = get_class_from_config(AUTH_PROVIDER_KEY, config)
        Encryptor = get_class_from_config(PASSWORD_ENCRYPTOR_KEY, config)
        Form = get_class_from_config(LOGIN_FORM_CLASS_KEY, config)

        # create the service and auth provider and add it to the app
        # so it can be referenced elsewhere
        app.login_manager = login_manager
        app.password_encryptor = Encryptor(config[SALT_KEY])
        app.auth_provider = Provider(Form)

        DEBUG_LOGIN = "******"
        ERROR_LOGIN = "******"
        DEBUG_LOGOUT = "User logged out, redirecting to: %s"
        FLASH_INACTIVE = "Inactive user"

        @login_manager.user_loader
        def load_user(id):
            try:
                return user_service.get_user_with_id(id)
            except Exception, e:
                current_app.logger.error("Error getting user: %s" % e)
                return None
Beispiel #2
0
    def init_app(self, app):
        if app is None: return

        blueprint = Blueprint(AUTH_CONFIG_KEY.lower(), __name__)

        config = default_config.copy()
        try:
            config.update(app.config.get(AUTH_CONFIG_KEY, {}))
        except:
            pass
        app.config[AUTH_CONFIG_KEY] = config

        app.logger.debug("Auth Configuration: %s" % config)

        # setup the login manager extension
        login_manager = LoginManager()
        login_manager.anonymous_user = Anonymous
        login_manager.login_view = config[LOGIN_VIEW_KEY]
        login_manager.setup_app(app)

        # get some things form the config
        Provider = get_class_from_config(AUTH_PROVIDER_KEY, config)
        Encryptor = get_class_from_config(PASSWORD_ENCRYPTOR_KEY, config)
        Form = get_class_from_config(LOGIN_FORM_CLASS_KEY, config)

        # create the service and auth provider and add it to the app
        # so it can be referenced elsewhere
        app.login_manager = login_manager
        app.password_encryptor = Encryptor(config[SALT_KEY])
        app.auth_provider = Provider(Form)

        DEBUG_LOGIN = '******'
        ERROR_LOGIN = '******'
        DEBUG_LOGOUT = 'User logged out, redirecting to: %s'
        FLASH_INACTIVE = 'Inactive user'

        @login_manager.user_loader
        def load_user(id):
            try:
                return user_service.get_user_with_id(id)
            except Exception, e:
                current_app.logger.error('Error getting user: %s' % e)
                return None
Beispiel #3
0
USERS = {1: User(u"Notch", 1), 2: User(u"Steve", 2), 3: User(u"Creeper", 3, False)}

USER_NAMES = dict((u.name, u) for u in USERS.itervalues())


app = Flask(__name__)

SECRET_KEY = "yeah, not actually a secret"
DEBUG = True

app.config.from_object(__name__)

login_manager = LoginManager()

login_manager.anonymous_user = Anonymous
login_manager.login_view = "login"
login_manager.login_message = u"Please log in to access this page."
login_manager.refresh_view = "reauth"


@login_manager.user_loader
def load_user(id):
    return USERS.get(int(id))


login_manager.setup_app(app)


@app.route("/")
def index():
Beispiel #4
0
from pwdmanager import LmfdbUser, LmfdbAnonymousUser

# TODO update this url, needed for the user login token
base_url = "http://www.l-functions.org"


@login_manager.user_loader
def load_user(userid):
    from pwdmanager import LmfdbUser
    return LmfdbUser(userid)


login_manager.login_view = "users.info"

# this anonymous user has the is_admin() method
login_manager.anonymous_user = LmfdbAnonymousUser


# globally define the user and username
@app.context_processor
def ctx_proc_userdata():
    userdata = {}
    userdata['username'] = '******' if current_user.is_anonymous(
    ) else current_user.name
    userdata['user_is_authenticated'] = current_user.is_authenticated()
    userdata['user_is_admin'] = current_user.is_admin()
    return userdata


# blueprint specific definition of the body_class variable
@login_page.context_processor
Beispiel #5
0
import pwdmanager
from pwdmanager import LmfdbUser, LmfdbAnonymousUser

# TODO update this url, needed for the user login token
base_url = "http://www.l-functions.org"

@login_manager.user_loader
def load_user(userid):
  from pwdmanager import LmfdbUser
  return LmfdbUser(userid) 

login_manager.login_view = "users.info"

# this anonymous user has the is_admin() method
login_manager.anonymous_user = LmfdbAnonymousUser

# globally define the user and username
@app.context_processor
def ctx_proc_userdata():
  userdata = {}
  userdata['username'] = '******' if current_user.is_anonymous() else current_user.name
  userdata['user_is_authenticated'] =  current_user.is_authenticated()
  userdata['user_is_admin'] = current_user.is_admin()
  return userdata

# blueprint specific definition of the body_class variable
@login_page.context_processor
def body_class():
  return { 'body_class' : 'login' }