Exemplo n.º 1
0
def gen_default_client():
    """
    Generates the default client.
    :return: The default client.
    """
    default_client = Clients()
    default_client.id = 0
    default_client.name = "default"
    return default_client
def add_clients():
    clients = [
        Clients(name='Ally'),
        Clients(name='Blayze'),
        Clients(name='Courtney'),
        Clients(name='Delmer'),
    ]
    db_session.bulk_save_objects(clients, return_defaults=True)
    return clients
Exemplo n.º 3
0
def create_client(session, orga, name="test"):
    client = Clients()
    client.orga = orga
    client.email = name + "@test.com"
    client.name = name
    client.identifier = name + "id"

    session.add(client)
    session.commit()
    time.sleep(config.SPI_GENERATION_INTERVAL * 3)
    return client
Exemplo n.º 4
0
def add_new_client():
    body = json.loads(request.data)

    name = body.get('name', None)
    username = body.get('username', None)
    password = body.get('password', None)
    courriel = body.get('courriel', None)

    if name is None:
        return jsonify({'error': 'name cannot be null'})

    if username is None:
        return jsonify({'error': 'username cannot be null'})

    if password is None:
        return jsonify({'error': 'password cannot be null'})

    if courriel is None:
        return jsonify({'error': 'courriel cannot be null'})

    new_clients = Clients(name=name,
                          username=username,
                          password=password,
                          courriel=courriel)
    db.add(new_client)
    return jsonify({'result': new_client._dump()})
Exemplo n.º 5
0
def add(request):
    if request.method == 'POST':
        #form = ClientsForm(request.POST)
        user_id = request.POST.get('registerID')
        user_name = request.POST.get('registername')
        user_no = request.POST.get('registernum')
        user_network = request.POST.get('registernetwork')
        user_dob = request.POST.get('registerdob')
        q1 = Clients(name=user_name,
                     mob_no=user_no,
                     network=user_network,
                     dob=user_dob)
        q1.save()
        #registered = True
    else:
        pass

    return render(request, 'QA/add.html')
Exemplo n.º 6
0
def client_create(request, decoded):
    """
    REST endpoint to create a client.

    :param request: The flask request.
    :param decoded: The decoded json value from the with_json decorator.
    :return: json of the newly created client.
    """
    orga = int(request.args.get('ebuio_orgapk') or request.form.get('ebuio_orgapk'))

    client = Clients()
    client.orga = orga
    client.email = decoded['email']
    client.name = decoded['name']
    client.identifier = decoded['identifier']

    db.session.add(client)
    db.session.commit()
    return {'client': client.json}
Exemplo n.º 7
0
def create_rab():
    if db.session.query(Roles).filter_by(
            id_role=current_user.id_role).first().name != "Менеджер":
        return 'What are you doing here?'
    if request.method == 'GET':
        return render_template('create_rab.html',
                               role=db.session.query(Roles).filter_by(
                                   id_role=current_user.id_role).first().name)
    if request.method == 'POST':
        cipher = Salsa20.new(key=secret)
        fio = request.form['fio']
        created = time.strftime('%d/%m/%Y',
                                time.localtime())  # использовать дату
        dob = request.form['dob']
        if request.form['role'] == 'Стажер':
            role = 1
            id_position = 0
        elif request.form['role'] == 'Продавец-консультант':
            role = 1
            id_position = 1
        elif request.form['role'] == 'Менеджер':
            role = 2
            id_position = 2
        email = request.form['email']
        phone = request.form['phone']
        company = request.form['company']
        hash_password = generate_password_hash(request.form['password'])
        hash_address = request.form['address']
        hash_card = str(cipher.nonce +
                        cipher.encrypt(bytes(request.form['card'], 'utf-8')))
        amount = request.form['amount']
        new_Client = Clients(email=email,
                             fio=fio,
                             created=created,
                             dob=dob,
                             id_role=role)
        db.session.add(new_Client)
        db.session.commit()
        new_Contactdetailsclients = Contactdetailsclients(
            id_clients=new_Client.id_clients, phone=phone, company=company)
        new_Secretdate = Secretdate(id_clients=new_Client.id_clients,
                                    hash_password=hash_password,
                                    hash_address=hash_address)
        new_Card = Card(id_clients=new_Client.id_clients,
                        hash_card=hash_card,
                        amount=amount)
        new_Staff = Staff(id_staff=new_Client.id_clients,
                          id_position=id_position)
        db.session.add(new_Contactdetailsclients)
        db.session.add(new_Secretdate)
        db.session.add(new_Card)
        db.session.add(new_Staff)
        db.session.commit()
        return redirect('/login')
