Example #1
0
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)
Example #2
0
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)
Example #3
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'))