bottle.request.get_cookie - python examples

Here are the examples of the python api bottle.request.get_cookie taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

16 Examples 7

3 View Complete Implementation : youtube-dl-server.py
Copyright MIT License
Author : hyeonsangjeon
@get('/youtube-dl')
def dl_queue_list():
    with open('Auth.json') as data_file:
        data = json.load(data_file)

    userNm = request.get_cookie("account", secret="34y823423b23b4234#$@$@#be")
    print("CHK : ", userNm)

    if (userNm == data["MY_ID"]):
        return template("./static/template/index.tpl", userNm=userNm)
    else:
        print("no cookie or fail login")
        redirect("/")

3 View Complete Implementation : handler_util.py
Copyright Apache License 2.0
Author : icfpc2016
def get_xsrf_token():
    """Returns the XSRF token for the current client.

    Returns:
        XSRF token string, or None if XSRF token is not astigned to the client
        yet.
    """
    return bottle.request.get_cookie(
        _XSRF_TOKEN_COOKIE, secret=_get_session_cookie_secret())

3 View Complete Implementation : bottlesession.py
Copyright MIT License
Author : Jwink3101
    def get_session(self):
        #  get existing or create new session identifier
        sessionid = bottle.request.get_cookie('sessionid')
        if not sessionid:
            sessionid = self.allocate_new_session_id()
            bottle.response.set_cookie(
                'sessionid', sessionid, path='/',
                expires=(int(time.time()) + self.cookie_expires))

        #  load existing or create new session
        data = self.load(sessionid)
        if not data:
            data = {'sessionid': sessionid, 'valid': False}
            self.save(data)

        return data

3 View Complete Implementation : bottlesession.py
Copyright MIT License
Author : Jwink3101
    def load(self, sessionid):
        cookie = bottle.request.get_cookie(
            self.cookie_name,
            secret=self.secret)
        if cookie is None:
            return {}
        return pickle.loads(cookie)

3 View Complete Implementation : main.py
Copyright GNU Lesser General Public License v2.1
Author : knro
@app.route('/')
def main_form():
    """Main page"""
    global saved_profile
    drivers = collection.get_families()

    if not saved_profile:
        saved_profile = request.get_cookie('indiserver_profile') or 'Simulators'

    profiles = db.get_profiles()
    hostname = socket.gethostname()
    return template(os.path.join(views_path, 'form.tpl'), profiles=profiles,
                    drivers=drivers, saved_profile=saved_profile,
                    hostname=hostname)

3 View Complete Implementation : main.py
Copyright GNU Lesser General Public License v2.1
Author : knro
@app.post('/api/server/stop')
def stop_server():
    """Stop INDI Server"""
    indi_server.stop()

    global active_profile
    active_profile = ""

    # If there is saved_profile already let's try to reset it
    global saved_profile
    if saved_profile:
        saved_profile = request.get_cookie("indiserver_profile") or "Simulators"

3 View Complete Implementation : app.py
Copyright MIT License
Author : microsoft
    def checkAuthenticated(self, admin=False):
        if self.demoMode:
            return True

        try:
            username = cgi.escape(request.get_cookie('username'))
            sessionToken = cgi.escape(request.get_cookie('session_token'))
            return self.middleware.isAuthenticated(username, sessionToken, admin)
        except:
            return False

3 View Complete Implementation : session.py
Copyright ISC License
Author : ticketfrei
    def apply(self, callback, route):
        if self.keyword in Signature.from_callable(route.callback).parameters:
            @wraps(callback)
            def wrapper(*args, **kwargs):
                uid = request.get_cookie('uid', secret=db.get_secret())
                if uid is None:
                    return redirect(self.loginpage)
                kwargs[self.keyword] = User(uid)
                if request.method == 'POST':
                    if request.forms['csrf'] != request.get_cookie('csrf',
                                                        secret=db.get_secret()):
                        abort(400)
                return callback(*args, **kwargs)

            return wrapper
        else:
            return callback

0 View Complete Implementation : session.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : Bogdanp
def user_required(*permissions):
    def decorator(fn):
        def wrapper(*args, **kwargs):
            session_id = request.get_cookie("sid")
            if not session_id:
                return redirect("/login")

            session = Session.get(session_id)
            if not session:
                return redirect("/login")

            user = session.user.get()
            if user is None:
                return redirect("/login")

            for permission in permissions:
                if permission not in user.permissions:
                    return abort(403)

            return fn(user, *args, **kwargs)
        return wrapper
    return decorator

0 View Complete Implementation : proxy.py
Copyright MIT License
Author : comsysto
def check_past(username, pastword):
    #
    # First check if already valid JWT Token in Cookie
    #
    auth_cookie = request.get_cookie("cs-proxy-auth")
    if auth_cookie and valid_jwt_token(auth_cookie):
        print ('PROXY-AUTH: found valid JWT Token in cookie')
        return True

    #
    # GitHub Basic Auth - also working with username + personal_access_token
    #
    print ('PROXY-AUTH: doing github basic auth - authType: {0}, owner: {1}'.format(auth_type, owner))
    basic_auth = HTTPBasicAuth(username, pastword)
    auth_response = requests.get('https://api.github.com/user', auth=basic_auth)
    if auth_response.status_code == 200:
        if auth_type == 'onlyGitHubOrgUsers':
            print ('PROXY-AUTH: doing org membership request')
            org_membership_response = requests.get('https://api.github.com/user/orgs', auth=basic_auth)
            if org_membership_response.status_code == 200:
                for org in org_membership_response.json():
                    if org['login'] == owner:
                        response.set_cookie("cs-proxy-auth", create_jwt_token())
                        return True
                return False
        else:
            response.set_cookie("cs-proxy-auth", create_jwt_token())
            return True
    return False