Beispiel #1
0
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)
Beispiel #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)
Beispiel #3
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,
    )
Beispiel #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,
    )
Beispiel #5
0
def activate_user(id):
    user = User.by_id(id)
    user.active = True
    db.session.commit()

    send_mail(
        _("Account activated mail subject"),
        render_template("user/activated_mail.txt", user=user, _external=True),
        [user.email]
    )

    flash(_('User activated', email=user.email), 'success')
    return redirect(url_for("admin.user_detail", id=id))
Beispiel #6
0
def activate_user(user_id):
    user = User.by_id(user_id)
    user.verified = True
    user.active = True
    db.session.commit()

    send_mail(
        _("Account activated mail subject"),
        render_template("user/activated_mail.txt", user=user, _external=True),
        [user.email]
    )

    flash(_('User activated %(email)s', email=user.email), 'success')
    return redirect(request.args.get("next") or url_for("admin.inactive_users_list"))
Beispiel #7
0
def recover():
    form = RecoverRequestForm()
    if form.validate_on_submit():
        user = User.by_email(form.data['email'])
        recover = EmailVerification.recover(user)
        db.session.add(recover)
        db.session.commit()

        send_mail(
            _("Password recover mail subject"),
            render_template("user/recover_mail.txt",
                            user=user,
                            recover=recover), [user.email])

        return redirect(url_for(".recover_sent"))
    return render_template("user/recover.html", form=form)
Beispiel #8
0
def recover():
    form = RecoverRequestForm()
    if form.validate_on_submit():
        user = User.by_email(form.data['email'])
        recover = EmailVerification.recover(user)
        db.session.add(recover)
        db.session.commit()

        send_mail(
            _("Password recover mail subject"),
            render_template("user/recover_mail.txt", user=user, recover=recover),
            [user.email]
        )

        return redirect(url_for(".recover_sent"))
    return render_template("user/recover.html", form=form)
Beispiel #9
0
def send_verifymail(id):
    user = User.by_id(id)
    if not user or user.verified:
        raise NotFound()

    verify = EmailVerification.verify(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]
    )

    flash(_('email verification was sent successfully'), 'success')
    return redirect(url_for(".login"))
Beispiel #10
0
def send_verifymail(id):
    user = User.by_id(id)
    if not user or user.verified:
        raise NotFound()

    verify = EmailVerification.verify(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])

    flash(_('email verification was sent successfully'), 'success')
    return redirect(url_for(".login"))
Beispiel #11
0
def verify(uuid):
    verify = EmailVerification.by_hash(uuid)
    if not verify or not verify.is_verify:
        raise NotFound()

    user = verify.user
    user.verified = True
    db.session.delete(verify)
    db.session.commit()
    if not user.is_customer:
        send_mail(
            _("Activate user subject"),
            render_template("admin/user_activate_mail.txt", user=user, _external=True),
            [member.email for member in User.all_admins()]
        )

    flash(_("Email verified"), 'success')
    return redirect(url_for(".login"))
Beispiel #12
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)
Beispiel #13
0
def verify(uuid):
    verify = EmailVerification.by_hash(uuid)
    if not verify or not verify.is_verify:
        return render_template("errors/404.html",
                               error_msg=_('infotext verify not possible'))

    user = verify.user
    user.verified = True
    db.session.delete(verify)
    db.session.commit()

    send_mail(
        _("Activate user subject"),
        render_template("admin/user_activate_mail.txt",
                        user=user,
                        _external=True),
        [member.email for member in User.all_admins()])

    flash(_("Email verified"), 'success')
    return redirect(url_for(".login"))
Beispiel #14
0
def verify(uuid):
    verify = EmailVerification.by_hash(uuid)
    if not verify or not verify.is_verify:
        return render_template(
            "errors/404.html",
            error_msg=_('infotext verify not possible')
        )

    user = verify.user
    user.verified = True
    db.session.delete(verify)
    db.session.commit()

    send_mail(
        _("Activate user subject"),
        render_template("admin/user_activate_mail.txt", user=user, _external=True),
        [member.email for member in User.all_admins()]
    )

    flash(_("Email verified"), 'success')
    return redirect(url_for(".login"))