Ejemplo n.º 1
0
def competition_delete_confirm(comp_record_hash):
    form = CompetitionDeleteForm()
    # Get competition info
    comp_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
               '/api/competition/competition-record-hash/' + str(comp_record_hash)
    result = requests.get(comp_url)
    # Functional Part
    if form.validate_on_submit():
        if result.status_code == 200:
            # ToDo: Auth recognization
            user_id = get_api_info(result)[0]['contributor_id']
            delete_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                         '/api/competition/competition-record-hash/' + str(comp_record_hash)
            requests.delete(delete_url)
            return redirect(
                url_for('competition-operator.competition_list_view',
                        user_id=user_id))
    # View Part
    else:
        if result.status_code == 200:
            # ToDo: Auth recognization
            competition = get_api_info(result)[0]
            return render_template('competition/compDelete.html',
                                   form=form,
                                   competition=competition)
Ejemplo n.º 2
0
def login_verify():
    # check whether user has already login
    if current_user.is_authenticated:
        return redirect(url_for('auth.home_view', account_id=current_user.account_id))

    # main function process below
    form = LoginForm()
    if form.validate_on_submit():
        # POST method
        if form.validate_on_submit():
            # captcha validate ( get from session )
            if str(form.captcha.data).upper() != session.get('captcha_code'):
                flash('CAPTCHA is not Correct!', 'warning')
                return redirect(url_for('auth.login_view'))
        account_email = form.email.data
        password = form.password.data
        dest_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/validate-password'
        result = requests.post(dest_url, data={'account_email': account_email, 'password': password})
        if result.status_code == 200 and len(get_api_info(result)) > 0:
            account = get_api_info(result)[0]
            if account['account_id'] != -1:
                # add auth
                verified_user = User(account_id=account['account_id'])
                login_user(verified_user)
                return redirect(url_for('auth.home_view', account_id=account['account_id']))
            else:
                flash('Email unknown or Password is not correct.', 'danger')
                return redirect(url_for('auth.login_view'))
Ejemplo n.º 3
0
def register_view():
    # auth process
    if current_user.is_authenticated is True:
        account = get_account_info_by_account_id(current_user.account_id)
    else:
        return redirect(url_for('auth.login_view'))
    if account['account_status'] != 'admin':
        return redirect(url_for('auth.home_view'))
    # process end

    # main function process below
    form = RegisterForm()
    captcha = dict()
    captcha_url = 'http://' + Config.CAPTCHA_SERVICE_URL + '/api/hash-match/captcha'
    result = requests.get(captcha_url)
    if result.status_code == 200:
        captcha['captcha_code'] = get_api_info(result)[0]['CAPTCHA']
        captcha['hash_code'] = get_api_info(result)[0]['Hash-Code']
        # store the captcha code into session
        session['captcha_code'] = captcha['captcha_code']
        captcha['captcha_url'] = 'http://' + Config.CAPTCHA_SERVICE_URL +\
                                 '/api/hash-match/captcha/' + captcha['hash_code']
    else:
        captcha['captcha_code'] = '0000'
        captcha['captcha_url'] = 'error'
    return render_template('auth/register/register.html', form=form, captcha=captcha, account=account)
Ejemplo n.º 4
0
def competition_updating_view(comp_record_hash):
    comp_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
               '/api/competition/competition-record-hash/' + str(comp_record_hash)
    result = requests.get(comp_url)
    if result.status_code == 200 and len(get_api_info(result)) >= 1:
        competition = get_api_info(result)[0]
        # check user's authentication by account_id in url whether match current_user.account_id
        # Mention!! Type of current_user.account_id is not string!
        if str(current_user.account_id) != str(competition['contributor_id']):
            # back to detail viewing page
            return redirect(url_for('competition-operator.competition_detail_view', comp_record_hash=comp_record_hash))

        # main function process below
        form = CompetitionUpdateForm()
        form.comp_title.data = competition['comp_title']
        form.comp_subtitle.data = competition['comp_subtitle']
        form.comp_range.data = competition['comp_range']
        form.comp_url.data = competition['comp_url']
        form.comp_description.data = competition['comp_description']
        form.comp_host_name.data = competition['comp_host'][0]['comp_host_name']
        form.comp_host_url.data = competition['comp_host'][0]['comp_host_url']
        form.prize_currency.data = competition['prize_currency']
        form.prize_amount.data = competition['prize_amount']
        form.deadline.data = datetime.datetime.strptime(competition['deadline'], '%Y-%m-%d %H:%M:%S')
        form.timezone.data = competition['timezone']
        comp_scenario = list()
        for scenario in competition['comp_scenario']:
            comp_scenario.append(scenario)
        form.comp_scenario.data = comp_scenario
        data_feature = list()
        for feature in competition['data_feature']:
            data_feature.append(feature)        
        form.data_feature.data = data_feature
        return render_template('competition/compUpdate.html', form=form)
