示例#1
0
文件: admin.py 项目: gr2m/gbi-server
def create_user():
    form = CreateUserForm()
    if form.validate_on_submit():
        user = User(form.data['email'], form.data['password'])
        user.realname = form.data['realname']
        user.florlp_name = form.data['florlp_name']
        user.type = form.data.get('type')
        user.street = form.data['street']
        user.housenumber =  form.data['housenumber']
        user.zipcode = form.data['zipcode']
        user.city = form.data['city']
        if not form.data['verified']:
            verify = EmailVerification.verify(user)
            db.session.add(verify)
            send_mail(
                _("Email verification mail subject"),
                render_template("user/verify_mail.txt", user=user, verify=verify, _external=True),
                [user.email]
            )
        else:
            user.verified = True
            if form.data['activate']:
                user.active = True
        db.session.add(user)
        db.session.commit()

        init_user_boxes(user, current_app.config.get('COUCH_DB_URL'))

        flash(_('User created', email=user.email), 'success')
        return redirect(url_for('admin.user_list'))
    return render_template('admin/create_user.html', form=form)
示例#2
0
文件: user.py 项目: gr2m/gbi-server
def refresh_florlp():
    user = current_user
    form = RefreshFlorlpForm(request.form)
    if form.validate_on_submit():
        layers = [(current_app.config.get('USER_READONLY_LAYER'), current_app.config.get('USER_READONLY_LAYER_TITLE'))]
        try:
            florlp_session = create_florlp_session(user.florlp_name, form.data['password'])
        except FLOrlpUnauthenticated:
            flash(_('Invalid florlp password'), 'error')
            return render_template("user/refresh_florlp.html", form=form)
        try:
            schema, feature_collection = latest_flursteuck_features(florlp_session)
        finally:
            remove_florlp_session(florlp_session)

        feature_collection = transform_geojson(from_srs=current_app.config.get('FLORLP_SHP_SRS'), to_srs=3857, geojson=feature_collection)

        init_user_boxes(user, current_app.config.get('COUCH_DB_URL'))
        couch = CouchDBBox(current_app.config.get('COUCH_DB_URL'), '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))

        if (not couch.layer_schema(current_app.config.get('USER_WORKON_LAYER')) or not couch.layer_extent(current_app.config.get('USER_WORKON_LAYER'))) and not user.type:
            layers.append((current_app.config.get('USER_WORKON_LAYER'), current_app.config.get('USER_WORKON_LAYER_TITLE')))

        for layer, title in layers:
            couch.clear_layer(layer)
            couch.store_layer_schema(layer, schema, title=title)
            couch.store_features(layer, feature_collection['features'])

            signals.features_updated.send(user, layer=layer)


        flash(_('Refreshed florlp data'), 'success')
        return redirect(url_for(".index"))
    return render_template("user/refresh_florlp.html", form=form)
示例#3
0
文件: user.py 项目: gr2m/gbi-server
def new():
    form = NewUserForm()
    if form.validate_on_submit():
        florlp_session = False
        user_type = form.data['type']
        layers = [(current_app.config.get('USER_READONLY_LAYER'), current_app.config['USER_READONLY_LAYER_TITLE']), (current_app.config.get('USER_WORKON_LAYER'), current_app.config['USER_WORKON_LAYER_TITLE'])]
        if user_type == User.Type.CUSTOMER:
            try:
                florlp_session = create_florlp_session(form.data['florlp_name'], form.data['florlp_password'])
            except FLOrlpUnauthenticated:
                flash(_('Invalid florlp username/password'), 'error')
                return render_template("user/new.html", form=form)

        user = User(form.data['email'], form.data['password'])
        user.realname = form.data['realname']
        user.florlp_name = form.data['florlp_name']
        user.type = form.data.get('type')
        user.street = form.data['street']
        user.housenumber =  form.data['housenumber']
        user.zipcode = form.data['zipcode']
        user.city = form.data['city']
        user.active = user_type == User.Type.CUSTOMER
        verify = EmailVerification.verify(user)
        db.session.add(user)
        db.session.add(verify)
        db.session.commit()

        send_mail(
            _("Email verification mail subject"),
            render_template("user/verify_mail.txt", user=user, verify=verify, _external=True),
            [user.email]
        )

        couch_url = current_app.config.get('COUCH_DB_URL')
        if user.is_service_provider or user.is_customer:
            # create couch document and area boxes
            # and initialize security
            init_user_boxes(user, couch_url)

        if florlp_session:
            couch = CouchDBBox(couch_url, '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))
            try:
                schema, feature_collection = latest_flursteuck_features(florlp_session)
            finally:
                remove_florlp_session(florlp_session)
            feature_collection = transform_geojson(from_srs=current_app.config.get('FLORLP_SHP_SRS'), to_srs=3857, geojson=feature_collection)
            for layer, title in layers:
                couch.store_layer_schema(layer, schema, title=title)
                couch.store_features(layer, feature_collection['features'])

        if user.is_service_provider:
            couch = CouchDBBox(couch_url, '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))
            couch.store_layer_schema(current_app.config['USER_WORKON_LAYER'], florlp.base_schema(), title=current_app.config['USER_WORKON_LAYER_TITLE'])


        return redirect(url_for(".verify_wait", id=user.id))

    return render_template("user/new.html", form=form, customer_id=User.Type.CUSTOMER)
示例#4
0
def new():
    form = NewUserForm()

    form.federal_state.choices = []
    form.federal_state.choices.append(('', _('Please select')))
    for state in current_app.config['FEDERAL_STATES']:
        form.federal_state.choices.append(state)

    form.title.choices = current_app.config['SALUTATIONS']

    form.type.choices = []
    # add choice wich account types are possible
    if current_app.config['FEATURE_CUSTOMER_USERS']:
        form.type.choices.append((User.Type.CUSTOMER, _('customer')))
    if current_app.config['FEATURE_CONSULTANT_USERS']:
        form.type.choices.append((User.Type.CONSULTANT, _('consultant')))
    form.type.choices.append((User.Type.SERVICE_PROVIDER, _('service_provider')))

    if form.validate_on_submit():
        user = User(form.data['email'], form.data['password'])
        user.set_user_data(form.data)
        user.type = form.data.get('type')

        # no use type will be active automatically all must be activated by an admin
        user.active = False

        # send verifycation mail to check user email
        verify = EmailVerification.verify(user)
        db.session.add(user)
        db.session.add(verify)
        db.session.commit()

        send_mail(
            _("Email verification mail subject"),
            render_template(
                "user/verify_mail.txt",
                user=user,
                verify=verify,
                _external=True
            ),
            [user.email]
        )

        couch_url = current_app.config.get('COUCH_DB_URL')
        if user.is_service_provider or user.is_customer:
            # create couch document and area boxes
            # and initialize security
            init_user_boxes(user, couch_url)

        return redirect(url_for(".verify_wait", id=user.id))

    return render_template(
        "user/new.html",
        form=form,
        customer_id=User.Type.CUSTOMER,
        service_provider_id=User.Type.SERVICE_PROVIDER,
    )
示例#5
0
def new():
    form = NewUserForm()

    form.federal_state.choices = []
    form.federal_state.choices.append(('', _('Please select')))
    for state in current_app.config['FEDERAL_STATES']:
        form.federal_state.choices.append(state)

    form.title.choices = current_app.config['SALUTATIONS']

    form.type.choices = []
    # add choice wich account types are possible
    if current_app.config['FEATURE_CUSTOMER_USERS']:
        form.type.choices.append((User.Type.CUSTOMER, _('customer')))
    if current_app.config['FEATURE_CONSULTANT_USERS']:
        form.type.choices.append((User.Type.CONSULTANT, _('consultant')))
    form.type.choices.append(
        (User.Type.SERVICE_PROVIDER, _('service_provider')))

    if form.validate_on_submit():
        user = User(form.data['email'], form.data['password'])
        user.set_user_data(form.data)
        user.type = form.data.get('type')

        # no use type will be active automatically all must be activated by an admin
        user.active = False

        # send verifycation mail to check user email
        verify = EmailVerification.verify(user)
        db.session.add(user)
        db.session.add(verify)
        db.session.commit()

        send_mail(
            _("Email verification mail subject"),
            render_template("user/verify_mail.txt",
                            user=user,
                            verify=verify,
                            _external=True), [user.email])

        couch_url = current_app.config.get('COUCH_DB_URL')
        if user.is_service_provider or user.is_customer:
            # create couch document and area boxes
            # and initialize security
            init_user_boxes(user, couch_url)

        return redirect(url_for(".verify_wait", id=user.id))

    return render_template(
        "user/new.html",
        form=form,
        customer_id=User.Type.CUSTOMER,
        service_provider_id=User.Type.SERVICE_PROVIDER,
    )
示例#6
0
def create_user():
    form = CreateUserForm()
    form.type.choices = []
    form.federal_state.choices = current_app.config['FEDERAL_STATES']
    form.title.choices = current_app.config['SALUTATIONS']

    if current_app.config['FEATURE_CUSTOMER_USERS']:
        form.type.choices.append((User.Type.CUSTOMER, _('customer')))
    form.type.choices.append((User.Type.SERVICE_PROVIDER, _('service_provider')))
    if current_app.config['FEATURE_CONSULTANT_USERS']:
        form.type.choices.append((User.Type.CONSULTANT, _('consultant')))
    form.type.choices.append((User.Type.ADMIN, _('admin')))

    if form.validate_on_submit():
        user = User(form.data['email'], form.data['password'])
        user.set_user_data(form.data)
        user.type = form.data.get('type')

        if not form.data['verified']:
            verify = EmailVerification.verify(user)
            db.session.add(verify)
            send_mail(
                _("Email verification mail subject"),
                render_template(
                    "user/verify_mail.txt",
                    user=user,
                    verify=verify,
                    _external=True,
                ),
                [user.email]
            )
        else:
            user.verified = True
            if form.data['activate']:
                user.active = True
        db.session.add(user)
        db.session.commit()

        init_user_boxes(user, current_app.config.get('COUCH_DB_URL'))

        flash(_('User created', email=user.email), 'success')
        return redirect(url_for('admin.user_list'))
    return render_template('admin/create_user.html', form=form)
示例#7
0
def init_couchdb(config):
    user = model.User.by_email('*****@*****.**')
    init_user_boxes(user, config.get('COUCH_DB_URL'))
    couch = CouchDBBox(config.get('COUCH_DB_URL'), '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))
    layers = [(config.get('USER_READONLY_LAYER'), config.get('USER_READONLY_LAYER_TITLE')), (config.get('USER_WORKON_LAYER'), config.get('USER_WORKON_LAYER_TITLE'))]
    print layers
    florlp_session = create_florlp_session("demo", "demo")
    try:
        schema, feature_collection = latest_flursteuck_features(florlp_session)
    finally:
        remove_florlp_session(florlp_session)

    feature_collection = transform_geojson(from_srs=config.get('FLORLP_SHP_SRS'), to_srs=3857, geojson=feature_collection)
    for layer, title in layers:
        couch.clear_layer(layer)
        couch.store_layer_schema(layer, schema, title=title)
        couch.store_features(layer, feature_collection['features'])

    user = model.User.by_email('*****@*****.**')
    init_user_boxes(user, config.get('COUCH_DB_URL'))
示例#8
0
def init_couchdb(config):
    user = model.User.by_email('*****@*****.**')
    init_user_boxes(user, config.get('COUCH_DB_URL'))

    user = model.User.by_email('*****@*****.**')
    init_user_boxes(user, config.get('COUCH_DB_URL'))

    user = model.User.by_email('*****@*****.**')
    init_user_boxes(user, config.get('COUCH_DB_URL'))
示例#9
0
def get_context_document():
    init_user_boxes(g.user, current_app.config.get('COUCH_DB_URL'))

    wmts_sources = db.session.query(WMTS, ST_AsGeoJSON(ST_Transform(WMTS.view_coverage, 3857))).order_by(desc(WMTS.is_background_layer)).all()

    wms_sources = db.session.query(WMS, ST_AsGeoJSON(ST_Transform(WMS.view_coverage, 3857))).order_by(desc(WMS.is_background_layer)).all()
    wfs_sources = db.session.query(WFS).all()

    response = {
        "version": "0.2",
        "portal": {
            "prefix": current_app.config['PORTAL_PREFIX'],
            "title": current_app.config['PORTAL_TITLE'],
        },
        "wmts_sources": [],
        "wms_sources": [],
        "wfs_sources": [],
        "couchdb_sources": [],
    }

    couchdb = CouchDBBox(current_app.config['COUCH_DB_URL'], '%s_%s' % (SystemConfig.AREA_BOX_NAME, g.user.id))

    for source in wmts_sources:
        wmts, view_coverage = source
        geom = json.loads(view_coverage)
        response['wmts_sources'].append({
            "name": wmts.name,
            "title": wmts.title,
            "url": wmts.client_url(external=True),
            "format": wmts.format,
            "overlay": wmts.is_overlay,
            "username": wmts.username,
            "password": wmts.password,
            "is_public": wmts.is_public,
            "is_protected": wmts.is_protected,
            "is_background_layer": wmts.is_background_layer,
            "max_tiles": wmts.max_tiles,
            "view_restriction": {
                "zoom_level_start": wmts.view_level_start,
                "zoom_level_end": wmts.view_level_end,
                "geometry": geom
            },
            "download_restriction": {
                "zoom_level_start": wmts.view_level_start,
                "zoom_level_end": wmts.view_level_end,
            }
        })

    for source in wms_sources:
        wms, view_coverage = source
        geom = json.loads(view_coverage)
        response['wms_sources'].append({
            "name": wms.name,
            "title": wms.title,
            "url": wms.url,
            "layer": wms.layer,
            "format": wms.format,
            "overlay": wms.is_overlay,
            "username": wms.username,
            "password": wms.password,
            "is_public": wms.is_public,
            "is_protected": wms.is_protected,
            "srs": wms.srs,
            "wms_version": wms.version,
            "view_restriction": {
                "zoom_level_start": wms.view_level_start,
                "zoom_level_end": wms.view_level_end,
                "geometry": geom
            },
            "download_restriction": {
                "zoom_level_start": wms.view_level_start,
                "zoom_level_end": wms.view_level_end,
            }
        })

    for wfs in wfs_sources:
        response['wfs_sources'].append({
            'id': wfs.id,
            'name': wfs.name,
            'layer': wfs.layer,
            'host': wfs.host,
            'url': wfs.url,
            'srs': wfs.srs,
            'geometry_field': wfs.geometry,
            'feature_ns': wfs.ns_uri,
            'typename': wfs.ns_prefix,
            'search_property': wfs.search_property,
            'username': wfs.username,
            'password': wfs.password,
            'is_protected': wfs.is_protected,

        })

    if current_app.config['FEATURE_AREA_BOXES']:
        response['couchdb_sources'].append({
            "name": _('area box'),
            "url": current_app.config['COUCH_DB_URL'],
            "dbname": '%s_%s' % (SystemConfig.AREA_BOX_NAME, g.user.id),
            "username": '******' % g.user.id,
            "password": g.user.authproxy_token,
            "writable": True,
            "dbname_user":  SystemConfig.AREA_BOX_NAME_LOCAL,
        })

    if current_app.config['FEATURE_DOC_BOXES']:
        if g.user.is_consultant:
            response['couchdb_sources'].append({
                "name": _('file box'),
                "url": current_app.config['COUCH_DB_URL'],
                "dbname": '%s_%s' % (SystemConfig.FILE_BOX_NAME, g.user.id),
                "username": '******' % g.user.id,
                "password": g.user.authproxy_token,
                "writable": True,
                "dbname_user":  SystemConfig.FILE_BOX_NAME_LOCAL,
            })
        else:
            response['couchdb_sources'].append({
                "name": _('consultant box'),
                "url": current_app.config['COUCH_DB_URL'],
                "dbname": '%s_%s' % (SystemConfig.DOWNLOAD_BOX_NAME, g.user.id),
                "username": '******' % g.user.id,
                "password": g.user.authproxy_token,
                "writable": False,
                "dbname_user":  SystemConfig.DOWNLOAD_BOX_NAME_LOCAL,
            })
            response['couchdb_sources'].append({
                "name": _('uploadbox'),
                "url": current_app.config['COUCH_DB_URL'],
                "dbname": '%s_%s' % (SystemConfig.UPLOAD_BOX_NAME, g.user.id),
                "username": '******' % g.user.id,
                "password": g.user.authproxy_token,
                "writable": True,
                "dbname_user":  SystemConfig.UPLOAD_BOX_NAME_LOCAL,
            })

    if current_app.config['PARCEL_SEARCH_DATABASE_URI']:
        response['parcel_search_url'] = url_for('search.query', token=g.user.authproxy_token, _external=True)

    response['logging'] = {
        'url': url_for('logserv.log', user_token=g.user.authproxy_token, _external=True),
    }

    response['update_coverage'] = {
        'url': url_for('authproxy.update_download_coverage',
            user_token=g.user.authproxy_token,
            _external=True
        ),
    }

    response['user'] = {
        'email': g.user.email,
        'type': g.user.type,
        'type_name': g.user.type_name,
    }

    return json.dumps(response)
示例#10
0
def get_context_document():
    init_user_boxes(g.user, current_app.config.get('COUCH_DB_URL'))

    wmts_sources = db.session.query(
        WMTS, ST_AsGeoJSON(ST_Transform(WMTS.view_coverage, 3857))).order_by(
            desc(WMTS.is_background_layer)).all()

    wms_sources = db.session.query(
        WMS, ST_AsGeoJSON(ST_Transform(WMS.view_coverage, 3857))).order_by(
            desc(WMS.is_background_layer)).all()
    wfs_sources = db.session.query(WFS).all()

    response = {
        "version": "0.2",
        "portal": {
            "prefix": current_app.config['PORTAL_PREFIX'],
            "title": current_app.config['PORTAL_TITLE'],
        },
        "wmts_sources": [],
        "wms_sources": [],
        "wfs_sources": [],
        "couchdb_sources": [],
    }

    couchdb = CouchDBBox(current_app.config['COUCH_DB_URL'],
                         '%s_%s' % (SystemConfig.AREA_BOX_NAME, g.user.id))

    for source in wmts_sources:
        wmts, view_coverage = source
        geom = json.loads(view_coverage)
        response['wmts_sources'].append({
            "name": wmts.name,
            "title": wmts.title,
            "url": wmts.client_url(external=True),
            "format": wmts.format,
            "overlay": wmts.is_overlay,
            "username": wmts.username,
            "password": wmts.password,
            "is_public": wmts.is_public,
            "is_protected": wmts.is_protected,
            "is_background_layer": wmts.is_background_layer,
            "max_tiles": wmts.max_tiles,
            "view_restriction": {
                "zoom_level_start": wmts.view_level_start,
                "zoom_level_end": wmts.view_level_end,
                "geometry": geom
            },
            "download_restriction": {
                "zoom_level_start": wmts.view_level_start,
                "zoom_level_end": wmts.view_level_end,
            }
        })

    for source in wms_sources:
        wms, view_coverage = source
        geom = json.loads(view_coverage)
        response['wms_sources'].append({
            "name": wms.name,
            "title": wms.title,
            "url": wms.url,
            "layer": wms.layer,
            "format": wms.format,
            "overlay": wms.is_overlay,
            "username": wms.username,
            "password": wms.password,
            "is_public": wms.is_public,
            "is_protected": wms.is_protected,
            "srs": wms.srs,
            "wms_version": wms.version,
            "view_restriction": {
                "zoom_level_start": wms.view_level_start,
                "zoom_level_end": wms.view_level_end,
                "geometry": geom
            },
            "download_restriction": {
                "zoom_level_start": wms.view_level_start,
                "zoom_level_end": wms.view_level_end,
            }
        })

    for wfs in wfs_sources:
        response['wfs_sources'].append({
            'id': wfs.id,
            'name': wfs.name,
            'layer': wfs.layer,
            'host': wfs.host,
            'url': wfs.url,
            'srs': wfs.srs,
            'geometry_field': wfs.geometry,
            'feature_ns': wfs.ns_uri,
            'typename': wfs.ns_prefix,
            'search_property': wfs.search_property,
            'username': wfs.username,
            'password': wfs.password,
            'is_protected': wfs.is_protected,
        })

    if current_app.config['FEATURE_AREA_BOXES']:
        response['couchdb_sources'].append({
            "name":
            _('area box'),
            "url":
            current_app.config['COUCH_DB_URL'],
            "dbname":
            '%s_%s' % (SystemConfig.AREA_BOX_NAME, g.user.id),
            "username":
            '******' % g.user.id,
            "password":
            g.user.authproxy_token,
            "writable":
            True,
            "dbname_user":
            SystemConfig.AREA_BOX_NAME_LOCAL,
        })

    if current_app.config['FEATURE_DOC_BOXES']:
        if g.user.is_consultant:
            response['couchdb_sources'].append({
                "name":
                _('file box'),
                "url":
                current_app.config['COUCH_DB_URL'],
                "dbname":
                '%s_%s' % (SystemConfig.FILE_BOX_NAME, g.user.id),
                "username":
                '******' % g.user.id,
                "password":
                g.user.authproxy_token,
                "writable":
                True,
                "dbname_user":
                SystemConfig.FILE_BOX_NAME_LOCAL,
            })
        else:
            response['couchdb_sources'].append({
                "name":
                _('consultant box'),
                "url":
                current_app.config['COUCH_DB_URL'],
                "dbname":
                '%s_%s' % (SystemConfig.DOWNLOAD_BOX_NAME, g.user.id),
                "username":
                '******' % g.user.id,
                "password":
                g.user.authproxy_token,
                "writable":
                False,
                "dbname_user":
                SystemConfig.DOWNLOAD_BOX_NAME_LOCAL,
            })
            response['couchdb_sources'].append({
                "name":
                _('uploadbox'),
                "url":
                current_app.config['COUCH_DB_URL'],
                "dbname":
                '%s_%s' % (SystemConfig.UPLOAD_BOX_NAME, g.user.id),
                "username":
                '******' % g.user.id,
                "password":
                g.user.authproxy_token,
                "writable":
                True,
                "dbname_user":
                SystemConfig.UPLOAD_BOX_NAME_LOCAL,
            })

    if current_app.config['PARCEL_SEARCH_DATABASE_URI']:
        response['parcel_search_url'] = url_for('search.query',
                                                token=g.user.authproxy_token,
                                                _external=True)

    response['logging'] = {
        'url':
        url_for('logserv.log',
                user_token=g.user.authproxy_token,
                _external=True),
    }

    response['update_coverage'] = {
        'url':
        url_for('authproxy.update_download_coverage',
                user_token=g.user.authproxy_token,
                _external=True),
    }

    response['user'] = {
        'email': g.user.email,
        'type': g.user.type,
        'type_name': g.user.type_name,
    }

    return json.dumps(response)