示例#1
0
def create(data):
    if data.get('name') is not None and data.get(
            'description') is not None and data.get(
                'release_date') is not None and data.get('rating') is not None:
        if data.get('poster_url') is None:
            data['poster_url'] = ''
        return model.create(data)
    else:
        raise InvalidUsage('POST movie is missing data')
示例#2
0
def addActorToMovie(movieId, actorId, role):
    try:
        role = MovAct(movieId, actorId, role)
        db.session.add(role)
        db.session.commit()
        db.session.refresh(role)
        return role.role
    except:
        raise InvalidUsage('Error, PATCH failed', status_code=400)
示例#3
0
def user_services():
    try:
        if current_user.is_authenticated:
            return render_template('user/services.html',
                                   key=current_user.api_key,
                                   access=current_user.access)
        else:
            return redirect("{}login".format(Config.URL_ENDPOINT))
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#4
0
def getActors(movieId):
    sql = ('select actors.*, movies_actors.role from movies\
     inner join movies_actors on movies.id = movies_actors.movies_id\
     inner join actors on actors.id = movies_actors.actors_id\
     where movies.id = %s' % movieId)
    result = db.engine.execute(sql)
    if result is not None:
        return json.dumps([dict(r) for r in result], default=str)
    else:
        raise InvalidUsage('Error Occured', status_code=404)
示例#5
0
def check_key():
    try:
        key = request.args.get('key')
        cur_key = db.engine.execute(
            "SELECT api_key FROM users WHERE api_key='{}'".format(key))
        if cur_key.rowcount > 0:
            return jsonify(True)
        else:
            return jsonify(False)
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#6
0
def insert_key():
    key = request.args.get('key')
    name = request.args.get('name')
    id = request.args.get('id')
    try:
        db.engine.execute(
            "UPDATE users set api_key='{}' where username='******' and id={}".
            format(key, name, id))
        return jsonify(True)
    except:
        return InvalidUsage(e, status_code=410)
示例#7
0
def update(actorId, data):
    try:
        db.session.query(Actors).\
        filter(Actors.id == actorId).\
        update({'name': data['name'], 'biography': data['biography'],
        'profile_url': data['profile_url'],'birth_date': data['birth_date']})

        db.session.commit()
        db.session.flush()
        return 'Actor Has Been Updated!'
    except:
        raise InvalidUsage('Error, update failed', status_code=400)
示例#8
0
def update(movieId, data):
    try:
        db.session.query(Movies).\
        filter(Movies.id == movieId).\
        update({'name': data['name'], 'description': data['description'],
                  'release_date': data['release_date'], 'rating': data['rating'],'poster_url': data['poster_url']})

        db.session.commit()
        db.session.flush()
        return 'Movie has been updated!'
    except:
        raise InvalidUsage('Error, update failed', status_code=400)
示例#9
0
def get(obj_id):
    """
    retrieves interviewer record matching obj_id
    :param obj_id:
    :return:
    """
    interviewer = models.Interviewer.query.get(obj_id)

    if not interviewer:
        raise InvalidUsage("Interviewer not found matching id - %s" % obj_id,
                           status_code=404)

    return jsonify({"data": interviewer.serialize()})
示例#10
0
def get(obj_id):
    """
    retrieves candidate record matching obj_id
    :param obj_id:
    :return:
    """
    candidate = models.Candidate.query.get(obj_id)

    if not candidate:
        raise InvalidUsage("Candidate not found matching id - %s" % obj_id,
                           status_code=404)

    return jsonify(candidate.serialize())
示例#11
0
def api_key():
    try:
        if current_user.is_authenticated:
            key = current_user.api_key
            return render_template('user/api_key.html',
                                   key=key,
                                   username=current_user.username,
                                   user_id=current_user.id,
                                   access=current_user.access,
                                   host=Config.URL_ENDPOINT)
        else:
            return url_for('user.login')
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#12
0
        def decorated_function(*args, **kwargs):
            if request.method == "GET":
                request_args = request.args.to_dict()
            else:
                request_args = request.get_json(silent=True) or {}

            try:
                parsed_args = schema.load(request_args)
                kwargs["args"] = parsed_args
            except ValidationError as error:
                raise InvalidUsage(
                    ErrorMessage.INVALID_POST_DATA, error_data=error.messages
                )
            return f(*args, **kwargs)
示例#13
0
def delete(obj_id):
    """
    deletes candidate record matching obj_id
    :param obj_id:
    :return:
    """
    candidate = models.Candidate.query.get(obj_id)

    if not candidate:
        raise InvalidUsage("Candidate not found matching id - %s" % obj_id,
                           status_code=404)

    models.db.session.delete(candidate)
    models.db.session.commit()

    return common.success_response("Candidate successfully deleted", 204)
