예제 #1
0
def insert_user(form):
    try:
        check_user = User.query(User.email == form.email.data).fetch(1)
        if check_user > 0:
            u = User()
            u.uuid = str(uuid.uuid4())
            u.nome = form.nome.data
            u.cognome = form.cognome.data
            u.password = hashlib.sha1(form.password.data).hexdigest()
            u.email = form.email.data

            # insert tariffa
            tariffe = Tariffa.query(Tariffa.visibilita == True).order(
                Tariffa.order).fetch()
            for i, tar in enumerate(tariffe):
                if (i + 1) == int(form.tariffa.data):
                    u.tariffa = tar.tariffa

            u.targa = form.targa.data
            u.put()
            return True

        return False
    except:
        return False
예제 #2
0
def auth_user(name, surname):
    try:
        # ndb.delete_multi(Models.Categorie.query(Models.Categorie.categoriaID == id).fetch(keys_only=True).get())
        usr = User().query(User.nome == name and User.cognome == surname).fetch(1)[0]
        usr.is_valid = True
        usr.put()
        return 'Utente abilitato!'
    except:
        return "Errore nell'abilitazione dell'utente!"
예제 #3
0
def change_targa(uuid, targa):
    try:
        # ndb.delete_multi(Models.Categorie.query(Models.Categorie.categoriaID == id).fetch(keys_only=True).get())
        usr = User().query(User.uuid == uuid).fetch(1)[0]
        usr.targa = targa
        usr.put()
        return True
    except:
        return False
예제 #4
0
def admin_user(name, surname):
    try:
        # ndb.delete_multi(Models.Categorie.query(Models.Categorie.categoriaID == id).fetch(keys_only=True).get())
        usr = User().query(User.nome == name and User.cognome == surname).fetch(1)[0]
        usr.has_superuser = True
        usr.put()
        return 'Utente admin!'
    except:
        return "Errore nell'admin dell'utente!"
예제 #5
0
def add_data():
    if request.method == 'GET':
        #utente
        usr = User()
        usr.nome = "Luca"
        usr.cognome = "Puggioninu"
        usr.uuid = str(uuid.uuid4())
        usr.password = hashlib.sha1("ciaone").hexdigest()
        usr.email = "*****@*****.**"
        usr.targa = "GF6543"
        usr.tariffa = "Tariffa 1"
        usr.is_valid = True
        usr.put()

        #admin
        usr = User()
        usr.nome = "Claudio"
        usr.cognome = "Marche"
        usr.uuid = str(uuid.uuid4())
        usr.password = hashlib.sha1("ciaone").hexdigest()
        usr.email = "*****@*****.**"
        usr.tariffa = "Tariffa 1"
        usr.targa = "GF6543"
        usr.is_valid = True
        usr.has_superuser = True
        usr.put()

        #tariffa
        tar = Tariffa()
        tar.tariffa = 'Tariffa 1'
        tar.description = "La piu' bella gazz"
        tar.prezzo = 5.00
        tar.order = 1
        tar.visibilita = True
        tar.put()

        tar = Tariffa()
        tar.tariffa = 'Tariffa 2'
        tar.description = "La meno bella gazz"
        tar.order = 2
        tar.prezzo = 5.00
        tar.visibilita = False
        tar.put()

        #parcheggi
        state = ['Libero', 'Prenotato', 'Occupato', 'Fuori Servizio']
        for piano in ['A', 'B', 'C', 'D']:
            for i in range(1, 41):
                parking = Parking()
                parking.piano = piano
                parking.number = i
                parking.stato = state[randint(0, 3)]
                parking.put()
        flash("Dati Aggiunti")
        return redirect(url_for('auth.login'))
예제 #6
0
def profilo():
    if request.method == 'GET':
        form = AddPlate()
        user = User().query(User.uuid == session['user']['user_id']).fetch(1)[0]

        try:
            tar = Tariffa.query(Tariffa.tariffa == user.tariffa).fetch(1)[0]
            tariffa = tar.tariffa
            descrizione = tar.description
            prezzo = tar.prezzo
        except:
            tariffa = None
            descrizione = None
            prezzo = None

        targhe = user.targa.split(",")
        return render_template('user/profilo.html', username=get_username(session), is_admin=session['user']['superuser'],
                               form=form, tariffa=tariffa, descr_tariffa=descrizione, prezzo_tariffa=prezzo,
                               targhe=targhe)
    # cancella o aggiungi targa nel profilo
    elif request.method == 'POST':
        command = request.form['command'].split('_')
        if command[0] == "delete":
            targa = command[1]
            user = User().query(User.email == session['user']['email']).fetch(1)[0]
            targhe = user.targa.split(',')
            targhe.remove(targa)
            user.targa = ','.join(targhe)
            user.put()

        elif command[0] == "add":
            targa = request.form['targa']
            user = User().query(User.email == session['user']['email']).fetch(1)[0]

            # check if exist
            targhe = user.targa.split(",")
            if targa == "":
                flash("Targa non valida!")
            else:
                if targa not in targhe:
                    user.targa = user.targa + ',' + targa
                    targhe = user.targa.split(",")
                    user.put()
                else:
                    flash("Targa precedentemente inserita!")

        return redirect(url_for('main.profilo'))
예제 #7
0
def profilo():
    if request.method == 'GET':
        form = AddPlate()
        user = User().query(
            User.uuid == session['user']['user_id']).fetch(1)[0]
        targhe = user.targa.split(",")

        return render_template('admin/profilo.html',
                               username=get_username(session),
                               form=form,
                               targhe=targhe)
    # gestione aggiungi o cancella targa
    elif request.method == 'POST':
        command = request.form['command'].split('_')
        if command[0] == "delete":
            targa = command[1]
            user = User().query(
                User.email == session['user']['email']).fetch(1)[0]
            targhe = user.targa.split(',')
            targhe.remove(targa)
            user.targa = ','.join(targhe)
            user.put()

        elif command[0] == "add":
            targa = request.form['targa']
            user = User().query(
                User.email == session['user']['email']).fetch(1)[0]

            # check if exist
            targhe = user.targa.split(",")
            if targa == "":
                flash("Targa non valida!")
            else:
                if targa not in targhe:
                    user.targa = user.targa + ',' + targa
                    targhe = user.targa.split(",")
                    user.put()
                else:
                    flash("Targa precedentemente inserita!")
        # attesa per salvataggio in database
        time.sleep(1)
        return redirect(url_for('admin.profilo'))