Ejemplo n.º 1
0
def homePage():
    if request.method == "GET":
        if session.get('username') is None:
            print("___app.py / homePage::homePage.html: User not logged in. Redirect to login.")
            return redirect(url_for('login'))
        if session['username']:
            print('___app.py / homePage::homePage.html: USER %s LOGGED IN.' % session.__getitem__('username') )
            return render_template('homePage.html')
Ejemplo n.º 2
0
def get_session_user() -> str or None:
    return session.__getitem__('current_user')
Ejemplo n.º 3
0
def logout():
    print("___app.py / logout::logout.html: Log out username: %s." % session.__getitem__('username'))
    session.clear()
    print("___app.py / logout::logout.html: Logout done. Session clear. Redirect to login.")
    return redirect(url_for('login'))
Ejemplo n.º 4
0
def login():
    if request.method == 'GET':
        if session.get('username') is None:
            print("___app.py / login::login.html: User not logged in.")
            return render_template('login.html')
        if session['username']:
            print("___app.py / login::login.html: User %s logged in. Redirect to homePage." % session.__getitem__('username'))
            return redirect(url_for('homePage'))

    else:
        session.clear()
        userLogin = request.form['userLog']
        passLogin = request.form['pwdLog'].encode('utf-8')
        curs = mysql.connection.cursor()
        curs.execute("SELECT * FROM tblUsers WHERE Username=%s", ([userLogin]))
        userInfo = curs.fetchone()
        curs.close()

        if len(userLogin) > 0:
            if userInfo is None:
                session['authenticated'] = False
                print("___app.py / login::login.html: Username not found.")
                return redirect(url_for('login'))
            if bcrypt.hashpw(passLogin, userInfo['Password'].encode('utf-8')) == userInfo['Password'].encode('utf-8'):

                session['username'] = userInfo['Username']
                session['numePrenume'] = userInfo['Nume'] + "    " + userInfo['Prenume']
                session['email'] = userInfo['Email']
                session['authenticated'] = True
                print("___app.py / login::login.html: Login success. Username: %s. Redirect to homePage." % session.__getitem__('username'))
                return redirect(url_for('homePage'))
            else:
                session['authenticated'] = False

                print("___app.py / login::login.html: LOGIN FAILED.")
                return redirect(url_for('login'))
Ejemplo n.º 5
0
def register():
    if request.method =='GET':
        if session.get('username') is None:
            print("___app.py / register::register.html: Session clear. Not logged in. Proceed to register.")
            return render_template('register.html')
        if session['username']:
            print("___app.py / register::register.html: User %s logged in. Redirect to homePage." % session.__getitem__('username'))
            return redirect(url_for('homePage'))

    if request.method == 'POST':
        session['reg'] = ""
        numeN        = request.form['nume']
        prenumeN     = request.form['prenume']
        emailN       = request.form['email']
        userN        = request.form['username']
        passwordN    = request.form['pwd2'].encode('utf-8')
        hash_pwd = bcrypt.hashpw(passwordN, bcrypt.gensalt())
        curs = mysql.connection.cursor()
        try:
            curs.callproc('register',[userN, numeN, prenumeN, emailN, hash_pwd])
            curs.close()
            eroareRegister = "OK"
            session['reg']='OK'
            print("___app.py / register::register.html: Register success. Username: %s." % [userN])
            session.clear()
            print("___app.py / register::register.html: CLEARING SESSION. PROCEED TO LOGIN. ")
            return redirect(url_for('login'))
        except Exception as e:
            print("___app.py / register::register.html: Error down.")
            print(e)
            if e.args[0] == 1062:
                eroareRegister = "Username already exist. Try another."
                print("___app.py / register::register.html: Username already exists in table.")

                session['reg'] = '1062'
                return redirect(url_for('register'))