Exemplo n.º 8
0
def clients() -> Tuple[str, int]:
    """Запрос на вывод и создание клиента."""
    if request.method == 'GET':
        client_id = request.args.get('clientId')
        client = session.query(Clients).filter(Clients.id == client_id).first()
        json_return = {'id': client.id, 'name': client.name,
                       'is_vip': client.is_vip}
        return jsonify(json_return)

    elif request.method == 'POST':
        response_post = request.json
        name = response_post['name']
        is_vip = response_post['is_vip']
        create_client = Clients(name, is_vip)
        session.add(create_client)
        print(create_client.__repr__())
        session.commit()
        session.close()
        return 'created!', 200
    assert False
Exemplo n.º 9
0
    def register(self, user, password):
        validator = get_validator(user)

        if not validator.is_valid(password):
            raise StrongPasswordException("Your password is not strong enough")

        hashed_password, salt = hash_password(password)

        current_user = self.session.query(Clients.username).\
                        filter(Clients.username == user).first()

        if current_user is not None:
            raise ClientAlreadyRegistered('Client already registered')

        client = Clients(username=user, password=hashed_password, salt=salt)
        self.__commit_object(client)
Exemplo n.º 10
0
def create_client(session, orga, name="test"):
    client = Clients()
    client.orga = orga
    client.email = name + "@test.com"
    client.name = name
    client.identifier = name + "id"

    session.add(client)
    session.commit()
    time.sleep(config.SPI_GENERATION_INTERVAL * 3)
    return client
Exemplo n.º 11
0
def registration():
    if request.method == 'GET':
        return render_template('registration.html')
    if request.method == 'POST':
        cipher = Salsa20.new(key=secret)
        fio = request.form['fio']
        created = time.strftime('%d/%m/%Y',
                                time.localtime())  # использовать дату
        dob = request.form['dob']  # определить формат
        role = 0
        email = request.form['email']
        phone = request.form['phone']
        company = request.form['company']
        hash_password = generate_password_hash(request.form['password'])
        print(hash_password)
        hash_address = request.form['address']
        hash_card = str(cipher.nonce +
                        cipher.encrypt(bytes(request.form['card'], 'utf-8')))
        amount = request.form['amount']
        new_Client = Clients(email=email,
                             fio=fio,
                             created=created,
                             dob=dob,
                             id_role=role)
        db.session.add(new_Client)
        db.session.commit()
        new_Contactdetailsclients = Contactdetailsclients(
            id_clients=new_Client.id_clients, phone=phone, company=company)
        new_Secretdate = Secretdate(id_clients=new_Client.id_clients,
                                    hash_password=hash_password,
                                    hash_address=hash_address)
        new_Card = Card(id_clients=new_Client.id_clients,
                        hash_card=hash_card,
                        amount=amount)
        db.session.add(new_Contactdetailsclients)
        db.session.add(new_Secretdate)
        db.session.add(new_Card)
        db.session.commit()
        return redirect('/login')
Exemplo n.º 12
0
def client_create(request, decoded):
    """
    REST endpoint to create a client.

    :param request: The flask request.
    :param decoded: The decoded json value from the with_json decorator.
    :return: json of the newly created client.
    """
    orga = int(
        request.args.get('ebuio_orgapk') or request.form.get('ebuio_orgapk'))

    client = Clients()
    client.orga = orga
    client.email = decoded['email']
    client.name = decoded['name']
    client.identifier = decoded['identifier']

    db.session.add(client)
    db.session.commit()
    return {'client': client.json}
