Exemplo n.º 1
0
 def action_untrash(self, ids):
     qs = self.model.objects(pk__in=ids)
     count = qs.update(set__mark_for_delete=0, multi=True)
     if count:
         flash(
             gettext("%(count)s records has been restore from trash.",
                     count=count))
Exemplo n.º 2
0
def init_admin(
    app,
    admin_app=None,
    url='/admin',
    name="Shortener URL Admin",
    base_template='shortener_url/admin/layout.html',
    #index_template='shortener_url/admin/index.html',
    index_view=None,
):

    index_view = index_view or AdminIndexView(
        #template=index_template,
        url=url,
        name="home")

    admin = admin_app or Admin(app,
                               url=url,
                               name=name,
                               index_view=index_view,
                               base_template=base_template,
                               template_mode='bootstrap3')

    admin.add_view(URLView(models.URL, name=gettext("URLs")))

    admin.add_view(
        UserView(
            models.Role,
            #name=gettext("Roles"),
            category=gettext("Users")))

    admin.add_view(
        UserView(
            models.User,
            #name=gettext("Users"),
            category=gettext("Users")))

    admin.add_view(
        UserView(
            models.SocialConnection,
            #name=gettext("Social Connections"),
            category=gettext("Users")))
Exemplo n.º 3
0
class SocialConnection(BaseDocument):

    user = fields.ReferenceField(User)

    provider = fields.StringField(max_length=255)

    profile_id = fields.StringField(max_length=255)

    username = fields.StringField(max_length=255)

    email = fields.StringField(max_length=255)

    access_token = fields.StringField(max_length=255)

    secret = fields.StringField(max_length=255)

    first_name = fields.StringField(max_length=255,
                                    help_text=gettext("First Name"))

    last_name = fields.StringField(max_length=255,
                                   help_text=gettext("Last Name"))

    cn = fields.StringField(max_length=255, help_text=gettext("Common Name"))

    profile_url = fields.StringField(max_length=512)

    image_url = fields.StringField(max_length=512)

    def get_user(self):
        return self.user

    @classmethod
    def by_profile(cls, profile):
        provider = profile.data["provider"]
        return cls.objects(provider=provider, profile_id=profile.id).first()

    @classmethod
    def from_profile(cls, user, profile):
        if not user or user.is_anonymous:
            email = profile.data.get("email")
            if not email:
                msg = "Cannot create new user, authentication provider did not not provide email"
                logging.warning(msg)
                raise Exception(_(msg))
            conflict = User.objects(email=email).first()
            if conflict:
                msg = "Cannot create new user, email {} is already used. Login and then connect external profile."
                msg = _(msg).format(email)
                logging.warning(msg)
                raise Exception(msg)

            now = utils.utcnow()
            user = User(
                email=email,
                first_name=profile.data.get("first_name"),
                last_name=profile.data.get("last_name"),
                confirmed_at=now,
                active=True,
            )
            user.save()

        connection = cls(user=user, **profile.data)
        connection.save()
        return connection

    def __unicode__(self):
        return self.email

    meta = {
        'collection': 'socialconnection',
        'indexes': ['user', 'profile_id'],
    }
Exemplo n.º 4
0
class Config(object):

    BOOTSTRAP_SERVE_LOCAL = True
    TEMPLATES_AUTO_RELOAD = True

    SESSION_PROTECTION = 'strong'

    DB_SETTINGS = {
        'host': config('SHORTURL_DB_URL', 'mongodb://mongo/shorturl'),
        'db': 'shorturl'
    }

    SECRET_KEY = config('SHORTURL_SECRET_KEY', 'very very secret key key key')

    DEBUG = config('SHORTURL_DEBUG', False, cast=bool)

    SENTRY_DSN = config('SHORTURL_SENTRY_DSN', None)

    #---Flask-Babel
    TIMEZONE = "UTC"  #"Europe/Paris"
    DEFAULT_LANG = "fr"
    ACCEPT_LANGUAGES = ['en', 'fr']

    ACCEPT_LANGUAGES_CHOICES = (
        ('en', gettext('English')),
        ('fr', gettext('French')),
    )

    BABEL_DEFAULT_LOCALE = DEFAULT_LANG
    BABEL_DEFAULT_TIMEZONE = TIMEZONE

    RECAPTCHA2_SITEKEY = config('SHORTURL_RECAPTCHA2_SITEKEY', None)
    RECAPTCHA2_SECRETKEY = config('SHORTURL_RECAPTCHA2_SECRETKEY', None)

    MAIL_ADMINS = config('SHORTURL_MAIL_ADMIN', "*****@*****.**")

    #---Flask-Mail
    MAIL_SERVER = config('SHORTURL_MAIL_SERVER', "127.0.0.1")
    MAIL_PORT = config('SHORTURL_MAIL_PORT', 25, cast=int)
    MAIL_USE_TLS = config('SHORTURL_MAIL_USE_TLS', False, cast=bool)
    MAIL_USE_SSL = config('SHORTURL_MAIL_USE_SSL', False, cast=bool)
    #MAIL_DEBUG : default app.debug
    MAIL_USERNAME = config('SHORTURL_MAIL_USERNAME', None)
    MAIL_PASSWORD = config('SHORTURL_MAIL_PASSWORD', None)
    MAIL_DEFAULT_SENDER = config('SHORTURL_MAIL_DEFAULT_SENDER',
                                 "*****@*****.**")
    MAIL_MAX_EMAILS = None
    #MAIL_SUPPRESS_SEND : default app.testing
    MAIL_ASCII_ATTACHMENTS = False
    LOGGING_MAIL_ENABLE = config('SHORTURL_LOGGING_MAIL_ENABLE',
                                 False,
                                 cast=bool)

    #---Flask-Assets
    FLASK_ASSETS_USE_CDN = False
    FLASK_ASSETS_DEBUG = False
    FLASK_ASSETS_URL_EXPIRE = True

    #---Flask-Admin
    FLASK_ADMIN_SWATCH = config('SHORTURL_FLASK_ADMIN_SWATCH', "darkly")

    #---Flask-Login
    #LOGIN_DISABLED = False

    #---Flask Security
    SECURITY_PASSWORD_SALT = "abc"
    # SECURITY_PASSWORD_HASH = "bcrypt"  # requires py-bcrypt
    # SECURITY_PASSWORD_HASH = "pbkdf2_sha512"
    SECURITY_PASSWORD_HASH = "plaintext"
    SECURITY_EMAIL_SENDER = "*****@*****.**"
    SECURITY_CONFIRMABLE = False
    SECURITY_REGISTERABLE = False
    SECURITY_RECOVERABLE = False
    SECURITY_CHANGEABLE = False
    SECURITY_CONFIRM_SALT = "570be5f24e690ce5af208244f3e539a93b6e4f05"
    SECURITY_REMEMBER_SALT = "de154140385c591ea771dcb3b33f374383e6ea47"
    SECURITY_DEFAULT_REMEMBER_ME = True
Exemplo n.º 5
0
class SocialConnectionView(ModelView):
    _name = gettext(u"Social Connections")
Exemplo n.º 6
0
class RoleView(ModelView):
    _name = gettext(u"Rules")
Exemplo n.º 7
0
class UserView(ModelView):
    _name = gettext(u"Users")

    column_list = ('email', )