Exemplo n.º 1
0
def signup():
    an_error_has_ocurred = False
    username = request.form.get('username')
    password = request.form.get('password')
    repeat_password = request.form.get('password-repeat')
    errors = {}

    if not username or not utils.validate_data(username, 'username'):
        errors['username_error'] = 'Use alphanumeric characters (3 to 20) only'
        an_error_has_ocurred = True

    elif User.exist(username=username):
        errors['username_error'] = 'This username is already on use'
        an_error_has_ocurred = True

    if not password or not utils.validate_data(password, 'password'):
        errors['password_error'] = 'Use alphanumeric characters (3 to 20) only'
        an_error_has_ocurred = True

    elif not repeat_password or repeat_password != password:
        errors['repeat_password_error'] = 'The passwords do not match'
        an_error_has_ocurred = True

    if not an_error_has_ocurred:
        new_user = User(username=username, hashed_password=utils.encrypt_password(password))
        new_user.save()

        response = make_response(redirect('/'))
        response.set_cookie('user-token', utils.gen_secure_cookie(new_user.id))
        return response

    return render_template('index.html', username=username, **errors)
Exemplo n.º 2
0
def login():
    user = None
    an_error_has_ocurred = False
    username = request.form.get('username')
    password = request.form.get('password')
    errors = {}

    if not username or not utils.validate_data(username, 'username'):
        errors['username_error'] = 'Incorrect username'
        an_error_has_ocurred = True

    elif not User.exist(username=username):
        errors['username_error'] = 'This user does not exist'
        an_error_has_ocurred = True

    else:
        user = User.get(username=username)

        if not password:
            errors['password_error'] = 'Please, introduce the password'
            an_error_has_ocurred = True

        elif not utils.check_password(password, str(user.hashed_password)):
            errors['password_error'] = 'Wrong password'
            an_error_has_ocurred = True

    if not an_error_has_ocurred:
        response = make_response(redirect('/'))
        response.set_cookie('user-token', utils.gen_secure_cookie(user.id))
        return response

    return render_template('index.html', username=username, **errors)
Exemplo n.º 3
0
    def post(self):
        authenticated, this_user = utils.process_cookie(self.request)
        if authenticated:
            # a user should not be authenticated to sign up
            error = 'You are already a Fiider!'
            self.response.out.write(utils.generate_json(self.request, this_user, "POST", None, error))
            self.response.status = 403
            return

        err, req_params = utils.validate_data(self.request)
        if err:
            self.response.out.write(utils.generate_json(self.request, this_user, "POST", None, err.message()))
            self.response.status = 403
            return

        if utils.fail_blacklist(self.POST_BLACKLIST, req_params):
            error = 'Invalid data in body'
            self.response.out.write(utils.generate_json(self.request, this_user, "POST", None, error))
            self.response.status = 403
            return

        url_obj = urlparse.urlparse(str(self.request.url))
        subdirs = str(url_obj.path).split('/')
        num_layers = len(subdirs)

        # Only Handle the case of /user
        if num_layers == 2:
            userHandler.post_user(self, this_user, req_params)
        else:
            self.response.status = 405
Exemplo n.º 4
0
    def put(self):
        authenticated, this_user = utils.process_cookie(self.request)
        if not authenticated:
            self.response.status = 401
            return

        err, req_params = utils.validate_data(self.request)
        if err:
            self.response.out.write(utils.generate_json(self.request, this_user, "PUT", None, err.message()))
            self.response.status = 403
            return

        if utils.fail_blacklist(self.PUT_BLACKLIST, req_params):
            error = 'Invalid data in body'
            self.response.out.write(utils.generate_json(self.request, this_user, "PUT", None, error))
            self.response.status = 403
            return

        url_obj = urlparse.urlparse(str(self.request.url))
        subdirs = str(url_obj.path).split('/')
        num_layers = len(subdirs)
        last_dir_string = str(subdirs[len(subdirs)-1])

        if num_layers == 3:
            try:
                target_dish = int(last_dir_string)
                dishHandler.put_dish(self, this_user, target_dish, req_params)
            except ValueError:
                self.response.status = 405
        else:
            self.response.status = 405
Exemplo n.º 5
0
 def handle_form_modified(self):
     """
     decides what actions to take when selected fields in the form are
     modified, the selected fields will be determined by BIDS specification
     (required fields that affect validity of the dataset description file)
     :return:
     """
     data = self.form_widget.form.get_data()
     self.save_control.set_valid(validate_data(data))
Exemplo n.º 6
0
 async def post(self) -> Response:
     try:
         request_json = await self.request.json()
     except JSONDecodeError:
         return json_response({'status': 'bad request'}, status=400)
     data = validate_data(request_json, alarm_clock_schema)
     db: Engine = self.request.app['db']
     async with db.acquire() as conn:
         await create_alarm(conn, data)
     return Response()
