From 99ab046a756f4c1bf359be9e18f687412c451049 Mon Sep 17 00:00:00 2001 From: Micik2 Date: Wed, 28 Nov 2018 01:38:57 +0100 Subject: [PATCH] WU-14 --- Python/app.py | 317 ++++++++++++++++++++++++++---- Python/static/calendar.css | 73 +++++++ Python/templates/errorENG.html | 51 +++++ Python/templates/index.html | 4 + Python/templates/indexENG.html | 55 ++++++ Python/templates/signin.html | 8 +- Python/templates/signinENG.html | 60 ++++++ Python/templates/signup.html | 2 + Python/templates/signupENG.html | 82 ++++++++ Python/templates/userHome.html | 200 ++++++++++++++++++- Python/templates/userHomeENG.html | 239 ++++++++++++++++++++++ 11 files changed, 1041 insertions(+), 50 deletions(-) create mode 100644 Python/static/calendar.css create mode 100644 Python/templates/errorENG.html create mode 100644 Python/templates/indexENG.html create mode 100644 Python/templates/signinENG.html create mode 100644 Python/templates/signupENG.html create mode 100644 Python/templates/userHomeENG.html diff --git a/Python/app.py b/Python/app.py index 1ba539d..6d88796 100644 --- a/Python/app.py +++ b/Python/app.py @@ -45,13 +45,25 @@ testing_face = 0 def main(): return render_template('index.html', info="Witaj!") +@app.route("/indexENG") +def indexENG(): + return render_template('indexENG.html', info="Hello!") + @app.route('/showSignUp') def showSignUp(): return render_template('signup.html') + +@app.route('/showSignUpENG') +def showSignUpENG(): + return render_template('signupENG.html') @app.route('/showSignIn') def showSignIn(): return render_template('signin.html') + +@app.route('/showSignInENG') +def showSignInENG(): + return render_template('signinENG.html') @app.route('/signUp',methods=['POST','GET']) def signUp(): @@ -93,6 +105,46 @@ def signUp(): cursor.close() conn.close() +@app.route('/signUpENG',methods=['POST','GET']) +def signUpENG(): + try: + _login = request.form['inputLogin'] + _password = request.form['inputPassword'] + + # validate the received values + if _login and _password: + + # All Good, let's call MySQL + + conn = mysql.connect() + cursor = conn.cursor() + #_hashed_password = generate_password_hash(_password) + #cursor.callproc('rejestracja4',(_name,_email,_hashed_password)) + #cursor.callproc('rejestracja4',(_name,_email,_password)) + + #cursor.callproc('dodajUzytkownika', (_email, _password, _type, _organization, _name, _surname)) + args = (_login, _password) + cursor.execute("INSERT into Users(login, password) values(%s, %s)", args) + data = cursor.fetchall() + + if len(data) is 0: + conn.commit() + #return redirect("index.html") + #return redirect("/") + return render_template("indexENG.html", info="Successfully registered!") + #return json.dumps({'message':'User created successfully !'}) + else: + return render_template("errorENG.html", error="The user already exists!") + #return json.dumps({'error':str(data[0])}) + else: + return json.dumps({'html':'Enter the required fields'}) + + #except Exception as e: + # return json.dumps({'error':str(e)}) + finally: + cursor.close() + conn.close() + @app.route('/validateLogin',methods=['POST']) def validateLogin(): try: @@ -112,7 +164,8 @@ def validateLogin(): #if str(data[0][3]) == _password: if str(data[0][1]) == _password: session['user'] = data[0][0] - return redirect('/userHome') + #return redirect('/userHome', user=session['user']) + return render_template('userHome.html', user=session['user']) else: return render_template('error.html',error = 'Zly email lub haslo!') else: @@ -123,52 +176,63 @@ def validateLogin(): finally: cursor.close() con.close() + +@app.route('/validateLoginENG',methods=['POST']) +def validateLoginENG(): + try: + _username = request.form['inputLogin'] + _password = request.form['inputPassword'] + + con = mysql.connect() + cursor = con.cursor() + #cursor.callproc('logowanie',(_username,)) + args = (_username, _password) + query = "SELECT * from Users where login = %s and password = %s" + cursor.execute(query, args) + data = cursor.fetchall() + + if len(data) > 0: + #if check_password_hash(str(data[0][3]),_password): + #if str(data[0][3]) == _password: + if str(data[0][1]) == _password: + session['user'] = data[0][0] + #return redirect('/userHomeENG', user=session['user']) + return render_template('userHomeENG.html', user=session['user']) + else: + return render_template('errorENG.html',error = 'Wrong email or password!') + else: + return render_template('errorENG.html',error = 'Wrong email or password!') + + except Exception as e: + return render_template('errorENG.html', error = str(e)) + finally: + cursor.close() + con.close() + @app.route('/userHome') def userHome(): if session.get('user'): - return render_template('userHome.html') + return render_template('userHome.html', user=session['user']) else: return render_template('error.html',error = 'Nieautoryzowany dostep!') + +@app.route('/userHomeENG') +def userHomeENG(): + if session.get('user'): + return render_template('userHomeENG.html', user=session['user']) + else: + return render_template('errorENG.html',error = 'Unauthorized access!') @app.route('/logout') def logout(): session.pop('user',None) return redirect('/') - -@app.route('/newSheet', methods=['POST','GET']) -def newSheet(): - try: - _sheet_name = request.form['inputSheetName'] - _number_items = request.form['inputItems'] - _number_operators = request.form['inputOperators'] - _number_chars = request.form['inputChars'] - _number_trials = request.form['inputTrials'] - - if _sheet_name and _number_items and _number_operators and _number_chars and _number_trials: - conn = mysql.connect() - cursor = conn.cursor() - cursor.callproc('nowyArkusz',(_sheet_name, _number_items,_number_operators,_number_chars, _number_trials)) - data = cursor.fetchall() - - if len(data) is 0: - conn.commit() - return redirect('/sheet') - #return json.dumps({'message':'Arkusz stworzono poprawnie!'}) - else: - return json.dumps({'error':str(data[0])}) - else: - return json.dumps({'html':'Enter the required fields'}) - except Exception as e: - return json.dumps({'error':str(e)}) - finally: - cursor.close() - conn.close() - #return render_template('newSheet.html') - -@app.route('/sheet', methods=['POST']) -def sheet(): - return render_template('sheet.html') + +@app.route('/logoutENG') +def logoutENG(): + session.pop('user',None) + return redirect('/indexENG') @app.route('/signUpWithFace') def signUpWithFace(): @@ -277,6 +341,113 @@ def signUpWithFace(): ''' #return render_template('error.html', error="Nie wykryto twarzy!") +@app.route('/signUpWithFaceENG') +def signUpWithFaceENG(): + cascPath = "haarcascade_frontalface_default.xml" + faceCascade = cv2.CascadeClassifier(cascPath) + log.basicConfig(filename='webcam.log',level=log.INFO) + + video_capture = cv2.VideoCapture(0) + anterior = 0 + faces = None + #testing_face = 0 + #faces_list = [] + i = 0 + + while True: + if not video_capture.isOpened(): + print('Unable to load camera.') + sleep(5) + pass + + # Capture frame-by-frame + ret, frame = video_capture.read() + + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + + faces = faceCascade.detectMultiScale( + gray, + scaleFactor=1.1, + minNeighbors=5, + minSize=(30, 30) + ) + + # Draw a rectangle around the faces + for (x, y, w, h) in faces: + cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) + + if anterior != len(faces): + anterior = len(faces) + log.info("faces: "+str(len(faces))+" at "+str(dt.datetime.now())) + + + # Display the resulting frame + cv2.imshow('Video', frame) + + + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + # Display the resulting frame + cv2.imshow('Video', frame) + #break + #face_list.append() + #print (type(faces)) + #print (len(faces)) + + #print (type(faces[0])) + #print (type(faces[0][0])) + + #if testing_face == faces: + # break + + #if type(faces) == "numpy.ndarray" or type(faces) == "ndarray": + #if not isinstance(faces, types.TupleType): + if type(faces) is not tuple: + i += 1 + face = 0 + for f in faces[0]: + face += f + faces_list.append(face) + if i == 5: + break + # faces_list.append(faces) + # i += 1 + # if i == 5: + # break + + ''' + face = 0 + i += 1 + for id in faces[0]: + face += id + if i == 5: + break + if 825 == face: + video_capture.release() + cv2.destroyAllWindows() + return render_template('index.html') + print (face) + ''' + #return render_template("index.html") + + #print (faces) + + # When everything is done, release the capture + video_capture.release() + cv2.destroyAllWindows() + print (faces_list) + return render_template('indexENG.html', info="A face has been saved") + ''' + face = 0 + for id in faces[0]: + face += id + print (id) + #if face + print (face) + ''' + #return render_template('error.html', error="Nie wykryto twarzy!") + @app.route('/signInWithFace') def signInWithFace(): cascPath = "haarcascade_frontalface_default.xml" @@ -347,7 +518,79 @@ def signInWithFace(): video_capture.release() cv2.destroyAllWindows() #print (faces_list) - return render_template('userHome.html', info="Zapisano twarz") + return render_template('userHome.html', info="Zapisano twarz", user=session.get('user')) + +@app.route('/signInWithFaceENG') +def signInWithFaceENG(): + cascPath = "haarcascade_frontalface_default.xml" + faceCascade = cv2.CascadeClassifier(cascPath) + log.basicConfig(filename='webcam.log',level=log.INFO) + + video_capture = cv2.VideoCapture(0) + anterior = 0 + faces = None + testing_face = 825 + #faces_list = [] + i = 0 + + while True: + if not video_capture.isOpened(): + print('Unable to load camera.') + sleep(5) + pass + + # Capture frame-by-frame + ret, frame = video_capture.read() + + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + + faces = faceCascade.detectMultiScale( + gray, + scaleFactor=1.1, + minNeighbors=5, + minSize=(30, 30) + ) + + # Draw a rectangle around the faces + for (x, y, w, h) in faces: + cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) + + if anterior != len(faces): + anterior = len(faces) + log.info("faces: "+str(len(faces))+" at "+str(dt.datetime.now())) + + + # Display the resulting frame + cv2.imshow('Video', frame) + + + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + # Display the resulting frame + cv2.imshow('Video', frame) + + #print (faces_list) + if type(faces) is not tuple: + face = 0 + i += 1 + for f in faces[0]: + face += f + if face in faces_list: + break + + # print (faces) + # if faces in faces_list: + # break + elif i == 20: + return render_template("errorENG.html", error="Lack of access!") + + + # When everything is done, release the capture + video_capture.release() + cv2.destroyAllWindows() + #print (faces_list) + return render_template('userHomeENG.html', info="A face has been saved", user=session.get('user')) if __name__ == "__main__": #app.run(port=5002) diff --git a/Python/static/calendar.css b/Python/static/calendar.css new file mode 100644 index 0000000..6dd305d --- /dev/null +++ b/Python/static/calendar.css @@ -0,0 +1,73 @@ +ul {list-style-type: none;} +body {font-family: Verdana, sans-serif;} + +/* Month header */ +.month { + /*padding: 70px 25px;*/ + width: 100%; + background: #1abc9c; + text-align: center; +} + +/* Month list */ +.month ul { + margin: 0; + padding: 0; +} + +.month ul li { + color: white; + font-size: 20px; + text-transform: uppercase; + letter-spacing: 3px; +} + +/* Previous button inside month header */ +.month .prev { + float: left; + padding-top: 10px; +} + +/* Next button */ +.month .next { + float: right; + padding-top: 10px; +} + +/* Weekdays (Mon-Sun) */ +.weekdays { + margin: 0; + padding: 10px 0; + background-color:#ddd; +} + +.weekdays li { + display: inline-block; + width: 13.6%; + color: #666; + text-align: center; +} + +/* Days (1-30) */ +.days { + padding: 10px 0; + background: cyan; + margin: 0; +} + +.days li { + list-style-type: none; + display: inline-block; + width: 13.6%; + text-align: center; + margin-bottom: 5px; + font-size:12px; + color: #777; +} + +/* Highlight the "current" day */ +.days li .active { + padding: 5px; + background: #1abc9c; + color: white !important +} \ No newline at end of file diff --git a/Python/templates/errorENG.html b/Python/templates/errorENG.html new file mode 100644 index 0000000..422bcd3 --- /dev/null +++ b/Python/templates/errorENG.html @@ -0,0 +1,51 @@ + + + + + + Unauthorized Access:: Python Flask App + + + + + + + + + + + + +
+
+ +

Python Flask

+
+ +
+

{{error}}

+
+ + + +
+

© UAM 2018

+
+ +
+ + + \ No newline at end of file diff --git a/Python/templates/index.html b/Python/templates/index.html index b23e410..a00b550 100644 --- a/Python/templates/index.html +++ b/Python/templates/index.html @@ -22,6 +22,10 @@