Ejemplo n.º 5
0
def competition_list_view(user_id):
    # check user's authentication by account_id in url whether match current_user.account_id
    # Mention!! Type of current_user.account_id is not string!
    if str(current_user.account_id) != user_id:
        auth = {'operator': False}
    else:
        auth = {'operator': True}

    # account function
    account_url = 'http://' + Config.ACCOUNT_SERVICE_URL + \
                  '/api/account/account-id/' + str(user_id)
    result = requests.get(account_url)
    if result.status_code == 200 and len(get_api_info(result)) > 0:
        auth['account_nickname'] = get_api_info(result)[0]['account_nickname']
    else:
        auth['account_nickname'] = 'Unknown'

    # main function process below
    own_competition_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                          '/api/competition/contributor-id/' + str(user_id)
    result = requests.get(own_competition_url)
    if result.status_code == 200:
        owner_comps_list = get_api_info(result)
        owner_comps_list.reverse()
        return render_template('competition/compMenu.html', comp_list=owner_comps_list, auth=auth)
Ejemplo n.º 6
0
def calculate_gas_consumption_by_given_date(first_date, last_date, boiler_room,
                                            boiler_no):
    data = list()
    result_dict = {}
    # assemble url
    search_first_url = 'http://' + Config.LOCALHOST_IP_PORT + \
                       url_for('gas.get_gas_document_by_boiler_room_and_no_and_date', boiler_room=boiler_room,
                               boiler_no=boiler_no, date=first_date)
    search_last_url = 'http://' + Config.LOCALHOST_IP_PORT + \
                      url_for('gas.get_gas_document_by_boiler_room_and_no_and_date', boiler_room=boiler_room,
                              boiler_no=boiler_no, date=last_date)
    first_date_doc_list = get_api_info(requests.get(search_first_url))
    last_date_doc_list = get_api_info(requests.get(search_last_url))
    # if all things are correct
    if len(first_date_doc_list) >= 1 and len(last_date_doc_list) >= 1:
        first_doc = first_date_doc_list[0]
        last_doc = last_date_doc_list[0]
        gas_consumption = round(
            float(first_doc['gas_indicator']) -
            float(last_doc['gas_indicator']), 3)
        if gas_consumption > 0:
            gas_consumption_type = '减少'
        elif gas_consumption == 0:
            gas_consumption_type = '持平'
        else:
            gas_consumption_type = '增加'
        result_dict['gas_consumption'] = abs(gas_consumption)
        result_dict['gas_consumption_type'] = gas_consumption_type
        result_dict['first_document'] = first_doc
        result_dict['last_document'] = last_doc
    # else Cannot find all relative document
    elif len(first_date_doc_list) < 1 and len(last_date_doc_list) < 1:
        result_dict['gas_consumption'] = 0
        result_dict['gas_consumption_type'] = '错误'
        result_dict['first_document'] = None
        result_dict['last_document'] = None
    # else Cannot find first relative document
    elif len(first_date_doc_list) < 1:
        last_doc = last_date_doc_list[0]
        result_dict['gas_consumption'] = 0
        result_dict['gas_consumption_type'] = '错误'
        result_dict['first_document'] = None
        result_dict['last_document'] = last_doc
    # else Cannot find last relative document
    elif len(last_date_doc_list) < 1:
        first_doc = first_date_doc_list[0]
        result_dict['gas_consumption'] = 0
        result_dict['gas_consumption_type'] = '错误'
        result_dict['first_document'] = first_doc
        result_dict['last_document'] = None
    # return result
    data.append(result_dict)
    return jsonify(data)