Ejemplo n.º 6
0
def getGrafice():
    if request.method =='GET':
        if session.get('username') is None:
            print("___app.py / grafice::grafice.html: Session clear. Not logged in. Proceed to login.")
            return redirect(url_for('login'))
        if session['username']:
            print("___app.py / grafice::grafice.html: User %s logged in. Proceed to grafice.html." % session.__getitem__('username'))
            curs = mysql.connection.cursor()
            q2 = "SELECT tblRaioane.Categorie, SUM(Unitati) as 'NumarTotalUnitati' FROM tblMateriale " \
                 "RIGHT JOIN tblRaioane ON tblMateriale.RaionFK = tblRaioane.idRaion " \
                 "GROUP BY tblRaioane.Categorie;"
            curs.execute(q2)
            categoriiForChart = curs.fetchall()
            curs.close()
            return render_template('grafice.html', cat=categoriiForChart)
Ejemplo n.º 7
0
def adauga():
    if request.method == "GET":
        if session.get('username') is None:
            print("___app.py / adauga::adauga..html: Not logged in. Redirect to login.")
            return redirect(url_for('login'))
        if session['username']:
            print("___app.py / adauga::.html: User %s logged in. Proceed to adauga.html." % session.__getitem__('username'))
            curs = mysql.connection.cursor()
            query0 = 'SELECT idRaion FROM tblRaioane'
            curs.execute(query0)
            raioane = curs.fetchall()
            curs.close()
            return render_template('adauga.html',raioane=raioane)

    if request.method == 'POST':
        print("___app.py / adauga::adauga.html: doPost STARTED")
        numeAn          = request.form['nume']
        print("___app.py / adauga::adauga.html: NumeAngajat to be added: "+numeAn)
        prenumeAn       = request.form['prenume']
        print("___app.py / adauga::adauga.html: PrenumeAngajat to be added: "+prenumeAn)

        functieeAn      = request.form['functie']
        print("___app.py / adauga::adauga.html: FunctieAngajat to be added: "+functieeAn)

        dataAngajariiAn = request.form['data_angajarii']
        print("___app.py / adauga::adauga.html: DataAngajarii to be added: "+dataAngajariiAn)

        telAn           = request.form['telefon']
        print("___app.py / adauga::adauga.html: TelefonAngajat to be added: "+telAn)

        emailAn         = request.form['email']
        print("___app.py / adauga::adauga.html: EmailAngajat to be added: "+emailAn)

        salariuAn       = request.form['salariu']
        print("___app.py / adauga::adauga.html: Salariu to be added: "+salariuAn)

        try:
            curs = mysql.connection.cursor()
            print("___app.py / adauga::adauga.html: ____CONEXIUNE OK DB____")
            try:
                curs.callproc('adaugaAngajat',[numeAn, prenumeAn, functieeAn, dataAngajariiAn, telAn, emailAn, salariuAn])
                curs.close()

                print("___app.py / adauga::adauga.html: Angajat added successfully.")
                curs.close()
                return  redirect(url_for('getAngajati'))
            except Exception as e:
                print("ERROR___app.py / adauga::adauga.html: ____EROARE ADAUGARE____::", e)
                # print(traceback.print_exc())
        except Exception as e:
            print("ERROR___app.py / adauga::adauga.html: ____EROARE CONEXIUNE DB____")
            print("ERROR___app.py / adauga::adauga.html: ____EROARE CONEXIUNE DB____::",e)

        print("___app.py / adauga::adauga.html: ____doPost END")
