This commit is contained in:
Micik2 2018-12-11 20:57:16 +01:00
parent b83a43c5b9
commit d0dddce7dd
5 changed files with 219 additions and 58 deletions

96
app.py
View File

@ -11,6 +11,11 @@ from time import sleep
from flask_socketio import SocketIO
from flask_socketio import emit, join_room, leave_room
import smtplib
from oauth2client import file, client, tools
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
main = Blueprint('main', __name__)
@ -37,7 +42,7 @@ def indexChat():
"""Login form to enter a room."""
form = LoginForm()
if form.validate_on_submit():
session['name'] = session["user"] #form.name.data
session['name'] = session["user"].split('@')[0] #form.name.data
session['room'] = "Czat grupowy" #form.room.data
return redirect(url_for('.chat'))
elif request.method == 'GET':
@ -93,6 +98,8 @@ class LoginForm(Form):
faces_list = []
testing_face = 0
service = None
SCOPES = "https://www.googleapis.com/auth/calendar.events"
@socketio.on('message')
def handleMessage(msg):
@ -101,6 +108,12 @@ def handleMessage(msg):
@app.route("/")
def main():
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
return render_template('index.html', info="Witaj!")
@app.route("/indexENG")
@ -199,8 +212,11 @@ def validateLogin():
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_username, gmail_password)
session['user'] = gmail_username.split('@')[0]
return render_template('userHome.html', user=gmail_username.split('@')[0])
if "@gmail.com" not in gmail_username:
session['user'] = gmail_username + "@gmail.com" #.split('@')[0]
else:
session["user"] = gmail_username
return render_template('userHome.html', user=session['user'].split('@')[0], calendar_src="https://calendar.google.com/calendar/embed?src=" + session.get("user"))
except:
return render_template('error.html',error = 'Zły email lub hasło!')
@ -249,7 +265,7 @@ def validateLoginENG():
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_username, gmail_password)
session['user'] = gmail_username.split('@')[0]
session['user'] = gmail_username#.split('@')[0]
return render_template('userHomeENG.html', user=gmail_username.split('@')[0])
except:
return render_template('errorENG.html',error = 'Wrong email or password!')
@ -287,14 +303,14 @@ def validateLoginENG():
@app.route('/userHome')
def userHome():
if session.get('user'):
return render_template('userHome.html', user=session['user'])
return render_template('userHome.html', user=session['user'].split('@')[0], calendar_src="https://calendar.google.com/calendar/embed?src=" + session.get("user"))
else:
return render_template('error.html',error = 'Nieautoryzowany dostęp!')
@app.route('/userHomeENG')
def userHomeENG():
if session.get('user'):
return render_template('userHomeENG.html', user=session['user'])
return render_template('userHomeENG.html', user=session['user'].split('@')[0])
else:
return render_template('errorENG.html',error = 'Unauthorized access!')
@ -497,7 +513,7 @@ def signInWithFace():
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
return render_template('userHome.html', info="Zapisano twarz", user=session.get('user'))
return render_template('userHome.html', info="Zapisano twarz", user=session.get('user').split('@')[0], calendar_src="https://calendar.google.com/calendar/embed?src=" + session.get("user"))
@app.route('/signInWithFaceENG')
def signInWithFaceENG():
@ -563,10 +579,72 @@ def signInWithFaceENG():
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
return render_template('userHomeENG.html', info="A face has been saved", user=session.get('user'))
return render_template('userHomeENG.html', info="A face has been saved", user=session.get('user').split('@')[0])
@app.route('/addEvent', methods=['POST'])
def addEvent():
summary = request.form["inputSummary"]
location = request.form["inputLocation"]
description = request.form["inputDescription"]
description = request.form["inputDescription"]
description = request.form["inputDescription"]
start = request.form["inputStart"]
end = request.form["inputEnd"]
attendees = request.form["inputAttendees"].split(',')
processed_attendees = []
for attendee in attendees:
attendee = attendee.strip()
if "@gmail.com" not in attendee:
attendee += "@gmail.com"
processed_attendees.append({'email': attendee})
event = { 'summary': summary,
'location': location,
'description': description,
'start': {
'dateTime': start + ":00+01:00",
'timeZone': 'Europe/Warsaw'
},
'end': {
'dateTime': end + ":00+01:00",
'timeZone': 'Europe/Warsaw'
},
'attendees': processed_attendees
}
#credentials = ServiceAccountCredentials.from_json_keyfile_name(
# 'credentials.json',
# scopes="https://www.googleapis.com/auth/calendar.events")
#http = httplib2.Http()
#http = credentials.authorize(http)
#service = build("calendar", "v3", http=http)
#store = file.Storage('token.json')
#creds = store.get()
#if not creds or creds.invalid:
# flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
# creds = tools.run_flow(flow, store)
#service = build('calendar', 'v3', http=creds.authorize(Http()))
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', "https://www.googleapis.com/auth/calendar.events")
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
service.events().insert(calendarId='primary', body=event).execute()
return render_template('userHome.html', user=session['user'].split('@')[0], calendar_src="https://calendar.google.com/calendar/embed?src=" + session.get("user"))
@app.route('/toAddEvent')
def toAddEvent():
if session.get('user'):
return render_template('addEvent.html')
else:
return render_template('error.html',error = 'Nieautoryzowany dostęp!')
if __name__ == "__main__":
#app.run(host='0.0.0.0')
# Port: 5000
#socketio.run(app, debug=True)
socketio.run(app, host="0.0.0.0", ssl_context=("cert.pem", "key.pem"))
socketio.run(app, host="0.0.0.0")#, ssl_context=("cert.pem", "key.pem"))

