Exemplo n.º 1
0
    def decorated(*args, **kwargs):
        token = None

        if 'x-access-token' in request.headers:
            token = request.headers['x-access-token']

        if not token:
            return create_error_exception(message="Token is missing",
                                          response_code=401,
                                          value="Token is missing")

        try:
            data = jwt.decode(token, app.config['SECRET_KEY'])
            db = DatabaseHelper()
            result = db.get_user(data['staff_id'])

            if not result['response']:
                return create_error_exception(message="User not found",
                                              response_code=401,
                                              value="User not found")

            current_user = result['value']

        except Exception as e:
            print("Error %d: %s" % (e.args[0], e.args[1]))
            return create_error_exception(message="Token is missing",
                                          response_code=401,
                                          value="Token is missing")

        return f(current_user, *args, **kwargs)
Exemplo n.º 2
0
def add_student_data(current_user):
    try:
        file = request.files['upload']
        if file and Constant.allowed_file(file.filename):
            destination = upload_helper.upload_file(
                store_folder=Constant.STUDENT_FOLDER, file=file)
        else:
            return api_helper.create_error_exception(
                "Type of file is not match", "file not match", 418)
    except Exception as e:
        print(e)
        return api_helper.create_error_exception(
            str(e), "Can not find a file with " + str(e.args[0]), 400)

    if destination['response']:
        data_helper = DataHelper()
        insert_value = data_helper.read_new_student_file(destination['value'])
        if insert_value['response']:
            db = DatabaseHelper()
            insert = db.insert_new_student_data(insert_value['value'])
        else:
            return api_helper.return_response(insert_value)
    else:
        return api_helper.return_response(destination)
    return api_helper.return_response(insert)
Exemplo n.º 3
0
def sign_in():
    auth_data = request.get_json()
    if not auth_data or not auth_data['username'] or not auth_data['password']:
        return api_helper.create_error_exception(message="Credentials data not found.", response_code=401,
                                                 value="Credentials data not found.")

    connect = DatabaseHelper()
    result = connect.get_user_for_auth(auth_data['username'])

    if not result['response']:
        return api_helper.create_error_exception(message="Cloud not verify.", response_code=401,
                                                 value="Cloud not verify.")

    user = result['value']
    user = list(user[0])
    user_type = "user" if user[1] == -1 else "admin"

    userData = {
        'name': user[2],
        'type': user_type
    }
    if check_password_hash(user[4], auth_data['password']):
        token = jwt.encode({'staff_id': user[0], 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=60)},
                           app.config['SECRET_KEY'])
        return api_helper.create_response(message="Signin successful",
                                          data={'token': token.decode('UTF-8'), 'userData': userData},
                                          response_code=200, response=True)

    return api_helper.create_error_exception(message="Cloud not verify.", response_code=401, value="Cloud not verify.")
Exemplo n.º 4
0
def insert_academic_record(current_user):
    # this api need education year (2561, 2562) and semester (1,2 or S)
    year = request.form.get('year')
    semester = request.form.get('semester')

    if year is None or semester is None:
        value = {'year': year, 'semester': semester}
        return api_helper.create_response(message="One of these is Null",
                                          response=False,
                                          data=[value],
                                          response_code=418)

    try:
        file = request.files['upload']
        if file and Constant.allowed_file(file.filename):
            destination = upload_helper.upload_file(
                store_folder=Constant.ACADEMIC_FOLDER, file=file, year=year)
        else:
            return api_helper.create_error_exception(
                "Type of file is not match", "file not match", 418)
    except Exception as e:
        print(e)
        return api_helper.create_error_exception(
            str(e), "Can not find a file with " + str(e.args[0]), 400)

    if destination['response']:
        data_helper = DataHelper()
        insert_value = data_helper.read_academic_file(destination['value'],
                                                      year, semester)
        if insert_value['response']:
            data = insert_value['value']
            db = DatabaseHelper()
            academic_record = db.insert_academic_record(
                data['academic_record'], data['gpa_record'],
                data['gpax_record'], data['status_record'])
            if not academic_record['response']:
                return api_helper.create_response(
                    message=academic_record['message'],
                    response=False,
                    response_code=500,
                    data=academic_record['value'])

    return api_helper.create_response(message="Developing",
                                      response=True,
                                      response_code=200,
                                      data="Developing")