Ejemplo n.º 7
0
def delete_confirm(record_id):
    # auth process
    if current_user.is_authenticated is True:
        account = get_account_info_by_account_id(current_user.account_id)
    else:
        return redirect(url_for('auth.login_view'))
    # process end
    form = DeleteForm()
    # Get record info
    record_url = 'http://' + Config.DB_OPS_URL + \
                 '/api/gas/document/rid/' + str(record_id)
    result = requests.get(record_url)
    # Functional Part
    if form.validate_on_submit():
        if result.status_code == 200:
            user_id = get_api_info(result)[0]['employee_no']

            # check user's authentication by account_id in url whether match current_user.account_id
            # Mention!! Type of current_user.account_id is not string!
            if str(current_user.account_id) != str(user_id):
                # back to detail viewing page
                flash('试图删除不属于自己的数据', 'danger')
                return redirect(
                    url_for('auth.home_view',
                            account_id=current_user.account_id))

            # main function process below
            delete_url = 'http://' + Config.DB_OPS_URL + \
                         '/api/gas/document/' + str(record_id)
            requests.delete(delete_url)
            flash('数据删除成功', 'success')
            return redirect(
                url_for('auth.home_view', account_id=current_user.account_id))
    # View Part
    else:
        if result.status_code == 200:
            user_id = get_api_info(result)[0]['employee_no']

            # check user's authentication by account_id in url whether match current_user.account_id
            # Mention!! Type of current_user.account_id is not string!
            if str(current_user.account_id) != str(user_id):
                # back to detail viewing page
                return redirect(
                    url_for('auth.home_view',
                            account_id=current_user.account_id))

            # main function process below
            competition = get_api_info(result)[0]
            return render_template('recordDelete.html',
                                   form=form,
                                   account=account)
Ejemplo n.º 8
0
def competition_detail_view(comp_record_hash):
    comp_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
               '/api/competition/competition-record-hash/' + str(comp_record_hash)
    type_dict =    {"DM": "Data Mining",
                    "CV" : "Computer Vision",
                    "NLP": "Natural Language Processing",
                    "RL": "Reinforcement Learning/Robotics",
                    "SP": "Speech/Signal Proccessing"}
    result = requests.get(comp_url)
    if result.status_code == 200:
        competition = get_api_info(result)[0]
        # check user's authentication by account_id in url whether match current_user.account_id
        # Mention!! Type of current_user.account_id is not string!
        try:
            if str(current_user.account_id) != competition['contributor_id']:
                auth = {'operator': False}
            else:
                auth = {'operator': True}
        except AttributeError:
            auth = {'operator': False}

        if competition['deadline'] is None :
            competition['deadline'] = 'No deadline'
        return render_template('competition/compView.html', competition=competition, auth=auth,
                               type_dict=type_dict)
Ejemplo n.º 9
0
def signup_validation():
    # check whether user has already login
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    # get POST infos
    data_received = request.values.to_dict()
    print(data_received)

    # check password difference
    if data_received['password'] != data_received['password_confirm']:
        return redirect(url_for('signup_view'))

    # assemble url
    api_format = '/users'
    validation_url = 'http://' + Config.DB_SOURCE_IP + ':' + Config.DB_SOURCE_PORT + api_format

    # POST to DB source API
    result = requests.post(validation_url, data=data_received)

    # get validation infos from api
    validation_result = get_api_info(result)[0]

    # verify
    # 如果注册后返回的用户名 与 用户在注册页面输入的相同
    # 则表明注册成功
    print(validation_result)
    if validation_result['username'] == data_received['username']:
        verified_user = User(validation_result['id'])
        login_user(verified_user)
        return redirect(url_for('home'))
    else:
        return redirect(url_for('signup_view'))