Ejemplo n.º 8
0
def adaugaMaterial():
    if request.method == "GET":
        if session.get('username') is None:
            print("___app.py / adaugaMaterial::adaugaMaterial.html: Not logged in. Redirect to login.")
            return redirect(url_for('login'))
        if session['username']:
            print("___app.py / adaugaMaterial::adaugaMaterial.html: User %s logged in. Proceed to adaugaMaterial.html" % session.__getitem__('username'))
            curs = mysql.connection.cursor()
            query0 = 'SELECT Categorie FROM tblRaioane'
            curs.execute(query0)
            varianteCategorie = curs.fetchall()  # de trimis ca parametru
            query1 = 'SELECT Denumire FROM tblProducatori'
            curs.execute(query1)
            varianteProducatori = curs.fetchall() # de trimis ca parametru
            curs.close()
            print(varianteProducatori)
            print(varianteCategorie)
            return render_template('adaugaMaterial.html', categoriiMaterial=varianteCategorie,
                                   producatoriMaterial=varianteProducatori)

    if request.method == 'POST':
        print("___app.py / adaugaMaterial::adaugaMaterial.html: doPost STARTED")
        numeProducator         = request.form['numeP']
        categorie      = request.form['categorieM']
        denumire      = request.form['denumireM']
        unitati = request.form['unitatiM']
        pret           = request.form['pretM']
        garantie        = request.form['garantieM']

        try:
            curs = mysql.connection.cursor()

            try:
                query1 = 'SELECT idProducator FROM tblProducatori WHERE Denumire = %s'
                query2 ='SELECT idRaion FROM tblRaioane WHERE Categorie = %s'
                curs.execute(query1, [numeProducator])
                producator = curs.fetchone()
                idProducator = producator['idProducator']
                curs.execute(query2, [categorie])
                raion = curs.fetchone()
                idRaion = raion['idRaion']
                curs.callproc('adaugaMaterial', [idProducator, idRaion, denumire, unitati, pret,garantie])
                print("___app.py / adaugaMaterial::adaugaMaterial.html: Material added successfully.")
                curs.close()

                return redirect(url_for('getMateriale'))
            except Exception as e:
                print("ERROR___app.py / adaugaMaterial::adaugaMaterial.html: ____EROARE ADAUGARE____::", e)
                # print(traceback.print_exc())
        except Exception as e:
            print("ERROR___app.py / adaugaMaterial::adaugaMaterial.html: ____EROARE CONEXIUNE DB____")
            print("ERROR___app.py / adaugaMaterial::adaugaMaterial.html: ____EROARE CONEXIUNE DB____::",e)

        print("___app.py / adaugaMaterial::adaugaMaterial.html.html: ____doPost END")
Ejemplo n.º 9
0
def adaugaProducator():
    if request.method == "GET":
        if session.get('username') is None:
            print("___app.py / adaugaProducator::adaugaProducator.html: Not logged in. Redirect to login.")
            return redirect(url_for('login'))
        if session['username']:
            print("___app.py / adaugaProducator::adaugaProducator.html: User %s logged in. Proceed to adaugaProducator.html." % session.__getitem__('username'))
            curs = mysql.connection.cursor()
            curs.close()
            return render_template('adaugaProducator.html')

    if request.method == 'POST':
        denumireP  = request.form['denumire']
        sediuP     = request.form['sediu']
        telefonP   = request.form['telefon']
        emailP     = request.form['email']

        try:
            curs = mysql.connection.cursor()
            print("___app.py / adaugaProducator::adaugaProducator.html: ____CONEXIUNE OK DB____")
            try:
                curs.callproc('adaugaProducator',[denumireP,sediuP,telefonP,emailP])
                curs.close()

                print("___app.py / adaugaProducator::adaugaProducator.html: Producator added successfully.")
                curs.close()
                return  redirect(url_for('getProducatori'))
            except Exception as e:
                print("ERROR___app.py / adaugaProducator::adaugaProducator.html: ____EROARE ADAUGARE____::", e)
                # print(traceback.print_exc())
        except Exception as e:
            print("ERROR___app.py / adaugaProducator::adaugaProducator.html: ____EROARE CONEXIUNE DB____")
            print("ERROR___app.py / adaugaProducator::adaugaProducator.html: ____EROARE CONEXIUNE DB____::",e)

        print("___app.py / adaugaProducator::adaugaProducator.html: ____doPost END")