Exemplo n.º 5
0
def insert_activity_participant(current_user):
    form = request.form
    activity_id = form.get('activity_id')
    project_id = form.get('project_id')
    project_type = form.get('project_type')
    year = form.get('year')

    data = [activity_id, project_id, year, project_type]

    if None in data:
        return api_helper.create_error_exception(
            message="Can not found some value.",
            response_code=400,
            value="Can not found some value.")
    try:
        file = request.files['upload']
        if file and Constant.allowed_file(file.filename):
            destination = upload_helper.upload_file(
                Constant.ACTIVITY_FOLDER + "/{}".format(project_id), file,
                year)
        else:
            return api_helper.create_error_exception(
                "Type of file is not match", "file not match", 418)
    except Exception as e:
        print(e)
        return api_helper.create_error_exception(
            str(e), "Can not find a file with " + str(e.args[0]), 400)

    if destination['response']:
        data_helper = DataHelper()
        insert_value = data_helper.read_activity_participant(
            destination['value'], activity_id)
        if insert_value['response']:
            db = DatabaseHelper()
            result = db.insert_activity_participant(insert_value['value'],
                                                    project_type)
        else:
            return api_helper.return_response(insert_value)
    else:
        return api_helper.return_response(destination)

    return api_helper.return_response(result)
Exemplo n.º 6
0
def delete_activity(current_user):
    act_id = request.args.get('act_id')
    project_type = request.args.get('project_type')

    if act_id is None or act_id == "null" or act_id == "undefined":
        return api_helper.create_error_exception(message="Can not get value.",
                                                 response_code=400,
                                                 value="Can not get value.")

    db = DatabaseHelper()
    result = db.delete_activity(act_id)

    return api_helper.return_response(result)
Exemplo n.º 7
0
def insert_admission(current_user):
    # This api need "Year" as year , "Admission type" as admission_type
    # and "Admission channel" as channel to be a parameter

    year = request.form.get('year')
    channel = request.form.get('channel')

    if year is None or channel is None:
        value = {"year": year, "channel": channel}
        return api_helper.create_response(message="One of these is Null",
                                          response=False,
                                          data=[value],
                                          response_code=418)

    try:
        file = request.files['upload']
        if file and Constant.allowed_file(file.filename):
            destination = upload_helper.upload_file(Constant.ADMISSION_FOLDER,
                                                    file, year)
        else:
            return api_helper.create_error_exception(
                "Type of file is not match", "file not match", 418)
    except Exception as e:
        print(e)
        return api_helper.create_error_exception(
            str(e), "Can not find a file with " + str(e.args[0]), 400)

    if destination['response']:
        data_helper = DataHelper()
        insert_value = data_helper.read_admission(channel, year,
                                                  destination['value'])
        if insert_value['response']:
            db = DatabaseHelper()
            insert = db.insert_admission(insert_value['value'])
        else:
            return api_helper.return_response(insert_value)
    else:
        return api_helper.return_response(destination)
    return api_helper.return_response(insert)
Exemplo n.º 8
0
def add_activity_project(current_user):
    data = request.get_json()

    if data is None:
        return api_helper.create_error_exception(message="Can not get value.",
                                                 response_code=400,
                                                 value="Can not get value.")

    if len(data) != 3:
        return api_helper.create_error_exception(
            message="Can not found some value.",
            response_code=400,
            value="Can not found some value.")

    project_id = data['project_id']
    project_name = data['project_name']
    project_type = data['project_type']

    data = [project_id, project_type, project_name]

    db = DatabaseHelper()
    result = db.create_project(data)

    return api_helper.return_response(result)
Exemplo n.º 9
0
def delete_admission_list():
    year = request.args.get('year')
    round_id = request.args.get('round_id')
    channel_id = request.args.get('channel_id')

    if year == 'null' or round_id == 'null' or channel_id == 'null':
        return api_helper.create_error_exception("Some data null",
                                                 "Some data null", 400)

    data = {
        'year': int(year),
        'round_id': int(round_id),
        'channel_id': int(channel_id)
    }

    db = DatabaseHelper()
    result = db.delete_admission_data(data)
    return api_helper.return_response(result)
Exemplo n.º 10
0
def add_new_activity(current_user):
    form = request.form
    activity_id = form.get('activity_id')
    project_id = form.get('project_id')
    activity_name = form.get('activity_name')
    activity_budget = form.get('budget')
    year = form.get('year')

    data = [activity_id, project_id, activity_name, activity_budget, year]

    if None in data:
        return api_helper.create_error_exception(
            message="Can not found some value.",
            response_code=400,
            value="Can not found some value.")

    db = DatabaseHelper()
    result = db.create_activity(data)

    return api_helper.return_response(result)