示例#14
0
def confirm_email(token_pass):
    try:
        username = token.confirm_token(token_pass)
        user = User.query.filter_by(username=username).first_or_404()
        app.logger.debug("State User{0}".format(user.confirmed))
        if user.confirmed is False:
            user.confirmed = True
            user.confirmed_on = datetime.datetime.now()
            db.session.add(user)
            db.session.commit()
            logout_user()
            return render_template('user/confirmed_mail.html', confimed=True)
        else:
            return render_template('user/confirmed_mail.html', confimed=False)
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#15
0
def delete(obj_id):
    """
    deletes interviewer record matching obj_id
    :param obj_id:
    :return:
    """
    interviewer = models.Interviewer.query.get(obj_id)

    if not interviewer:
        raise InvalidUsage("Interviewer not found matching id - %s" % obj_id,
                           status_code=404)

    models.db.session.delete(interviewer)
    models.db.session.commit()

    return common.success_response("Interviewer successfully deleted", 204)
示例#16
0
def send_error():
    try:
        message = request.args.get('message')
        name = request.args.get('name')

        mail = Mail(app)
        msg = Message(body=message,
                      subject='ERROR im Monitor bei: {}'.format(name),
                      sender="ERROR Monitor",
                      recipients=["*****@*****.**"])
        app.logger.debug(
            "send Mail for Error: \n message:{} \n sendto:{}".format(
                message, "*****@*****.**"))
        mail.send(msg)
        return jsonify("send")
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#17
0
def signup():
    try:
        form = RegisterForm(form_type="inline")
        if form.validate_on_submit():
            #Form Values
            hashed_password = generate_password_hash(form.password.data,
                                                     method='sha256')
            username = form.username.data
            email = form.email.data
            cur_check = db.engine.execute(
                "SELECT email, username FROM users WHERE username='******' or email='{}'"
                .format(username, email)).first()
            if cur_check is not None:
                error = Markup(
                    '<div class="alert alert-danger w-100" role="alert">Der <b>Nutzername</b> oder die <b>Mailadresse</b> ist schon registriert</div>'
                )
                return render_template('user/signup.html',
                                       form=form,
                                       error=error)
            else:
                new_user = User(username=username,
                                email=email,
                                password=hashed_password,
                                lastname=form.lastname.data,
                                firstname=form.firstname.data,
                                facility=form.facility.data,
                                access=1,
                                business=form.business.data,
                                confirmed=False)
                db.session.add(new_user)
                db.session.commit()

                token_user = token.generate_confirmation_token(username)
                confirm_url = "{}confirm/{}".format(Config.URL_ENDPOINT,
                                                    token_user)
                html = render_template('user/activate_mail.html',
                                       confirm_url=confirm_url)
                subject = "Bitte bestätigen Sie ihre Email"
                mail = Mailer(email, subject, html)
                mail.send_email()
                login_user(User.query.filter_by(username=username).first())
                return render_template('user/signup.html')
        return render_template('user/signup.html', form=form)
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#18
0
def send():
    try:
        sender = request.args.get('sender')
        message = request.args.get('message')
        name = request.args.get('name')

        mail = Mail(app)

        msg = Message(body=message,
                      sender=sender,
                      subject='IÖR-Feedback from: {}'.format(name),
                      recipients=["*****@*****.**"])
        app.logger.debug("send Mail from:{} \n message:{} \n sendto:{}".format(
            sender, message, "*****@*****.**"))
        mail.send(msg)
        return jsonify("send")
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#19
0
def get():
    job = request.args.get('job') or None
    values = request.get_data() or None
    job_id = request.args.get('job_id') or None
    # test if JSON is valid
    try:
        # validate json
        # set request and get response from esri server
        request_handler = ESRIServerManager(job, values=values, job_id=job_id)
        app.logger.debug("result: \n%s", str(request_handler.get_request()))
        return request_handler.get_request()
    except Exception as e:
        if job == None:
            return jsonify(
                error=
                'no job query, API-Doku: https://ioer-dresden.github.io/monitor-api-doku/docs/sora'
            )
        else:
            return InvalidUsage(e, status_code=410)