Ejemplo n.º 10
0
def login_validation():
    # check whether user has already login
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    # get POST infos
    data_received = request.values.to_dict()

    # assemble url
    api_format = '/users/validation/'
    validation_url = 'http://' + Config.DB_SOURCE_IP + ':' + Config.DB_SOURCE_PORT + api_format

    # POST to DB source API
    result = requests.post(validation_url, data=data_received)

    # get validation infos from api
    validation_result = get_api_info(result)[0]
    # print(validation_result)
    # print(type(validation_result))
    # print(validation_result['validation'])
    # print(type(validation_result['validation']))

    # verify
    if validation_result['validation'] == 'True':
        verified_user = User(validation_result['uid'])
        login_user(verified_user)
        return redirect(url_for('home'))
    else:
        return redirect(url_for('login_view'))
Ejemplo n.º 11
0
def register_account():
    # check whether user has already login
    if current_user.is_authenticated:
        return redirect(url_for('auth.home_view', account_id=current_user.account_id,
                                _external=True, _scheme='https'))

    # main function process below
    form = RegisterForm()
    # POST method
    if form.validate_on_submit():
        # captcha validate ( get from session )
        if str(form.captcha.data).upper() != session.get('captcha_code'):
            flash('CAPTCHA is not Correct!', 'warning')
            return redirect(url_for('auth.register_view', _external=True, _scheme='https'))
        if form.password.data != form.re_password.data:
            flash('Passwords should be the same.', 'warning')
            return redirect(url_for('auth.register_view', _external=True, _scheme='https'))
        # account info
        account_info = dict()
        account_info['account_email'] = form.email.data
        account_info['account_nickname'] = form.nickname.data
        account_info['password'] = form.re_password.data
        register_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/account-creating'
        result = requests.post(register_url, data=account_info)
        if result.status_code == 200:
            account = get_api_info(result)[0]
            return redirect(url_for('auth.login_view', account_id=account['account_id'],
                                    _external=True, _scheme='https'))
        else:
            flash('Please use an different email address.', 'danger')
            return redirect(url_for('auth.register_view', _external=True, _scheme='https'))
Ejemplo n.º 12
0
def send_reset_password_email_by_account_email():
    account_email = request.form.get('account_email')
    destin_url = 'http://' + Config.ACCOUNT_SERVICE_URL +\
                 '/api/reset-password/token-creating/account-email/' + str(account_email)
    account_to_reset = get_api_info(requests.get(destin_url))[0]
    send_password_reset_email(account_to_reset)
    data = [{'account_email': account_email, 'email_status': 'success'}]
    return jsonify(data)
Ejemplo n.º 13
0
def reset_password_request_receive_form():
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        account_email = form.email.data
        dest_url = 'http://' + Config.MAIL_SENDING_SERVICE_URL + '/api/reset-password/email-sending-by-account-email'
        result = requests.post(dest_url, data={'account_email': account_email})
        account_to_reset = get_api_info(result)
        return render_template('auth/email/inform_reset_email.html', account_email=account_email)
Ejemplo n.º 14
0
def reset_password_receiving_token(token):
    form = ResetPasswordForm()
    dest_url = 'http://' + Config.MAIL_SENDING_SERVICE_URL + '/api/reset-password/token-receiving/' +\
               str(token)
    result = requests.get(dest_url)
    if result.status_code == 200:
        account_to_reset = get_api_info(result)[0]
        return render_template('auth/email/reset_password.html', form=form, account_email=account_to_reset['account_email'])
Ejemplo n.º 15
0
def competition_detail_view(comp_record_hash):
    comp_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
               '/api/competition/competition-record-hash/' + str(comp_record_hash)
    result = requests.get(comp_url)
    if result.status_code == 200:
        competition = get_api_info(result)[0]
        return render_template('competition/compView.html',
                               competition=competition)
Ejemplo n.º 16
0
def send_registration_email_by_account_id():
    account_id = request.form.get('account_id')
    destin_url = 'http://' + Config.ACCOUNT_SERVICE_URL +\
                 '/api/registration/token-creating/account-id/' + str(account_id)
    account_unverify = get_api_info(requests.get(destin_url))[0]
    send_register_email(account_unverify)
    data = [{'account_id': account_id, 'email_sending_status': 'success'}]
    return jsonify(data)
