def logout(): token = google_bp.token["access_token"] google.post("https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) del google_bp.token session.clear() return "Logged out"
def logout(): token = blueprint.token['access_token'] google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"} ) session.clear() return redirect(url_for('core.index'))
def logout(): if not google.authorized and GOOGLE_LOGIN: return redirect(url_for("google.login")) token = blueprint.token['access_token'] logout_user() session.clear() google.post("https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) del blueprint.token return redirect(url_for('google.login'))
def add_calendar(summary, std_email): """Add a calendar to the database using a student_email and a calendar name (summary) as parameters. Args: summary (str): a string of the calendar name std_email (str): a string of the calendar student email. Returns: JSON: Reponse from the calendar API of the calendar creation status. """ cal_record = Calendar.query.filter_by(summary=summary).first() if cal_record is None: calendar__ = {'summary': summary, 'timeZone': 'Africa/Algiers'} resp = google.post("/calendar/v3/calendars", json=calendar__) if resp.status_code == 200: calendar_id = resp.json()["id"] else: print(resp.json()) calendar_id = None if calendar_id is not None: cal_rec = Calendar(calendar_id_google=calendar_id, summary=summary, std_email=std_email) db.session.add(cal_rec) else: print(cal_record) db.session.commit() if calendar_id: return jsonify(resp.json()), 200 else: return jsonify({"status": "failed"}), 200
def logout(): retrieve_user() if not google.authorized: return render_template('index.html') if 'username' in session: del session['username'] if 'template' in session: del session['template'] if hasattr(current_app.blueprints, 'google'): token = current_app.blueprints['google'].token['access_token'] resp = google.post( 'https://accounts.google.com/o/oauth2/revoke', params={'token': token}, headers={'Content-Type": "application/x-www-form-urlencoded'}, ) assert resp.ok, resp.text # FIXME del current_app.blueprints['google'].token['access_token'] else: print('Missing attribute google') session.clear() # oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) # Missing required parameter: refresh_token # FIXME what if token empty if 'username' in session: return render_template('index.html', name=session['template']) else: return render_template('index.html')
def logout(): token = blueprint.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) assert resp.ok, resp.text return render_template("welcome.html")
def google_logout(): token = google_bp.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"} ) #assert resp.ok, resp.text del google_bp.token # Delete
def logout(): token = current_app.blueprints["google"].token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) assert resp.ok, resp.text logout_user() # Delete Flask-Login's session cookie del blueprint.token # Delete OAuth token from storage return redirect(url_for('home'))
def logout(): token = current_app.blueprints["google"].token["access_token"] resp = google.post( "https://oauth2.googleapis.com/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) if not resp.ok: print(resp.text) del blueprint.token # Delete OAuth token return "<h1>Logged Out</h1>"
def calendar_add(): """Adds a calendar to the database according to the infos in POST data.\ Also creates the calendar in google calendar service if no google_calendar_id is present in POST data. """ calendar_name = request.form["calendar_name"] std_email = request.form["std_email"] google_calendar_id = request.form["google_calendar_id"] if check_google_calendar_id(google_calendar_id): # Add the google calendar directly to the local DB (Assume that Calendar has been already created) cal_obj = Calendar(summary=calendar_name, std_email=std_email, calendar_id_google=google_calendar_id) try: db.session.add(cal_obj) db.session.commit() except Exception: flash(('Could not add calendar {} to google calendar'.format( calendar_name)), category="error") return redirect(url_for("get_calendars")) return redirect(url_for("get_calendars")) else: # Creating a google calendar and receiving the gcal ID from Google cal_record = Calendar.query.filter_by(summary=calendar_name).first() if cal_record is None: calendar__ = { 'summary': calendar_name, 'timeZone': 'Africa/Algiers' } resp = google.post("/calendar/v3/calendars", json=calendar__) if resp.status_code == 200: if "id" in resp.json().keys(): calendar_id = resp.json()["id"] calendar_obj = Calendar(calendar_id_google=calendar_id, summary=calendar_name, std_email=std_email) db.session.add(calendar_obj) db.session.commit() flash(('Added calendar {} to google calendar'.format( calendar_name)), category="success") return redirect(url_for("get_calendars")) else: flash(("Invalid response from calendar api"), category="danger") return redirect(url_for('get_calendars')), 302 else: flash(("Calendar API returned a non 200 response"), category="danger") return redirect(url_for('get_calendars')), 302 else: flash(("Calendar {} already found in application database".format( calendar_name)), category="info") return redirect(url_for('get_calendars')), 302
def logout(): token = blueprint.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) if resp.ok: return "Logged out.", 200 else: return "There was a problem logging out :(", 500
def sign_out(): if 'userid' in session: token = google_bp.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) del google_bp.token session.pop('userid', None) session.pop("userid", None) return redirect(url_for("login"))
def new_calendar(calendar_name): if google.authorized: calendar__ = {'summary': calendar_name, 'timeZone': 'Africa/Algiers'} resp = google.post("/calendar/v3/calendars", json=calendar__) if resp.status_code == 200: return resp.json()["id"] else: print(resp.json()) return None else: return None
def logout(): if 'username' in session: if google.authorized: token = google_bp.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"} ) del google_bp.token session.pop('username') return redirect(url_for('index'))
def logout(): """ logout user and clear google access_token if exist """ if google.authorized: token = google_blueprint.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) logout_user() return redirect(url_for('main.home')) else: logout_user() return redirect(url_for('main.home'))
def logout(): if not current_user.is_authenticated: return redirect(url_for('google.login')) token = blueprint.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": "ya29.Glx0BkOLfor79Qg6kmNTIUs3Hnv61Zs6bA6xaW17jJmZiui3tm5QybewYpGRAUp3EBkePWI7OMeHJCTXjde1egQiwzvGBN8DVUZC7wGnWklk2zLPcDFMmVUFZTA7fA"}, headers={"Content-Type": "application/x-www-form-urlencoded"} ) logout_user() flash('You have successfully logged out of your account') return redirect(url_for('index'))
def import_calendars(): """Imports calendars from a json file returned by calendar api. """ if request.method == "GET": return render_template('calendars_import.html.j2', title='Import Calendars') elif request.method == "POST": if 'file' not in request.files: flash(("No file part"), category='danger') return redirect(request.url) file = request.files['file'] if file.filename == "": flash("No file selected for uploading", category='danger') return redirect(request.url) added_calendars = 1 # number of added calendars if file and allowed_file(file.filename): filename = secure_filename(file.filename) for line in file.readlines(): line = line.decode().strip().split(",") cal_record = Calendar.query.filter_by(summary=line[0]).first() print(cal_record) if cal_record is None: calendar__ = { 'summary': line[0], 'timeZone': 'Africa/Algiers' } resp = google.post("/calendar/v3/calendars", json=calendar__) if resp.status_code == 200: calendar_id = resp.json()["id"] else: print(resp.json()) calendar_id = None # ? I dont know if this is necessary, but you may be blocked by google if you initiate too many calendar # ? creation requests. sleep(5) if calendar_id is not None: cal_rec = Calendar(calendar_id_google=calendar_id, summary=line[0], std_email=line[1].replace('"', '')) db.session.add(cal_rec) added_calendars += 1 db.session.commit() flash(("Added {} calendars to google calendar from file {}".format( added_calendars, filename)), category="success") return redirect(request.url), 302 else: flash(("[ERROR] File is not allowed"), category="danger") return render_template('calendars_import.html.j2'), 200
def de_auth_google(): try: token = g_blueprint.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) if resp.ok: del g_blueprint.token except TypeError: pass # no token for manual login people except TokenExpiredError: # caused by lack of offline=True in config, may exist for some still del g_blueprint.token except InvalidClientError: # caused by lack of offline=True in config, may exist for some still del g_blueprint.token
def logout(): try: token = current_app.blueprints['google'].token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) assert resp.ok, resp.text logout_user() session.clear() return redirect(url_for('index')) except Exception: logout_user() session.clear() return redirect(url_for('index'))
def logout(): #delete google tocken try: token = google_Oauth.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) assert resp.ok, resp.text logout_user() # Delete Flask-Login's session cookie del blueprint.token # Delete OAuth token from storage except: pass logout_user() flash('You logged out!') return redirect(url_for('login'))
def logout(): # Logs out the current user if 'username' in login_session: token = google_blueprint.token["access_token"] resp = google.post( "https://accounts.google.com/o/oauth2/revoke", params={"token": token}, headers={"Content-Type": "application/x-www-form-urlencoded"}) assert resp.ok, resp.text del google_blueprint.token del login_session['username'] del login_session['email'] del login_session['picture'] del login_session['user_id'] flash("You have been successfully logged out!") return redirect(url_for('catList')) else: flash("You were not logged in!") return redirect(url_for('catList'))
def new_calendar(calendar_name): """Creates a new calendar in the google calendar service, using calendar API Args: calendar_name (str): A string of the calendar name to be created. Returns: JSON: returns a JSON reponse from the calendar API, returns None in case of error. """ if google.authorized: calendar__ = {'summary': calendar_name, 'timeZone': 'Africa/Algiers'} resp = google.post("/calendar/v3/calendars", json=calendar__) if resp.status_code == 200: return resp.json()["id"] else: print(resp.json()) return None else: return None