Пример #1
0
def initUser():
    UTENTI_INSERITI = 15
    CREDITI = [20, 30, 40, 55, 60, 75]
    NOMI = [
        "Luca", "Giovanni", "Mario", "Lucia", "Anna", "Assunta", "Giorgio",
        "Davide", "Michele", "Dario", "Valentina", "Sofia", "Daniela", "Gaia"
    ]
    COGNOMI = [
        "Rossi", "Sartori", "Bedin", "Rigon", "Casarotto", "Pavan", "Zanatta",
        "Scarpa", "Costantini", "Carraro"
    ]
    MAX_ANNO = 2000
    nome = cognome = credito = 0
    anno = MAX_ANNO - UTENTI_INSERITI
    for i in range(UTENTI_INSERITI):
        conn = engineAdmin.connect()
        email = NOMI[nome % len(NOMI)] + str(i) + "@gmail.it"
        insuser = users.insert().values(name=NOMI[nome % len(NOMI)],
                                        surname=COGNOMI[cognome %
                                                        len(COGNOMI)],
                                        email=email,
                                        password=1)
        conn.execute(insuser)
        query = select([users.c.id]).where(users.c.email == email)
        ris = convertToInt(str(conn.execute(query).fetchone()))
        insclients = clients.insert().values(id=ris,
                                             birthDate=str(anno) + "-03-12",
                                             credit=CREDITI[credito %
                                                            len(CREDITI)])
        conn.execute(insclients)
        conn.close()
        nome = nome + 1
        cognome = cognome + 1
        credito = credito + 1
        anno = anno + 1
Пример #2
0
def initManager():
    MANAGER_INSERITI = 5
    NOMI = [
        "Luca", "Giovanni", "Mario", "Lucia", "Anna", "Assunta", "Giorgio",
        "Davide", "Michele", "Dario", "Valentina", "Sofia", "Daniela", "Gaia"
    ]
    COGNOMI = [
        "Rossi", "Sartori", "Bedin", "Rigon", "Casarotto", "Pavan", "Zanatta",
        "Scarpa", "Costantini", "Carraro"
    ]
    nome = cognome = 0
    for i in range(MANAGER_INSERITI):
        conn = engineAdmin.connect()
        email = COGNOMI[cognome % len(COGNOMI)] + str(i) + "@ilMolo.it"
        insuser = users.insert().values(name=NOMI[nome % len(NOMI)],
                                        surname=COGNOMI[cognome %
                                                        len(COGNOMI)],
                                        email=email,
                                        password=1)
        conn.execute(insuser)
        query = select([users.c.id]).where(users.c.email == email)
        ris = convertToInt(str(conn.execute(query).fetchone()))
        insmanagers = managers.insert().values(id=ris,
                                               admin=False,
                                               financialReport=None)
        conn.execute(insmanagers)
        conn.close()
        nome = nome + 1
        cognome = cognome + 1
Пример #3
0
def register():
    if request.method == 'POST':
        name = request.form.get("name")
        surname = request.form.get("surname")
        email = request.form.get("email")
        password = request.form.get("password")
        birthdate = request.form.get("birthdate")
        if not name or not email or not password or not birthdate or not surname:
            flash("Devi inserire tutti i dati")
            return redirect("/register")
        #eta' minima di iscrizione 13 anni
        min = date.today() - timedelta(days=4745)
        if datetime.strptime(birthdate, "%Y-%m-%d").date(
        ) > min:  #mi serve per convertire una stringa in un tipo datetime
            flash("Inserisci una data di compleanno valida", "error")
            return redirect("/register")
        conn = choiceEngine()
        #mi serve per controllare la mail inserita non sia gia stata utilizzata
        u = select([users]).where(users.c.email == bindparam('email'))
        y = conn.execute(u, {'email': email}).fetchone()
        conn.close()
        if y is not None:
            flash('Email gia usata, riprova con un altra!', 'error')
            return redirect('/register')
        conn = choiceEngine()
        ins = users.insert(None).values(name=bindparam('name'),
                                        surname=bindparam('surname'),
                                        email=bindparam('email'),
                                        password=bindparam('password'))
        conn.execute(ins, {
            'name': name,
            'surname': surname,
            'email': email,
            'password': password
        })
        conn.close()
        conn = choiceEngine()
        query = select([users]).where(users.c.email == bindparam('email'))
        ris = conn.execute(query, {'email': email}).fetchone()
        insclients = clients.insert(None).values(id=ris.id,
                                                 birthDate=birthdate,
                                                 credit=0.)
        conn.execute(insclients)
        conn.close()
        flash('Ti sei registrato correttamente!', 'info')

        return redirect("/")
    return render_template("/user/noLogged/register.html")
Пример #4
0
def initAdmin():
    ins = users.insert().values(name="Admin",
                                surname="Admin",
                                email="*****@*****.**",
                                password="******")

    conn = engineAdmin.connect()
    conn.execute(ins)

    query = select([users]).where(
        users.c.email ==
        "*****@*****.**")  #mi serve per ritrovarmi l'ID corretto
    ris = conn.execute(query).fetchone()

    ins = managers.insert().values(id=ris.id, admin=True, financialReport=0)
    conn.execute(ins)
    conn.close()
Пример #5
0
def registerManager():
    if request.method == 'POST':
        name = request.form.get("name")
        surname = request.form.get("surname")
        email = request.form.get("email")
        password = request.form.get("password")
        if not name or not email or not password or not surname:  #controllo non ci siano valori mancanti
            flash("Devi inserire tutti i dati")  #in caso mando un errore
            return redirect("/registerManager")
        conn = choiceEngine()
        #mi serve per controllare che la mail inserita non sia gia stata utilizzata
        u = select([users]).where(users.c.email == bindparam('email'))
        y = conn.execute(u, {'email': email}).fetchone()
        conn.close()
        if y is not None:
            flash('Email gia usata, riprova con un altra!', 'error')
            return redirect('/registerManager')

        conn = choiceEngine()
        #insert sulla tabella users
        ins = users.insert(None).values(name=bindparam('name'),
                                        surname=bindparam('surname'),
                                        email=bindparam('email'),
                                        password=bindparam('password'))
        conn.execute(ins, {
            'name': name,
            'surname': surname,
            'email': email,
            'password': password
        })
        conn.close()

        conn = choiceEngine()
        query = select([users]).where(users.c.email == bindparam('email'))
        #mi serve per ritrovarmi l'ID corretto ed effettuare il giusto inserimento nella tabella user
        ris = conn.execute(query, {'email': email}).fetchone()
        insmanager = managers.insert(None).values(id=ris.id,
                                                  admin=False,
                                                  financialReport=None)
        conn.execute(insmanager)
        conn.close()
        return redirect("/")
    return render_template("/manager/admin/registerManager.html")