Ejemplo n.º 17
0
def competition_updating_function(comp_record_hash):
    form = CompetitionUpdateForm()
    if form.validate_on_submit():
        # Get competition info
        comp_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                   '/api/competition/competition-record-hash/' + str(comp_record_hash)
        result = requests.get(comp_url)
        if result.status_code == 200:
            mod_competition = get_api_info(result)[0]

            # check user's authentication by account_id in url whether match current_user.account_id
            # Mention!! Type of current_user.account_id is not string!
            if str(current_user.account_id) != str(mod_competition['contributor_id']):
                # back to detail viewing page
                return redirect(
                    url_for('competition-operator.competition_detail_view', comp_record_hash=comp_record_hash))

            # Update Info
            update_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                '/api/competition/competition-record-hash/' + comp_record_hash

            mod_competition['comp_title'] = form.comp_title.data
            mod_competition['comp_subtitle'] = form.comp_subtitle.data
            mod_competition['comp_range'] = form.comp_range.data
            mod_competition['comp_url'] = form.comp_url.data
            mod_competition['prize_currency'] = form.prize_currency.data
            mod_competition['prize_amount'] = form.prize_amount.data
            mod_competition['deadline'] = form.deadline.data
            mod_competition['timezone'] = form.timezone.data
            mod_competition['update_time'] = get_current_datetime()

            mod_competition['comp_description'] = form.comp_description.data
            host_list = [{'comp_host_name': form.comp_host_name.data, 'comp_host_url': form.comp_host_url.data}]
            mod_competition['comp_host'] = str(host_list)

            comp_scenario_list = str_to_right_type(str(form.comp_scenario.data))
            mod_competition['comp_scenario'] = str(comp_scenario_list)
            data_feature = str_to_right_type(str(form.data_feature.data))
            mod_competition['data_feature'] = str(data_feature)

            result = requests.put(update_url, data=mod_competition)
            if result.status_code == 200:
                user_id = get_api_info(result)[0]['contributor_id']
                return redirect(url_for('competition-operator.competition_detail_view',
                                        comp_record_hash=mod_competition['comp_record_hash']))
Ejemplo n.º 18
0
def competition_list_view(user_id):
    # ToDo: Auth recognization
    own_competition_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                          '/api/competition/contributor-id/' + str(user_id)
    result = requests.get(own_competition_url)
    if result.status_code == 200:
        owner_comps_list = get_api_info(result)
        return render_template('competition/compMenu.html',
                               comp_list=owner_comps_list)
Ejemplo n.º 19
0
def competition_updating_function(comp_record_hash):
    form = CompetitionUpdateForm()
    # ToDo: Auth recognization
    if form.validate_on_submit():
        # Get competition info
        comp_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                   '/api/competition/competition-record-hash/' + str(comp_record_hash)
        result = requests.get(comp_url)
        if result.status_code == 200:
            mod_competition = get_api_info(result)[0]

            # Update Info
            update_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                '/api/competition/competition-record-hash/' + comp_record_hash

            mod_competition['comp_title'] = form.comp_title.data
            mod_competition['comp_subtitle'] = form.comp_subtitle.data
            mod_competition['comp_range'] = form.comp_range.data
            mod_competition['comp_url'] = form.comp_url.data
            mod_competition['prize_currency'] = form.prize_currency.data
            mod_competition['prize_amount'] = form.prize_amount.data
            mod_competition['deadline'] = form.deadline.data
            mod_competition['timezone'] = form.timezone.data
            mod_competition['update_time'] = get_current_datetime()

            mod_competition['comp_description'] = form.comp_description.data
            host_list = [{
                'comp_host_name': form.comp_host_name.data,
                'comp_host_url': form.comp_host_url.data
            }]
            mod_competition['comp_host'] = str(host_list)

            comp_scenario_list = [str(form.comp_scenario.data)]
            mod_competition['comp_scenario'] = str(comp_scenario_list)
            data_feature = [str(form.data_feature.data)]
            mod_competition['data_feature'] = str(data_feature)

            result = requests.put(update_url, data=mod_competition)
            if result.status_code == 200:
                user_id = get_api_info(result)[0]['contributor_id']
                return redirect(
                    url_for(
                        'competition-operator.competition_detail_view',
                        comp_record_hash=mod_competition['comp_record_hash']))