1
credentials.json Normal file
View File

@ -0,0 +1 @@
{"installed":{"client_id":"566304981572-9hr3g1k77etvjovjr4qbordioblum93q.apps.googleusercontent.com","project_id":"my-project-1544556068455","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://www.googleapis.com/oauth2/v3/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"4ym9H4hS-IURN5BhxytXzb6J","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

78
templates/addEvent.html Normal file
View File

@ -0,0 +1,78 @@
<!DOCTYPE html>
<!--<html lang="en">-->
<html lang="pl-PL">
<head>
<meta charset="UTF-8">
<title>Python Flask App</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="signup.css">
<!-- <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"> -->
<link href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
<link href="../static/css/signup.css" rel="stylesheet">
<link rel="stylesheet" href="../static/css/calendar.css">
</head>
<body>
<div class="container">
<div class="header">
<nav>
<ul class="nav nav-pills pull-left">
<!--<form><input type="button" value="Back" onClick="history.go(-1);return true;"></form>-->
<!--<li role="presentation" class="active"><input type="button" value="Back" onClick="history.go(-1);return true;">
</li>-->
<!--<li role="presentation" class="active"><form action="http://google.com"><input type="button" value="Wstecz" onClick="history.go(-1);return true;"></form></li>-->
<!-- <li role="presentation" class="active"><a href="userHomeENG">ENG</a> -->
<!-- </li> -->
<li role="presentation" class="active"><a href="userHome">Wróć do strony domowej</a>
</li>
</ul>
<ul class="nav nav-pills pull-right">
<li role="presentation" class="active"><a href="/logout">Wyloguj</a>
</li>
</ul>
</nav>
<h3 class="text-muted"><center>Python Flask</center></h3>
</div>
<div class="jumbotron" style="height: 550px;">
<h2>Dodaj nowe wydarzenie do kalendarza</h2>
<div class="col-xs-12">
<form class="form-signin" action="/addEvent" method="post">
Nazwa:
<input type="text" name="inputSummary" id="inputSummary" class="form-control" placeholder="Wpisz nazwę" required autofocus/>
Lokalizacja:
<input type="text" name="inputLocation" id="inputLocation" class="form-control" placeholder="Wpisz lokalizację" required/>
Opis:
<input type="text" name="inputDescription" id="inputDescription" class="form-control" placeholder="Wpisz opis" required/>
Termin rozpoczęcia:
<input type="datetime-local" name="inputStart" id="inputStart" class="form-control" placeholder="Wpisz termin" required/>
Termin zakończenia:
<input type="datetime-local" name="inputEnd" id="inputEnd" class="form-control" placeholder="Wpisz termin" required/>
Uczestnicy:
<textarea type="text" name="inputAttendees" id="inputAttendees" class="form-control" placeholder="Podaj uczestników (ich adresy gmailowe) rozdzielając ich przecinkiem" required></textarea>
<div>
<input type="submit" value="Dodaj" style="margin-top: 5px; float: right;" class="btn btn-success"/></div>
</form>
</div>
</div>
<footer class="footer">
<p>&copy; UAM 2018</p>
</footer>
</div>
</body>
</html>

View File

@ -129,58 +129,61 @@ body {font-family: Verdana, sans-serif;}
<div class="jumbotron" style="height: 550px;">
<h1>Witaj w domu {{user}}!</h1>
<div class="col-xs-8">
<div class="month">
<ul>
<li>Listopad<br><span style="font-size:18px">2018</span></li>
</ul>
</div>
<ul class="weekdays">
<li>Cz</li>
<li>Pi</li>
<li>So</li>
<li>Ni</li>
<li>Po</li>
<li>Wt</li>
<li>Śr</li>
</ul>
<ul class="days">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
<li>21</li>
<li>22</li>
<li>23</li>
<li>24</li>
<li>25</li>
<li>26</li>
<li>27</li>
<li><span class="active">28</span></li>
<li>29</li>
<li>30</li>
</ul>
<!-- <iframe src="https://calendar.google.com/calendar/embed?src=micik220@gmail.com" style="border-width:0" width="500" height="350" frameborder="0" scrolling="no"></iframe> -->
<iframe src="{{ calendar_src }}" style="border-width:0" width="500" height="350" frameborder="0" scrolling="no"></iframe>
<!-- <div class="month"> -->
<!-- <ul> -->
<!-- <li>Listopad<br><span style="font-size:18px">2018</span></li> -->
<!-- </ul> -->
<!-- </div> -->
<!-- <ul class="weekdays"> -->
<!-- <li>Cz</li> -->
<!-- <li>Pi</li> -->
<!-- <li>So</li> -->
<!-- <li>Ni</li> -->
<!-- <li>Po</li> -->
<!-- <li>Wt</li> -->
<!-- <li>Śr</li> -->
<!-- </ul> -->
<!-- <ul class="days"> -->
<!-- <li>1</li> -->
<!-- <li>2</li> -->
<!-- <li>3</li> -->
<!-- <li>4</li> -->
<!-- <li>5</li> -->
<!-- <li>6</li> -->
<!-- <li>7</li> -->
<!-- <li>8</li> -->
<!-- <li>9</li> -->
<!-- <li>10</li> -->
<!-- <li>11</li> -->
<!-- <li>12</li> -->
<!-- <li>13</li> -->
<!-- <li>14</li> -->
<!-- <li>15</li> -->
<!-- <li>16</li> -->
<!-- <li>17</li> -->
<!-- <li>18</li> -->
<!-- <li>19</li> -->
<!-- <li>20</li> -->
<!-- <li>21</li> -->
<!-- <li>22</li> -->
<!-- <li>23</li> -->
<!-- <li>24</li> -->
<!-- <li>25</li> -->
<!-- <li>26</li> -->
<!-- <li>27</li> -->
<!-- <li><span class="active">28</span></li> -->
<!-- <li>29</li> -->
<!-- <li>30</li> -->
<!-- </ul> -->
</div>
<p class="lead"></p>
<p>
<a class="btn btn-lg btn-success" href="#" role="button">Moje zajęcia</a>
<a class="btn btn-lg btn-success" href="#" role="button">Test</a>
<a class="btn btn-lg btn-success" href="#" role="button">Wyniki</a>
<!-- <a class="btn btn-lg btn-success" href="#" role="button">Moje zajęcia</a> -->
<!-- <a class="btn btn-lg btn-success" href="#" role="button">Test</a> -->
<!-- <a class="btn btn-lg btn-success" href="#" role="button">Wyniki</a> -->
<a class="btn btn-lg btn-success" href="toAddEvent" role="button">Dodaj wydarzenie</a>
<a class="btn btn-lg btn-success" href="chat" role="button" style="margin-top:5px;">Czat grupowy</a>
<!-- <form action="ch"> -->
<!-- <input type="submit" value="Wejdź na czat grupowy" /> -->

1
token.json Normal file
View File

@ -0,0 +1 @@
{"access_token": "ya29.GltvBjJUQJa7byeuf8v3JCkjwtevLdEkDEAxeXytM542WScD1GrhdCU7MI7lgx74qV3b_Q4S5D0nAK8PQnqEC9yiUsYt16-vXHZ0oyZd2I6jlQNtmr0yma8UkSpn", "client_id": "566304981572-9hr3g1k77etvjovjr4qbordioblum93q.apps.googleusercontent.com", "client_secret": "4ym9H4hS-IURN5BhxytXzb6J", "refresh_token": "1/me1ZoXCKxkQuOW00ZUc0pNsFCQ9bjVnpY7SuFsetBv7DiONcLVMEwgcbw830I542", "token_expiry": "2018-12-11T20:44:33Z", "token_uri": "https://www.googleapis.com/oauth2/v3/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.GltvBjJUQJa7byeuf8v3JCkjwtevLdEkDEAxeXytM542WScD1GrhdCU7MI7lgx74qV3b_Q4S5D0nAK8PQnqEC9yiUsYt16-vXHZ0oyZd2I6jlQNtmr0yma8UkSpn", "expires_in": 3600, "refresh_token": "1/me1ZoXCKxkQuOW00ZUc0pNsFCQ9bjVnpY7SuFsetBv7DiONcLVMEwgcbw830I542", "scope": "https://www.googleapis.com/auth/calendar.events", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/calendar.events"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}