Exemplo n.º 7
0
    def put(self):
        authenticated, this_user = utils.process_cookie(self.request)
        if not authenticated:
            self.response.status = 401
            return

        err, req_params = utils.validate_data(self.request)
        if err:
            self.response.out.write(utils.generate_json(self.request, this_user, "PUT", None, err.message()))
            self.response.status = 403
            return

        url_obj = urlparse.urlparse(str(self.request.url))
        subdirs = str(url_obj.path).split('/')
        num_layers = len(subdirs)
        last_dir_string = str(subdirs[len(subdirs)-1])

        if num_layers == 2:
            if utils.fail_blacklist(self.PUT_BLACKLIST, req_params):
                error = 'Invalid data in body'
                self.response.out.write(utils.generate_json(self.request, this_user, "PUT", None, error))
                self.response.status = 403
                return
            userHandler.put_user(self, this_user, req_params)
        elif num_layers == 4:
            try:
                url_user = int(subdirs[2])
                if this_user == url_user:
                    subdir_string = str(last_dir_string)
                    handling_function = put_sub_routes["PUT_" + subdir_string]
                    getattr(globals()[subdir_string + "Handler"], handling_function)(self, this_user, req_params)
                else:
                    self.response.status = 401
            except ValueError:
                self.response.status = 405
            except KeyError:
                self.response.status = 405
        else:
            self.response.status = 405
Exemplo n.º 8
0
def scrape_data(link, file_name):
    detail = requests.get(link)
    soup = bs4(detail.content, 'html.parser')
    membership_level = validate_data(
        soup.find('div', {'id': 'idMembershipLevelContainer'}))
    organization = validate_data(soup.find('div',
                                           {'id': 'idContainer2075262'}))
    first_name = validate_data(soup.find('div', {'id': 'idContainer2075260'}))
    nick_name = validate_data(soup.find('div', {'id': 'idContainer2100498'}))
    last_name = validate_data(soup.find('div', {'id': 'idContainer2075261'}))
    email = validate_data(soup.find('div', {'id': 'idContainer2075259'}))
    street_address = validate_data(
        soup.find('div', {'id': 'idContainer2783240'}))
    city = validate_data(soup.find('div', {'id': 'idContainer2100502'}))
    state = validate_data(soup.find('div', {'id': 'idContainer2100503'}))
    zip_code = validate_data(soup.find('div', {'id': 'idContainer2783241'}))
    phone = validate_data(soup.find('div', {'id': 'idContainer2075265'}))
    office = validate_data(soup.find('div', {'id': 'idContainer2783253'}))
    job_title = validate_data(soup.find('div', {'id': 'idContainer2075270'}))

    data = [
        membership_level, organization, first_name, last_name, nick_name,
        email, street_address, city, state, zip_code, phone, office, job_title
    ]

    with open(f'all_scraped_data/{file_name}.csv', 'a+', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(data)
    return 'Task Done!!!'
Exemplo n.º 9
0
 def post(self):
     error, req_params = utils.validate_data(self.request)
     if error:
         self.response.out.write(error.message())
         return
     logging.info(json.dumps(req_params))
Exemplo n.º 10
0
    def set_data(self):

        settings_default = return_data("./data/settings_default.json")
        if data_exists("./data/settings.json"):
            settings = return_data("./data/settings.json")
        else:
            logger.alt(
                "Set-Settings-Data",
                "No existing settings found to be parsed, creating new from default."
            )
            write_data("./data/settings.json", settings_default)
            settings = return_data("./data/settings.json")

        if not validate_data(settings, settings_default):
            logger.error(
                "Set-Settings-Data", "Parsed settings data is malformed! "
                "This will most likely cause a fatal exception. "
                "Try removing existing settings.json")

        self.webhook_edit.setText(settings["webhook"])
        if settings["webhookonbrowser"]:
            self.browser_checkbox.setChecked(True)
        if settings["webhookonorder"]:
            self.order_checkbox.setChecked(True)
        if settings["webhookonfailed"]:
            self.paymentfailed_checkbox.setChecked(True)
        if settings["browseronfailed"]:
            self.onfailed_checkbox.setChecked(True)
        if settings["runheadless"]:
            self.headless_checkbox.setChecked(True)
        if settings["bb_ac_beta"]:
            self.bb_ac_beta_checkbox.setChecked(True)
        if settings['onlybuyone']:
            self.buy_one_checkbox.setChecked(True)
        if settings['dont_buy']:
            self.dont_buy_checkbox.setChecked(True)
        if settings['random_delay_start']:
            self.random_delay_start.setText(settings["random_delay_start"])
        if settings['random_delay_stop']:
            self.random_delay_stop.setText(settings["random_delay_stop"])

        self.geckodriver_path = settings["geckodriver"]

        # try:
        #     self.geckodriver.setText(settings["geckodriver"])
        # except:
        #     self.geckodriver.setText("")

        try:
            self.bestbuy_user_edit.setText(settings["bestbuy_user"])
        except:
            self.bestbuy_user_edit.setText("")

        try:
            self.bestbuy_pass_edit.setText((Encryption().decrypt(
                settings["bestbuy_pass"].encode("utf-8"))).decode("utf-8"))
        except:
            self.bestbuy_pass_edit.setText("")

        try:
            self.target_user_edit.setText(settings["target_user"])
        except:
            self.target_user_edit.setText("")

        try:
            self.target_pass_edit.setText((Encryption().decrypt(
                settings["target_pass"].encode("utf-8"))).decode("utf-8"))
        except:
            self.target_pass_edit.setText("")

        try:
            self.gamestop_user_edit.setText(settings["gamestop_user"])
        except:
            self.gamestop_user_edit.setText("")

        try:
            self.gamestop_pass_edit.setText((Encryption().decrypt(
                settings["gamestop_pass"].encode("utf-8"))).decode("utf-8"))
        except:
            self.gamestop_pass_edit.setText("")

        self.update_settings(settings)