Ejemplo n.º 20
0
def home_view(account_id):
    # check user's authentication by account_id in url whether match current_user.account_id
    # Mention!! Type of current_user.account_id is not string!
    if str(current_user.account_id) != account_id:
        return redirect(url_for('auth.home_view', account_id=str(current_user.account_id)))

    # get records from mongodb
    gas_records_url = 'http://' + Config.DB_OPS_URL + '/api/gas/document/employee-no/fuzzy/' + account_id
    water_records_url = 'http://' + Config.DB_OPS_URL + '/api/water/document/employee-no/fuzzy/' + account_id
    elec_records_url = 'http://' + Config.DB_OPS_URL + '/api/elec/document/employee-no/fuzzy/' + account_id
    result_gas = requests.get(gas_records_url)
    result_water = requests.get(water_records_url)
    result_elec = requests.get(elec_records_url)
    if result_elec.status_code == 200 and result_gas.status_code == 200 and result_water.status_code ==200:
        gas_record_list = get_api_info(result_gas)
        water_record_list = get_api_info(result_water)
        elec_record_list = get_api_info(result_elec)
        gas_record_list.reverse()
        water_record_list.reverse()
        elec_record_list.reverse()
    else:
        gas_record_list = water_record_list = elec_record_list = []

    # get record from user info
    user_records_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/all-accounts'
    result_user = requests.get(user_records_url)
    if result_user.status_code == 200:
        user_record_list = get_api_info(result_user)
    else:
        user_record_list = []

    # main function process below
    form = RegisterRequestForm()
    account_info_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/account-id/' +\
        str(account_id)
    result = requests.get(account_info_url)
    if result.status_code == 200:
        account_info = get_api_info(result)[0]
        return render_template('auth/individual/home_page.html', form=form, account=account_info,
                               gas_record_list=gas_record_list, water_record_list=water_record_list,
                               elec_record_list=elec_record_list, user_record_list=user_record_list)
    else:
        return redirect(url_for('auth.login_view'))
Ejemplo n.º 21
0
def announcement():
    query_url = 'http://' + Config.DB_CONNECTOR_URL + '/queries/' + 'Administer'
    # 获取最新的 comments 信息
    result = requests.get(query_url)
    queries_list = get_api_info(result)
    # 逆序,将最新的留言放置最前
    queries_list.reverse()
    # 处理 GET 的逻辑
    return render_template('announcement.html', title='Rules', comments=queries_list)
    pass
Ejemplo n.º 22
0
def index():
    addr = 'http://' + Config.COMPETITION_SERVICE_URL + '/api/competition/all-competitions'
    info_list = get_api_info(requests.get(addr))
    info_list = sorted(Filtering_pastcomp(info_list), key=Func_deadline) # Filtering and sort the list by deadline

    return render_template(
        "index.html",
        # id_type_checkboxs=id_type_checkboxs,
        id_type2_checkboxs=id_type2_checkboxs,
        competitions=info_list,
    )
Ejemplo n.º 23
0
def welcome():
    form = PostForm()
    query_url = 'http://' + Config.DB_CONNECTOR_URL + '/all-queries'
    # 获取最新的 comments 信息
    result = requests.get(query_url)
    queries_list = get_api_info(result)
    # 逆序,将最新的留言放置最前
    queries_list.reverse()
    # 处理 GET 的逻辑
    return render_template('frontPage.html', title='Greetings!', comments=queries_list, form=form)
    pass