示例#20
0
def get_service():
    try:
        #get all url parameter
        url = request.url.split("?")
        parameters = url[1].split("&")
        service = ''
        id = ''
        key = ''
        paramater_ogc = ''

        for x in parameters:
            x_str = x.lower()
            if 'key' in x:
                key = x.replace('key=', '')
            elif 'service' in x_str:
                service = x_str.replace('service=', '')
            elif 'id' in x_str:
                id = x_str.replace('id=', '')
            else:
                paramater_ogc += '&' + x_str

        url_ogc = "https://monitor.ioer.de/cgi-bin/mapserv?map=/mapsrv_daten/detailviewer/{}_mapfiles/{}_{}.map&SERVICE={}{}".format(
            service.lower(), service.lower(), id.upper(), service.upper(),
            paramater_ogc)
        app.logger.info("Mapserver request: %s", url_ogc)
        req = requests.get(url_ogc, stream=True)
        response = Response(req.text,
                            status=req.status_code,
                            content_type=req.headers['content-type'])
        if session.get('key') is not None:
            return response
        else:
            cur_key = db.engine.execute(
                "SELECT * FROM users WHERE api_key='{}'".format(key))
            if cur_key.rowcount == 0:
                return jsonify({"error": "Wrong API Key"})
            else:
                session['key'] = True
                return response
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#21
0
def login():
    try:
        logout_user()
        if current_user.is_authenticated:
            if current_user.access == 2:
                return redirect("{}admin/".format(Config.URL_ENDPOINT))
            else:
                return render_template('user/api_key.html',
                                       key=current_user.api_key,
                                       btn_text='Kopieren',
                                       username=current_user.username,
                                       user_id=current_user.id,
                                       host=Config.URL_ENDPOINT)
        form = LoginForm()
        if form.validate_on_submit():
            user = User.query.filter_by(username=form.username.data).first()
            if user and check_password_hash(user.password, form.password.data):
                login_user(user, remember=form.remember_me.data)
                if current_user.access == 2:
                    return redirect("{}admin/".format(Config.URL_ENDPOINT))
                else:
                    app.logger.info("%s is logged in as user",
                                    current_user.username)
                    return render_template('user/api_key.html',
                                           key=current_user.api_key,
                                           btn_text='Kopieren',
                                           username=current_user.username,
                                           user_id=current_user.id,
                                           host=Config.URL_ENDPOINT)
            else:
                error = Markup(
                    '<div class="alert alert-danger w-100" role="alert">Der <b>Nutzername</b> oder das <b>Passwort</b> ist falsch</div>'
                )
                return render_template('user/login.html',
                                       form=form,
                                       error=error)

        return render_template('user/login.html', form=form)
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#22
0
def reset_password(token_pass):
    try:
        form = ResetPasswordForm(form_type="inline")
        if token.confirm_token(token_pass):
            if form.validate_on_submit():
                email = token.confirm_token(token_pass)
                user = User.query.filter_by(email=email).first_or_404()
                new_pw = generate_password_hash(form.password.data,
                                                method='sha256')
                user.password = new_pw
                db.session.add(user)
                db.session.commit()
                logout_user()
                return render_template('user/reset_password.html',
                                       reseted=True)
            return render_template('user/reset_password.html', reset_form=form)
        else:
            error = Markup(
                '<div class="alert alert-danger w-100" role="alert">Der Token für die Zurücksetzung ist abgelaufen</div>'
            )
            return render_template('user/reset_password.html', error=error)
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#23
0
def logout():
    try:
        logout_user()
        return redirect(Config.URL_ENDPOINT)
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#24
0
def getAll():
    result = Movies.query.all()
    if result is not None:
        return Movies.serialize_list(result)
    else:
        raise InvalidUsage('Error, No Movies', status_code=404)
示例#25
0
def getOne(movieId):
    result = Movies.query.get(movieId)
    if result is not None:
        return Movies.toDict(result)
    else:
        raise InvalidUsage('Error, Movie Not Found', status_code=404)
示例#26
0
def getOne(actorId):
    if actorId is not None:
        return model.getOne(actorId)
    else:
        raise InvalidUsage('GetOne requires Actor Id')
示例#27
0
def getOne(movieId):
    if movieId is not None:
        return model.getOne(movieId)
    else:
        raise InvalidUsage('GetOne requires Movie Id')
示例#28
0
def geosn_service():
    try:
        geosn = GeoSN('/srv/www/htdocs/monitor_ogc_xml/')
        return jsonify(geosn.update())
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#29
0
def wms_service():
    try:
        wms = OgcFactory("wms")
        return jsonify(wms.create_service().createAllServices())
    except Exception as e:
        return InvalidUsage(e, status_code=410)
示例#30
0
def getOne(actorId):
    result = Actors.query.get(actorId)
    if result is not None:
        return Actors.toDict(result)
    else:
        raise InvalidUsage('Error, Actor Not Found', status_code=404)