def _initialize_extensions(application: Flask) -> None: """ Initialize the Flask extensions. :param application: The application instance for which the extensions will be registered. """ babel.init_app(application) babel.locale_selector_func = get_locale bcrypt.init_app(application) csrf.init_app(application) db.init_app(application) login.init_app(application) login.login_message = _l('Please log in to access this page.') login.login_message_category = 'error' login.login_view = 'userprofile.login' login.needs_refresh_message = _l('To protect your profile, please confirm your login.') login.needs_refresh_message_category = 'warning' login.refresh_view = 'userprofile.login_refresh' mail.init_app(application) migrate.init_app(application, db)
def __init__(self): Key.__init__( self, "PERMANENT_SESSION_LIFETIME", "timedelta", label=_l("Session lifetime"), description=_l( "Session expiration time after last visit. " "When session is expired user must login again." ), )
def __init__(self, message=None) -> None: """ Initialize the validator. :param message: The error message shown to the user if the validation fails. """ if not message: message = _l('The email address already is in use.') self.message = message
def _user_photo_endpoint(): from abilian.web.views import images # late import: avoid circular import return images.user_url_args(current_user, 16)[0] def _user_photo_icon_args(icon, url_args): from abilian.web.views import images # late import avoid circular import return images.user_url_args(current_user, max(icon.width, icon.height))[1] user_menu = NavGroup( 'user', 'authenticated', title=lambda c: current_user.name, icon=DynamicIcon(endpoint=_user_photo_endpoint, css='avatar', size=20, url_args=_user_photo_icon_args), condition=is_authenticated, items=( NavItem('user', 'logout', title=_l(u'Logout'), icon='log-out', url=lambda context: url_for('login.logout'), divider=True), )) _ACTIONS = ( NavItem('user', 'login', title=_l(u'Login'), icon='log-in', url=lambda context: url_for('login.login_form'), condition=is_anonymous), user_menu, ) class AuthServiceState(ServiceState): """ State class for :class:`AuthService`
from flask import Flask, request, current_app from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login import LoginManager from flask_mail import Mail from flask_bootstrap import Bootstrap from flask_moment import Moment from flask_babel import Babel, lazy_gettext as _l from elasticsearch import Elasticsearch from config import Config db = SQLAlchemy() migrate = Migrate() login = LoginManager() login.login_view = 'auth.login' login.login_message = _l('Please log in to access this page.') mail = Mail() bootstrap = Bootstrap() moment = Moment() babel = Babel() def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(config_class) db.init_app(app) migrate.init_app(app, db) login.init_app(app) mail.init_app(app) bootstrap.init_app(app)
return security.has_role(current_user, Admin, object=context.get("object")) class WikiPageModalAction(ModalActionMixin, WikiPageAction): pass class WikiAction(Action): Endpoint = CommunityEndpoint _actions = ( WikiPageAction( "wiki:page", "page_viewers", _l("Readers list"), icon="user", condition=lambda ctx: is_manager(context=ctx), endpoint=".page_viewers", ), WikiPageAction("wiki:page", "view", _l("View"), endpoint=".page", icon="eye-open"), WikiPageAction( "wiki:page", "edit", _l("Edit"), endpoint=".page_edit", icon="pencil" ), WikiPageModalAction( "wiki:page", "upload_attachment", _l("Upload an attachment"), url="#upload-files", icon="plus", ),
def breadcrumbs(self): return [ {"label": _l("Communities"), "path": "/communities/"}, {"label": self._model.name}, ]
user_menu = NavGroup( "user", "authenticated", title=lambda c: current_user.name, icon=DynamicIcon( endpoint=_user_photo_endpoint, css="avatar", size=20, url_args=_user_photo_icon_args, ), condition=is_authenticated, items=( NavItem( "user", "logout", title=_l("Logout"), icon="log-out", url=lambda context: url_for("login.logout"), divider=True, ), ), ) _ACTIONS = ( NavItem( "user", "login", title=_l("Login"), icon="log-in", url=lambda context: url_for("login.login_form"), condition=is_anonymous,
def __init__(self): Key.__init__(self, 'PERMANENT_SESSION_LIFETIME', 'timedelta', label=_l(u'Session lifetime'), description=_l( u'Session expiration time after last visit. ' u'When session is expired user must login again.'))
endpoint = self.endpoint if endpoint: return endpoint else: return url_for("%s.index" % self.name) def is_current(self): return g.current_tab == self.name _actions = ( # Navigation NavItem( "section", "communities", title=_l("Communities"), url=lambda context: url_for_orig("communities.index"), condition=lambda ctx: current_user.is_authenticated, ), # Tabs CommunityTabAction("communities:tabs", "wall", _l("Activities")), CommunityTabAction( "communities:tabs", "documents", _l("Documents"), condition=lambda ctx: g.community.has_documents, ), CommunityTabAction( "communities:tabs", "wiki", _l("Wiki"),
from flask import Flask, request, current_app from flask_mail import Mail from flask_login import LoginManager from config import Config from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_babel import Babel from flask_babel import lazy_gettext as _l db = SQLAlchemy() migrate = Migrate() login = LoginManager() login.login_view = 'auth.login' login.login_message = _l('please log in to access this page') mail = Mail() babel = Babel() def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(config_class) login.init_app(app) mail.init_app(app) babel.init_app(app) db.init_app(app) migrate.init_app(app, db) from webapp.auth import bp as auth_bp from webapp.main import bp as main_bp from webapp.api import bp as api_bp