Ejemplo n.º 24
0
def login_view():
    # check whether user has already login
    if current_user.is_authenticated:
        return redirect(url_for('auth.home_view', account_id=current_user.account_id))

    # main function process below
    form = LoginForm()
    captcha = dict()
    captcha_url = 'http://' + Config.CAPTCHA_SERVICE_URL + '/api/hash-match/captcha'
    result = requests.get(captcha_url)
    if result.status_code == 200:
        captcha['captcha_code'] = get_api_info(result)[0]['CAPTCHA']
        captcha['hash_code'] = get_api_info(result)[0]['Hash-Code']
        # store the captcha code into session
        session['captcha_code'] = captcha['captcha_code']
        captcha['captcha_url'] = 'http://' + Config.CAPTCHA_SERVICE_URL +\
                                 '/api/hash-match/captcha/' + captcha['hash_code']
    else:
        captcha['captcha_code'] = '0000'
        captcha['captcha_url'] = 'error'
    return render_template('auth/login/login.html', form=form, captcha=captcha)
Ejemplo n.º 25
0
def home_view(account_email):
    form = RegisterRequestForm()
    account_info_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/account-email/' +\
        str(account_email)
    result = requests.get(account_info_url)
    if result.status_code == 200:
        account_info = get_api_info(result)[0]
        return render_template('auth/individual/home_page.html',
                               form=form,
                               account=account_info)
    else:
        return redirect('auth.login_view')
Ejemplo n.º 26
0
def reset_password(token):
    form = ResetPasswordForm()
    if form.validate_on_submit():
        dest_url = 'http://' + Config.MAIL_SENDING_SERVICE_URL + '/api/reset-password/token-receiving/' +\
                   str(token)
        new_password = str(form.re_new_password.data)
        result = requests.get(dest_url)
        account_to_reset = get_api_info(result)[0]
        account_to_reset['password'] = new_password
        update_account_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/account-updating'
        requests.put(update_account_url, data=account_to_reset)
        return render_template('auth/email/inform_reset_success.html', form=form, account_email=account_to_reset['account_email'])
Ejemplo n.º 27
0
def receive_reset_password_token(token):
    data = list()
    destin_url = 'http://' + Config.ACCOUNT_SERVICE_URL +\
                 '/api/reset-password/token-receiving/' + str(token)
    result = requests.get(destin_url)
    # Incorrect operations with error response
    if result.status_code == 400:
        return result.content
    # change account_status
    else:
        account_to_reset = get_api_info(result)[0]
        data.append(account_to_reset)
        return jsonify(data)
Ejemplo n.º 28
0
def competition_delete_confirm(comp_record_hash):
    form = CompetitionDeleteForm()
    # Get competition info
    comp_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
               '/api/competition/competition-record-hash/' + str(comp_record_hash)
    result = requests.get(comp_url)
    # Functional Part
    if form.validate_on_submit():
        if result.status_code == 200:
            user_id = get_api_info(result)[0]['contributor_id']

            # check user's authentication by account_id in url whether match current_user.account_id
            # Mention!! Type of current_user.account_id is not string!
            if str(current_user.account_id) != str(user_id):
                # back to detail viewing page
                return redirect(
                    url_for('competition-operator.competition_detail_view', comp_record_hash=comp_record_hash))

            # main function process below
            delete_url = 'http://' + Config.COMPETITION_SERVICE_URL + \
                         '/api/competition/competition-record-hash/' + str(comp_record_hash)
            requests.delete(delete_url)
            return redirect(url_for('competition-operator.competition_list_view', user_id=user_id))
    # View Part
    else:
        if result.status_code == 200:
            user_id = get_api_info(result)[0]['contributor_id']

            # check user's authentication by account_id in url whether match current_user.account_id
            # Mention!! Type of current_user.account_id is not string!
            if str(current_user.account_id) != str(user_id):
                # back to detail viewing page
                return redirect(
                    url_for('competition-operator.competition_detail_view', comp_record_hash=comp_record_hash))

            # main function process below
            competition = get_api_info(result)[0]
            return render_template('competition/compDelete.html', form=form, competition=competition)
