Ejemplo n.º 1
0
def init():
    global security
    
    app.config['SECURITY_CONFIRMABLE'] = not app.config['MAIL_SUPPRESS_SEND']
    app.config['SECURITY_CHANGEABLE'] = True
    app.config['SECURITY_SEND_PASSWORD_CHANGE_EMAIL'] = not app.config['MAIL_SUPPRESS_SEND']
    app.config['SECURITY_POST_CHANGE_VIEW'] = "profile.html"
    app.config['SECURITY_PASSWORD_HASH'] = "bcrypt"
    app.config['SECURITY_MSG_CONFIRMATION_REQUIRED'] = (
            Markup('Email requires confirmation. <a href="/confirm">Resend confirmation instructions</a>.'), 
            'error')
    # This comes from config: app.config['SECURITY_REGISTERABLE']

    # Update all salts with SECRET_KEY if they are not set
    secret_key = app.config['SECRET_KEY']
    for salt in ('SECURITY_PASSWORD_SALT', 'SECURITY_CONFIRM_SALT', 
            'SECURITY_RESET_SALT', 'SECURITY_LOGIN_SALT', 
            'SECURITY_REMEMBER_SALT'):
        app.config[salt] = app.config.get(salt, secret_key)

    app.config['SECURITY_EMAIL_SENDER'] = app.config['MAIL_DEFAULT_SENDER']

    app.config['SECURITY_POST_LOGIN_VIEW'] = "/"

    security = Security(app, CustomUserDatastore(), 
            login_form=CustomLoginForm,
            register_form=CustomRegisterForm,
            confirm_register_form=CustomRegisterForm)

    security.send_mail_task(send_security_mail)

    if app.config['SECURITY_CONFIRMABLE'] and app.config['NEW_USER_NOTIFICATION']:
        user_confirmed.connect(new_user_notification, app)
Ejemplo n.º 2
0
def confirmations(app):
    records = []

    def record(sender, *args, **kwargs):
        records.append(kwargs['user'])
    user_confirmed.connect(record, app)

    try:
        yield records
    finally:
        user_confirmed.disconnect(record, app)
Ejemplo n.º 3
0
def confirmations(app):
    records = []

    def record(sender, *args, **kwargs):
        records.append(kwargs['user'])
        print("Record: ", records[-1])
    user_confirmed.connect(record, app)

    try:
        yield records
    finally:
        print("Disconnect record: ", records)
        user_confirmed.disconnect(record, app)
Ejemplo n.º 4
0
def init():
    global security

    app.config["SECURITY_CONFIRMABLE"] = not app.config["MAIL_SUPPRESS_SEND"]
    app.config["SECURITY_CHANGEABLE"] = True
    app.config["SECURITY_SEND_PASSWORD_CHANGE_EMAIL"] = not app.config["MAIL_SUPPRESS_SEND"]
    app.config["SECURITY_POST_CHANGE_VIEW"] = "profile.html"
    app.config["SECURITY_PASSWORD_HASH"] = "bcrypt"
    app.config["SECURITY_MSG_CONFIRMATION_REQUIRED"] = (
        Markup('Email requires confirmation. <a href="/confirm">Resend confirmation instructions</a>.'),
        "error",
    )
    # This comes from config: app.config['SECURITY_REGISTERABLE']

    # Update all salts with SECRET_KEY if they are not set
    secret_key = app.config["SECRET_KEY"]
    for salt in (
        "SECURITY_PASSWORD_SALT",
        "SECURITY_CONFIRM_SALT",
        "SECURITY_RESET_SALT",
        "SECURITY_LOGIN_SALT",
        "SECURITY_REMEMBER_SALT",
    ):
        app.config[salt] = app.config.get(salt, secret_key)

    app.config["SECURITY_EMAIL_SENDER"] = app.config["MAIL_DEFAULT_SENDER"]

    app.config["SECURITY_POST_LOGIN_VIEW"] = "/"

    security = Security(
        app,
        CustomUserDatastore(),
        login_form=CustomLoginForm,
        register_form=CustomRegisterForm,
        confirm_register_form=CustomRegisterForm,
    )

    security.send_mail_task(send_security_mail)

    if app.config["SECURITY_CONFIRMABLE"] and app.config["NEW_USER_NOTIFICATION"]:
        user_confirmed.connect(new_user_notification, app)
Ejemplo n.º 5
0
def register_users_blueprint_and_signals(app):
    """Registers blueprint to app and connects signals"""
    app.register_blueprint(users_blueprint)
    user_confirmed.connect(when_user_confirmed)
    email_dispatched.connect(log_email_message)
    update_user_rss.connect(when_update_user_rss)
Ejemplo n.º 6
0
def register_users_blueprint_and_signals(app):
    app.register_blueprint(users_blueprint)
    user_confirmed.connect(when_user_confirmed)
Ejemplo n.º 7
0
        db.Integer(),
        db.ForeignKey('user.id', ondelete="CASCADE")),
    db.Column(
        'committee_id',
        db.Integer(),
        db.ForeignKey('committee.id', ondelete="CASCADE")),
    db.Column(
        'created_at',
        db.DateTime(timezone=True),
        index=True,
        unique=False,
        nullable=False,
        server_default=func.now()))

user_committee_alerts = db.Table(
    'user_committee_alerts',
    db.Column(
        'user_id',
        db.Integer(),
        db.ForeignKey('user.id', ondelete="CASCADE")),
    db.Column(
        'committee_id',
        db.Integer(),
        db.ForeignKey('committee.id', ondelete="CASCADE")))


# Setup Flask-Security
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore, confirm_register_form=forms.RegisterForm, send_confirmation_form=forms.SendConfirmationForm)
user_confirmed.connect(user_confirmed_handler, app)
Ejemplo n.º 8
0
        db.Integer(),
        db.ForeignKey('user.id', ondelete="CASCADE")),
    db.Column(
        'committee_id',
        db.Integer(),
        db.ForeignKey('committee.id', ondelete="CASCADE")),
    db.Column(
        'created_at',
        db.DateTime(timezone=True),
        index=True,
        unique=False,
        nullable=False,
        server_default=func.now()))

user_committee_alerts = db.Table(
    'user_committee_alerts',
    db.Column(
        'user_id',
        db.Integer(),
        db.ForeignKey('user.id', ondelete="CASCADE")),
    db.Column(
        'committee_id',
        db.Integer(),
        db.ForeignKey('committee.id', ondelete="CASCADE")))


# Setup Flask-Security
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore, confirm_register_form=forms.RegisterForm, send_confirmation_form=forms.SendConfirmationForm)
user_confirmed.connect(user_confirmed_handler, app)