Exemplo n.º 13
0
def get_profile():
    cli = Clients.query.filter_by(id=current_user.id).first()
    username = ClientLog.query.filter_by(id=current_user.id).first()

    if cli is None:
        cli = Clients(id=current_user.id,
                      first_name=request.form.get('firstname'),
                      last_name=request.form.get('lastname'),
                      sex=request.form.get('sex'),
                      date_of_birth=request.form.get('date'),
                      location=request.form.get('location'))
        db.session.add(cli)

        for i in range(1, 11):
            # if request.form.get('v{}'.format(i)) is not None:
            #     v = Vaccines(name=request.form.get('v{}'.format(i)))
            #     db.session.add(v)
            vacc = VaccControl(
                client_id=current_user.id,
                vacc_id=Vaccines.query.filter_by(id=i).first().id,
                date=(datetime.date.today() - datetime.timedelta(
                    days=(730 - randint(1, 730)))).isoformat(),
                is_done=True
                if request.form.get('v{}'.format(i)) is not None else False)

            db.session.add(vacc)

    else:
        cli.first_name = request.form.get('firstname')
        cli.last_name = request.form.get('lastname')
        cli.sex = request.form.get('sex')
        cli.date_of_birth = request.form.get('date')
        cli.location = request.form.get('location')
        username.name = request.form.get('username')
        for i in range(1, 11):
            if request.form.get('v{}'.format(i)) is None:
                temp = db.session.query(VaccControl).filter_by(
                    client_id=current_user.id).filter_by(
                        is_done=True).join(Vaccines).filter_by(id=i).first()
                if temp is not None:
                    temp.is_done = False
            else:
                temp = db.session.query(VaccControl).filter_by(
                    client_id=current_user.id).join(Vaccines).filter_by(
                        id=i).first()
                if temp is not None:
                    temp.is_done = True
                else:
                    db.session.add(
                        VaccControl(client_id=current_user.id,
                                    vacc_id=Vaccines.query.filter_by(
                                        name=request.form.get('v{}'.format(
                                            i))).first().id,
                                    date=datetime.date.today().isoformat(),
                                    is_done=True))

    db.session.commit()

    if request.form.get('firstname') == '' or request.form.get(
            'lastname') == '' or request.form.get(
                'date') == '' or request.form.get(
                    'location') == '' or request.form.get('username') == '':
        flash("*")
        return redirect(url_for('main.profile'))
    return redirect(url_for('main.home'))
