def delete_collection(collection, keep_metadata=False, sync=False): log.warning("DFAAAAAAAAAAAAAAAAAAAAAA") deleted_at = collection.deleted_at or datetime.utcnow() if not keep_metadata: log.warning("am i getting deleted..") collection.delete(deleted_at=deleted_at) else: log.warning("WHHHHYYY") db.session.commit() if not keep_metadata: index.delete_collection(collection.id, sync=True) Authz.flush() refresh_collection(collection.id)
def password_login(): """ Provides email and password authentication """ # require(settings.PASSWORD_LOGIN) request_data = request.get_json() email = request_data.get('email') password = request_data.get('password') log.warning("THE REQUEST DATA LOOKS LIKE {}".format(request_data)) require(settings.PASSWORD_LOGIN) data = request.get_json() role = Role.login(data.get("email"), data.get("password")) #log.warning("LOGGING IN FROM THE SESSIONS API: {}".format(role.email)) if role is None: raise BadRequest("Invalid user or password") # role.touch() db.session.commit() # update_role(role) authz = Authz.from_role(role) return jsonify({"status": "ok", "token": authz.to_token()})
def get_role_channels(role): """ Generate the set of notification channels that the current user4 should listen to """ key = cache.object_key(Role, role.id, "channels") channels = cache.get_list(key) if len(channels): return channels channels = [GLOBAL] if role.is_actor: authz = Authz.from_role(role) for role_id in authz.roles: channels.append(cha)
def create(): data = request.get_json() email = "*****@*****.**" role = Role.by_email(email) if role is not None: return jsonify( { "status": "error", "message": "Email is already registered" }, status=409) role = create_user(email, data.get("name"), data.get("password")) request.authz = Authz.from_role(role) return jsonify({"status": "ok"})
def oauth_callback(): require(settings.OAUTH) err = Unauthorized("Authentication has failed.") state = cache.get_complex(_oauth_session(request.args.get("state"))) if state is None: raise err try: oauth.provider.framework.set_session_data(request, "state", state.get("state")) uri = state.get("redirect_uri") oauth_token = oauth.provider.authorize_access_token(redirect_uri=uri) except AuthlibBaseError as err: log.warning("Failed OAuth: %r", err) raise err if oauth_token is None or isinstance(oauth_token, AuthlibBaseError): log.warning("Failed OAuth: %r", oauth_token) raise err role = handle_oauth(oauth.provider, oauth_token) if role is None: raise err # Determine session duration based on OAuth settings expire = oauth_token.get("expires_in", Authz.EXPIRE) expire = oauth_token.get("refresh_expires_in", expire) db.session.commit() update_role(role) log.debug("Logged in: %r", role) request.authz = Authz.from_role(role, expire=expire) token = request.authz.to_token() id_token = oauth_token.get("id_token") if id_token is not None: cache.set(_token_session(token), id_token, expires=expire) next_path = get_url_path(state.get("next_url")) next_url = ui_url("oauth", next=next_path) next_url = "%s#token=%s" % (next_url, token) session.clear() return redirect(next_url)
def refresh_role(role, sync=False): Authz.flush_role(role) cache.kv.delete( cache.object_key(Role, role.id), cache.object_key(Role, role.id, "channels") )
def update_collection(collection, sync=False): Authz.flush() refresh_collection(collection.id) return index.index_collection(collection, sync=sync)