def init_app(self, app): """Flask application initialization.""" self.init_config(app) self.create_resources() self.init_views(app) app.extensions['sonar'] = self if app.config['SONAR_APP_ENABLE_CORS']: from flask_cors import CORS CORS(app) Bootstrap(app) Wiki(app) app.context_processor(utility_processor) # Connect to signal sent when a user is created in Flask-Security. user_registered.connect(user_registered_handler, weak=False) # Connect to signal sent when a file is uploaded or deleted file_uploaded.connect(file_uploaded_listener, weak=False) file_deleted.connect(file_deleted_listener, weak=False) # Add user's full name before record index before_record_index.connect(add_full_name, weak=False)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['sonar_app'] = self if app.config['SONAR_APP_ENABLE_CORS']: from flask_cors import CORS CORS(app) Bootstrap(app) Wiki(app) # Register assets for sonar-ui assets = Environment(app) assets.register( 'sonar_ui_js', Bundle('sonar-ui/runtime.js', 'sonar-ui/polyfills.js', 'sonar-ui/main.js', output='sonar_ui.%(version)s.js')) app.context_processor(utility_processor) # Connect to signal sent when a user is created in Flask-Security. user_registered.connect(user_registered_handler, weak=False)
def create_app(config_name=None): # Create the database tables. app = flask.Flask(__name__) if not config_name: app.config.from_envvar('FLASKDASH_SETTINGS') else: app.config.from_pyfile(config_name) from mahercpa.modules.models import db, Budget, BudgetVersion, Client, User, Role, user_datastore db.init_app(app) mail.init_app(app) #user_datastore = SQLAlchemySessionUserDatastore(db, User, Role) security.init_app(app, user_datastore) # This processor is added to only the register view @user_registered.connect_via(app) def user_registered_sighandler(sender, user, confirm_token): #print("print-user_registered_sighandler:", user.email) user_domain = str(user.email).split('@')[1] #print(user_domain) user_client = Client.query.filter_by(domain=user_domain).first() client_role = Role.query.filter_by(name.ilike(user_client.abbreviation)).first() if user_client is not None: #print(user_client.name) user.client.append(user_client) user.roles.append(client_role) db_session.commit() user_registered.connect(user_registered_sighandler) apimanager.init_app(app=app) #Don't pass in db a second time, just the app object # Create API endpoints, which will be available at /api/<tablename> by # default. Allowed HTTP methods can be specified as well. with app.app_context(): client_cols = ['name','abbreviation','domain'] apimanager.create_api(Client, methods=['GET'], include_columns=client_cols, app=app) apimanager.create_api(BudgetVersion, methods=['GET','POST'], results_per_page=100, app=app) from mahercpa.views.main import main app.register_blueprint(main) from mahercpa.views.bud_track import bud_track app.register_blueprint(bud_track) from mahercpa.views.admin import admin app.register_blueprint(admin) from mahercpa.views.dash_revenue import dash_revenue app.register_blueprint(dash_revenue) return app
add_default_role, check_dates, safe_send_mail, ) from art17.auth.forms import DatasetForm, LoginForm from art17.auth.security import (Art17LocalRegisterForm, Art17LDAPRegisterForm, Art17AdminEditUserForm, AnonymousUser, encrypt_password, verify) from art17.common import HOMEPAGE_VIEW_NAME, get_config def user_registered_sighandler(app, user, confirm_token): add_default_role(user) user_registered.connect(user_registered_sighandler) @auth.app_errorhandler(PermissionDenied) def handle_permission_denied(error): html = render_template('auth/permission_denied.html') return Response(html, status=403) @auth.route('/auth/register/local', methods=['GET', 'POST']) def register_local(): form = Art17LocalRegisterForm(request.form) if form.validate_on_submit(): register_user(**form.to_dict()) return render_template('message.html', message="")
mail = Mail(app) import stripe stripe.api_key = app.config["STRIPE_API_KEY"] from mixpanel import Mixpanel mp = Mixpanel(app.config["PROJECT_TOKEN"]) def mixpanel_register_new_user(sender, user, confirm_token, **extra): mp.people_set(user.id, {'$first_name': user.first_name, '$last_name': user.last_name, '$email': user.email}) user_registered.connect(mixpanel_register_new_user, app) @app.context_processor def navbar_context_processor(): categories = db.session.query(Category).all() return dict(categories=categories) @app.route('/') def hello(): projects = db.session.query(Project).order_by(Project.time_created.desc()).limit(15) return render_template("index.html", projects=projects) @app.route('/projects/create/', methods=['GET', 'POST'])
""" g.user_id = identity.id or None if g.user_id is None: g.logged_off = True flash("Successfully Logged Out.", category="doc doc system message") else: g.logged_in = True flash("Successfully Logged In.", category="doc doc system message") @user_logged_out.connect def user_logged_out_handler(*args, **kwargs): """Clear the login_session upon logout""" login_session.clear() # We should try to handle some errors # ( 500 ) # ( 404 ) @app.errorhandler(500) @app.errorhandler(404) def errors_and_stuff(error=None): if error is not None: print error return render_template(resources.error["html"], error_code=404) # When the user_registered signal is triggered the app should take action user_registered.connect(newly_registered_user)
def init_security_logging(): user_logged_in.connect(log_user_logged_in) user_logged_out.connect(log_user_logged_out) user_registered.connect(log_user_registered) user_confirmed.connect(log_user_confirmed)