Ejemplo n.º 29
0
def gas_stats_panel():
    # auth process
    if current_user.is_authenticated is True:
        account = get_account_info_by_account_id(current_user.account_id)
    else:
        return redirect(url_for('auth.login_view'))
    # process end

    form = GasDataStatsForm()
    # functional url
    basic_successive_url = 'http://' + Config.DB_OPS_URL + '/api/gas/calculating/gas-consumption/successive/'
    basic_sum_url = 'http://' + Config.DB_OPS_URL + '/api/gas/calculating/gas-consumption/inexact-date/'

    # post function
    if form.validate_on_submit():
        boiler_room = str(form.boiler_room_and_no.data).split('/')[0]
        boiler_no = str(form.boiler_room_and_no.data).split('/')[1]
        sum_url = basic_sum_url + boiler_room + '/' + boiler_no + '/' +\
                        str(form.start_date.data) + '/' + str(form.end_date.data)
        successive_url = basic_successive_url + boiler_room + '/' + boiler_no + '/' +\
                         str(form.start_date.data) + '/' + str(form.end_date.data)
    # get function
    else:
        today_date = get_current_date()
        last_date = get_last_date()
        form.start_date.data = get_last_date_strftime()
        form.end_date.data = get_current_date_strftime()

        default_boiler_room_and_no = GasInfoClass().get_gas_url_list()[0]
        sum_url = basic_sum_url + default_boiler_room_and_no + '/' + last_date + '/' + today_date
        successive_url = basic_successive_url + default_boiler_room_and_no + '/' + last_date + '/' + today_date
        flash('默认统计"今日与昨日"的燃气消耗量。', 'info')
    # get relative gas data
    # get first with dict type
    consumption_sum_dict = get_api_info_first(requests.get(sum_url))
    # get all with list type
    consumption_successive_list = get_api_info(requests.get(successive_url))
    if consumption_sum_dict['gas_consumption_type'] == '错误' or\
            consumption_sum_dict['gas_consumption_type'] == '日期区间错误':
        flash('无相关数据!', 'danger')
    else:
        flash('数据统计成功!', 'success')
    # render templates
    return render_template(
        'gas/statsPanel.html',
        consumption_sum_dict=consumption_sum_dict,
        account=account,
        consumption_successive_list=consumption_successive_list,
        form=form,
        title='燃气数据统计')
Ejemplo n.º 30
0
def calculate_gas_consumption_by_inexact_date(first_date, last_date,
                                              boiler_room, boiler_no):
    data = list()
    # assemble url
    search_url = 'http://' + Config.LOCALHOST_IP_PORT + \
                 url_for('gas.calculate_gas_consumption_successive_by_boiler_room_and_no', boiler_room=boiler_room,
                         boiler_no=boiler_no)
    # search list has been sorted!!
    search_list = get_api_info(requests.get(search_url))
    if len(search_list) >= 1:
        if search_list[0]['gas_consumption_type'] != '错误':
            gas_doc_list = list()
            for consumption_dict in search_list:
                gas_doc_list.append(consumption_dict['first_document'])
                gas_doc_list.append(consumption_dict['last_document'])
            # scale date
            successive_list = list()
            for gas_doc in gas_doc_list:
                # pop item
                if gas_doc['date'] >= first_date and gas_doc[
                        'date'] <= last_date:
                    successive_list.append(gas_doc)
            # this list only include gas_doc whose date in the scale you given
            if len(successive_list) >= 1:
                result_dict = {}
                gas_consumption = round(
                    float(successive_list[0]['gas_indicator']) -
                    float(successive_list[-1]['gas_indicator']), 3)
                if gas_consumption > 0:
                    gas_consumption_type = '减少'
                elif gas_consumption == 0:
                    gas_consumption_type = '持平'
                else:
                    gas_consumption_type = '增加'
                result_dict['gas_consumption'] = abs(gas_consumption)
                result_dict['gas_consumption_type'] = gas_consumption_type
                result_dict['first_document'] = successive_list[0]
                result_dict['last_document'] = successive_list[-1]
                data.append(result_dict)
            else:
                error_dict = {}
                error_dict['gas_consumption'] = 0
                error_dict['gas_consumption_type'] = '日期区间错误'
                error_dict['first_document'] = None
                error_dict['last_document'] = None
                data.append(error_dict)
        else:
            data = search_list
    return jsonify(data)