Exemplo n.º 14
0
def clients(rut):
    if request.method == 'GET':
        list = []
        if rut == "17.402.744-7" or rut == "20.968.696-1":
            resp = db.session.query(Clients).all(
            )  #DEPURAR ESTO, TOMAR RESP Y QUE EL MODEL ARROJE UN OBJ DE TODOS LOS CAMPOS
            for item in resp:
                list.append({
                    "clients_id": item.clients_id,
                    "clients_name": item.clients_name,
                    "clients_rut": item.clients_rut,
                    "clients_nationality": item.clients_nationality,
                    "clients_civilStatus": item.clients_civilStatus,
                    "clients_job": item.clients_job,
                    "clients_address": item.clients_address,
                    "clients_contact": item.clients_contact
                })
            return jsonify({"resp": list}), 200
        else:
            resp = db.session.query(Clients).filter_by(clients_rut=rut).all()
            for item in resp:
                list.append({
                    "clients_id": item.clients_id,
                    "clients_name": item.clients_name,
                    "clients_rut": item.clients_rut,
                    "clients_nationality": item.clients_nationality,
                    "clients_civilStatus": item.clients_civilStatus,
                    "clients_job": item.clients_job,
                    "clients_address": item.clients_address,
                    "clients_contact": item.clients_contact
                })
            return jsonify({"resp": list}), 200

    if request.method == 'POST':

        incomingData = request.get_json()
        existingClient = db.session.query(Clients).filter_by(
            clients_rut=incomingData['rut']).all(
            )  #CHECKING IF THE CLIENT ALREADY EXIST
        list = []
        for item in existingClient:
            list.append(item.clients_id)

        if len(list) == 0:
            insertedData = Clients(
                clients_name=incomingData['name'],
                clients_rut=incomingData['rut'],
                clients_nationality=incomingData['nationality'],
                clients_civilStatus=incomingData['civilStatus'],
                clients_job=incomingData['job'],
                clients_address=incomingData['address'],
                clients_contact=incomingData['contact'])
            db.session.add(insertedData)
            db.session.commit()
            lastId = insertedData.clients_id
            return jsonify({
                "resp": "inserted data",
                "lastId": str(lastId)
            }), 200

        if len(list) > 0:
            return jsonify({"resp": "client already exist", "lastId": list[0]})

    if request.method == 'PUT':
        incomingData = request.get_json()
        updateData = Clients.query.filter_by(clients_rut=rut)

        listOfNotEmptyStrings = []
        for item in incomingData:
            if incomingData[item] != "":
                listOfNotEmptyStrings.append(item)

        for item2 in listOfNotEmptyStrings:
            print(incomingData[item2], item2)
            updateData.update({item2: incomingData[item2]})
            db.session.commit()
        return "updated"

    if request.method == 'DELETE':
        deletedRow = Clients.query.filter_by(clients_rut=rut).first()
        db.session.delete(deletedRow)
        db.session.commit()
        return "data deleted", 200
Exemplo n.º 15
0
def save_or_update_station(sp, request, errors, station_instance=None, client=None, parent_station=None):
    """
    Saves or updates a station based on the request form values.

    :param sp: The service provider.
    :param request: The fask request.
    :param errors: The error list instance.
    :param station_instance: The station instance if any. If this is a new station leave this paramter to None.
    :param client: The client instance if this is an override for a client. If this is a new station leave this
        parameter to None.
    :param parent_station: The parent station of this station if this is a
    :return: the save/updated/same station instance and the errors list.
    """
    if not client:
        client = Clients()
        client.id = 0
        client.name = "default"

    is_override = "True" == request.form.get("is_client_override_" + str(client.id))
    if not is_override and client.id != 0:
        return station_instance, errors

    if not station_instance:
        station_instance = Station(int(request.form.get('ebuio_orgapk')))
    station_instance.service_provider_id = sp.id

    for field in station_fields:
        field_value = request.form.get(field + '_' + str(client.id))

        if parent_station and field_value == parent_station[field]:
            field_value = None
        setattr(station_instance, field, field_value)

    if not is_override and station_instance.name == "":
        errors.append("Please set a name")
        return station_instance, errors

    # handle special fields
    station_instance.radiovis_enabled = 'radiovis_enabled_' + str(client.id) in request.form
    station_instance.radioepg_enabled = station_instance.radiospi_enabled = 'radioepg_enabled_' + str(
        client.id) in request.form
    station_instance.radiotag_enabled = 'radiotag_enabled_' + str(client.id) in request.form
    station_instance.radioepgpi_enabled = 'radioepgpi_enabled_' + str(client.id) in request.form

    # handle genres
    clientid = str(client.id) if is_override else '0'
    genre_href = map(lambda key: request.form[key],
                     filter(lambda key: key.startswith('genrehref[]_' + clientid + "_") and request.form[key] != '',
                            request.form.keys()))
    genre_href = sorted(genre_href)
    genres = []

    for h in genre_href:
        genre_id = h.split(':')[-1]
        if genre_id != '':
            genres.append({'href': h, 'name': genres_map[genre_id]})

    station_instance.genres = json.dumps(genres)

    if is_override:
        station_instance.parent = parent_station.id
        station_instance.fk_client = client.id

    # save
    if (is_override or client.id == 0) and not station_instance.id:
        station_instance.gen_random_password()
        db.session.add(station_instance)

    return station_instance, errors