Esempio n. 1
0
 def POST(self):        
     upload = web.input(bigImage={}, sampleImage={})
     print (upload.contact, upload.instructions, 
             upload.bigImage.filename, upload.sampleImage.filename)
     
     if upload['contact'] and upload['instructions'] and upload.bigImage.filename:
         # write fields to db
         uid = model.insert_request(upload['contact'], upload['instructions'])
         print "New request uid: ", uid
         
         # write file to server
         filepath = upload.bigImage.filename.replace('\\','/') # correct Windows-style paths
         filename = filepath.split('/')[-1] # grab the filename with extension
         
         store = config.request_store
         write_path = model.mkdir_storage_unless_exists(store, uid)
         model.write_file(filename, write_path, upload.bigImage.file)
         
         # write sample image to server IF provided
         if upload.sampleImage.filename:
             filepath = upload.sampleImage.filename.replace('\\','/') # correct Windows-style paths
             filename = filepath.split('/')[-1] # grab the filename with extension
             model.write_file(filename, '..', upload.sampleImage.file)
         
     confirm.send_mail(upload.contact, uid)
     raise web.seeother('/askconfirm')
def handle_request(request):
    if request.GET.button:
        if __is_authenticated(request):
            return successfully_authenticated(request.GET.user)

        write_file(request.GET.user)
        attempts = ', '.join(read_file())

        return access_denied(attempts)

    return login_page()
def handle_request(request):
    if request.GET.button:
        if __is_authenticated(request):
            return successfully_authenticated(request.GET.user)

        write_file(request.GET.user)
        file_content = read_file()
        users = set(file_content)
        user_attempts = []

        for user in users:
            attemps = file_content.count(user)
            user_attempts.append((user, attemps))

        return access_denied(user_attempts)

    return login_page()
def handle_add_contacts_request():
    if request.GET.button:
        name = request.GET.name
        age = request.GET.age
        gender = request.GET.gender

        if name or age or gender:
            if name and age and gender:
                write_file(f'{name};{age};{gender}')
            else:
                return add_contact('Preencha todos os dados')

        file = read_file()

        return (redirect('/list-contacts')
                if file else add_contact('O arquivo está vazio'))

    return add_contact()
def handle_add_contacts_request():
    if request.GET.button:
        name = request.GET.name
        id = request.GET.id
        email = request.GET.email
        phone = request.GET.phone

        if name or id or email or phone:
            if name and id and email and phone:
                write_file(f'{name};{id};{email};{phone}')
            else:
                return add_contact('Preencha todos os dados')

        file = read_file()

        return (redirect('/list-contacts') if file
                else add_contact('O arquivo está vazio'))

    return add_contact()
Esempio n. 6
0
def submit():
    user = check_session()
    if user is None:
        return Response(response="unauthorized",
                        status=401,
                        mimetype="text/plain")

    content = request.json
    app.logger.info('submit %s %s', user.email, content['language'])

    challenge = next(x for x in CHALLENGES
                     if x.identifier == content['challenge'])

    identifier = str(uuid.uuid4())
    task = Task.create(uuid=identifier,
                       user=user,
                       state='reset',
                       challenge=challenge.identifier)
    task.max = challenge.max

    write_file(task.answer, content['answer'])

    meta = {
        "email": user.email,
        "language": content['language'],
    }

    write_file(task.meta, json.dumps(meta))

    task.state = 'todo'
    task.save()

    response = {'result': 'OK', 'task': task.json}
    return Response(response=json.dumps(response),
                    status=200,
                    mimetype="application/json")
Esempio n. 7
0
 def edit(self, name, id, email, phone):
     self.__remove_row_from_file(id)
     write_file(f'{name};{id};{email};{phone}')
Esempio n. 8
0
 def add(self, name, id, email, phone):
     write_file(f'{name};{id};{email};{phone}')