Python flask.session.clear() Examples
The following are 30
code examples of flask.session.clear().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.session
, or try the search function
.
Example #1
Source File: account.py From restpie3 with MIT License | 14 votes |
def build_session(user_obj, is_permanent=True): """On login+signup, builds the server-side session dict with the data we need. userid being the most important.""" assert user_obj assert user_obj.id # make sure session is empty session.clear() # fill with relevant data session['userid'] = user_obj.id session['role'] = user_obj.role # if you update user.role, update this too # remember session even over browser restarts? session.permanent = is_permanent # could also store ip + browser-agent to verify freshness # of the session: only allow most critical operations with a fresh # session
Example #2
Source File: login.py From easywall with GNU General Public License v3.0 | 11 votes |
def login_post(): """ the function handles the login post request and if all information are correct a session variable is set to store the login information """ utils = Webutils() hostname = platform.node().encode("utf-8") salt = hashlib.sha512(hostname).hexdigest() pw_hash = hashlib.sha512( str(salt + request.form['password']).encode("utf-8")).hexdigest() if request.form['username'] == utils.cfg.get_value( "WEB", "username") and pw_hash == utils.cfg.get_value( "WEB", "password"): session.clear() session['logged_in'] = True session['ip_address'] = request.remote_addr session.permanent = True return redirect("/") return login("Incorrect username or password.", "danger")
Example #3
Source File: app.py From 7Eleven-Python with GNU General Public License v3.0 | 8 votes |
def logout(): # The logout payload is an empty string but it is still needed payload = '""' tssa = functions.generateTssa(functions.BASE_URL + "account/logout", "POST", payload, session['accessToken']) headers = {'User-Agent':'Apache-HttpClient/UNAVAILABLE (java 1.4)', 'Authorization':'%s' % tssa, 'X-OsVersion':functions.OS_VERSION, 'X-OsName':'Android', 'X-DeviceID':session['DEVICE_ID'], 'X-VmobID':functions.des_encrypt_string(session['DEVICE_ID']), 'X-AppVersion':functions.APP_VERSION, 'X-DeviceSecret':session['deviceSecret'], 'Content-Type':'application/json; charset=utf-8'} response = requests.post(functions.BASE_URL + "account/logout", data=payload, headers=headers) # Clear all of the previously set session variables and then redirect to the index page session.clear() return redirect(url_for('index')) # The confirmation page for a manual lock in
Example #4
Source File: decorators.py From Ostrich with MIT License | 6 votes |
def user_session(func): @wraps(func) def wrapper(**kwargs): from app.models import Utils if Utils.getParam(request.args, 'session', default=None): user_data = session.get('_user', None) if user_data and user_data['is_admin']: session.clear() user_data = session.get('_user', None) kwargs['props'] = {'user': user_data, 'cdn': webapp.config['S3_HOST']+'website/', 'host': webapp.config['HOST']+'/' } return func(**kwargs) return wrapper
Example #5
Source File: test_decorators.py From quay with Apache License 2.0 | 6 votes |
def test_extract_namespace_repo_from_session_present(app): encountered = [] def somefunc(namespace, repository): encountered.append(namespace) encountered.append(repository) # Add the namespace and repository to the session. session.clear() session["namespace"] = "foo" session["repository"] = "bar" # Call the decorated method. extract_namespace_repo_from_session(somefunc)() assert encountered[0] == "foo" assert encountered[1] == "bar"
Example #6
Source File: auth.py From CTFd with Apache License 2.0 | 5 votes |
def logout_user(): session.clear()
Example #7
Source File: auth.py From zeus with Apache License 2.0 | 5 votes |
def get_redirect_target(clear=True, session=session) -> Optional[str]: if clear: session_target = session.pop("next", None) else: session_target = session.get("next") for target in request.values.get("next"), session_target: if not target: continue if is_safe_url(target): return target return None
Example #8
Source File: user.py From notifications-admin with MIT License | 5 votes |
def sign_out(self): session.clear() # Update the db so the server also knows the user is logged out. self.update(current_session_id=None) logout_user()
Example #9
Source File: index.py From marvin with BSD 3-Clause "New" or "Revised" License | 5 votes |
def clear_session(self): current_session.clear() return jsonify(result=dict(current_session))
Example #10
Source File: server.py From auth0-python-web-app with MIT License | 5 votes |
def logout(): session.clear() params = {'returnTo': url_for('home', _external=True), 'client_id': AUTH0_CLIENT_ID} return redirect(auth0.api_base_url + '/v2/logout?' + urlencode(params))
Example #11
Source File: userauth.py From confidant with Apache License 2.0 | 5 votes |
def clear_session(self): logger.info('Clearing flask session') session['user'] = {} session.clear()
Example #12
Source File: userauth.py From confidant with Apache License 2.0 | 5 votes |
def log_out(self): """ Initiate SAML SLO redirect. """ logger.info('Initiating SAML logout request') try: current_nameid = self._current_user_nameid() current_session_id = self._current_saml_session_id() except errors.UserUnknownError: # must be already logged out logger.warning('No SAML data in session. Cannot SLO log out') self.clear_session() return self.redirect_to_goodbye() auth = self._saml_auth() # check for SLO support if not auth.get_slo_url(): logger.warning('No SingleLogOut endpoint defined for IdP') self.clear_session() return self.redirect_to_goodbye() # TODO: decide whether to always clear the session here or not. Relying # on the IDP to redirect back to us hasn't been super reliable. self.clear_session() # redirect to SLO endpoint return flask.redirect(auth.logout(name_id=current_nameid, session_index=current_session_id))
Example #13
Source File: index.py From PowerDNS-Admin with MIT License | 5 votes |
def clear_session(): session.pop('user_id', None) session.pop('github_token', None) session.pop('google_token', None) session.pop('authentication_type', None) session.pop('remote_user', None) session.clear() logout_user()
Example #14
Source File: SessionPuzzle.py From skf-labs with GNU Affero General Public License v3.0 | 5 votes |
def logout(): session.clear() return redirect(url_for('login'))
Example #15
Source File: login.py From analytics-quarry-web with MIT License | 5 votes |
def logout(): session.clear() return redirect("/")
Example #16
Source File: api.py From elearning with MIT License | 5 votes |
def logout(): session.clear() return redirect('/')
Example #17
Source File: login.py From listenbrainz-server with GNU General Public License v2.0 | 5 votes |
def logout(): session.clear() logout_user() return redirect(url_for('index.index'))
Example #18
Source File: api_account.py From restpie3 with MIT License | 5 votes |
def logout(): """Logs out the user, clears the session.""" session.clear() return jsonify({}), 200
Example #19
Source File: app.py From spotipy with MIT License | 5 votes |
def sign_out(): session.clear() return redirect('/')
Example #20
Source File: notebook.py From Notebook with MIT License | 5 votes |
def delete_account(): user_id = session['user_id'] if not delete_usr(user_id): return jsonify({'resp': ''}) session.clear() return jsonify({'resp': ''})
Example #21
Source File: notebook.py From Notebook with MIT License | 5 votes |
def logout(): session.clear() return redirect(url_for('index'))
Example #22
Source File: login.py From acousticbrainz-server with GNU General Public License v2.0 | 5 votes |
def logout(): logout_user() session.clear() next = request.args.get('next') if next: return redirect(next) return redirect(url_for('index.index'))
Example #23
Source File: website.py From Ostrich with MIT License | 5 votes |
def signout(): session.clear() return jsonify(status=True)
Example #24
Source File: user.py From Titan with GNU Affero General Public License v3.0 | 5 votes |
def logout(): redir = session.get("redirect", None) if not redir: redir = request.args.get("redirect", None) session.clear() if redir: session['redirect'] = redir return redirect(session['redirect']) return redirect(url_for("index"))
Example #25
Source File: app.py From myflaskapp with MIT License | 5 votes |
def logout(): session.clear() flash('You are now logged out', 'success') return redirect(url_for('login')) # Dashboard
Example #26
Source File: app.py From Cloud-Native-Python with MIT License | 5 votes |
def clearsession(): # Clear the session session.clear() # Redirect the user to the main page return redirect(url_for('main'))
Example #27
Source File: user.py From picoCTF with MIT License | 5 votes |
def logout(): """Clear the session.""" session.clear()
Example #28
Source File: views.py From FXTest with MIT License | 5 votes |
def get(self): username = session.get("username") session.clear() logout_user() user = User.query.filter_by(username=username).first() user.is_login = False db.session.add(user) db.session.commit() return redirect(url_for('home.login', next=request.url))
Example #29
Source File: wrappers.py From cloud-inquisitor with Apache License 2.0 | 5 votes |
def __check_auth(self, view): headers = {x[0]: x[1] for x in request.headers} if 'Authorization' in headers: try: token = jwt.decode( headers['Authorization'], get_jwt_key_data() ) if token['auth_system'] != current_app.active_auth_system.name: self.log.error('Token is from another auth_system ({}) than the current one ({})'.format( token['auth_system'], current_app.active_auth_system.name )) return view.make_unauth_response() if has_access(session['user'], self.role): return self.log.error('User {} attempted to access page {} without permissions'.format( session['user'].username, request.path )) return view.make_unauth_response() except (jwt.DecodeError, jwt.ExpiredSignatureError) as ex: session.clear() view.log.info('Failed to decode signature or it had expired: {0}'.format(ex)) return view.make_unauth_response() session.clear() view.log.info('Failed to detect Authorization header') return view.make_unauth_response()
Example #30
Source File: __init__.py From cloud-inquisitor with Apache License 2.0 | 5 votes |
def get(self): def dscb(): session.clear() url = self.auth.process_slo(delete_session_cb=dscb) errors = self.auth.get_errors() if len(errors) == 0: if url: return self.auth.redirect_to(url) return redirect('/logout')