Exemplo n.º 1
0
    def cb(wh, *args, **kwargs):
        url_user = urllib.unquote(args[0])

        auth_header = wh.request.headers.get('Authorization')
        if auth_header == None:
            wh.response.set_status(401, message="Authorization Required")
            wh.response.headers['WWW-Authenticate'] = 'Basic realm="firefox-sync"'
            return
        
        auth_parts = auth_header.split(' ')
        user_arg, pass_arg = base64.b64decode(auth_parts[1]).split(':')

        valid_authen = (
            (url_user == user_arg) 
                and 
            Profile.authenticate(user_arg, pass_arg)
        )

        if not valid_authen:
            wh.response.set_status(401, message="Authorization Required")
            wh.response.headers['WWW-Authenticate'] = 'Basic realm="firefox-sync"'
            wh.response.out.write("Unauthorized")
        else:
            wh.request.profile = Profile.get_by_user_name(user_arg)
            return func(wh, *args, **kwargs)
Exemplo n.º 2
0
    def cb(wh, *args, **kwargs):
        url_user = urllib.unquote(args[0])

        auth_header = wh.request.headers.get('Authorization')
        if auth_header == None:
            wh.response.set_status(401, message="Authorization Required")
            wh.response.headers[
                'WWW-Authenticate'] = 'Basic realm="firefox-sync"'
            return

        auth_parts = auth_header.split(' ')
        user_arg, pass_arg = base64.b64decode(auth_parts[1]).split(':')

        valid_authen = ((url_user == user_arg)
                        and Profile.authenticate(user_arg, pass_arg))

        if not valid_authen:
            wh.response.set_status(401, message="Authorization Required")
            wh.response.headers[
                'WWW-Authenticate'] = 'Basic realm="firefox-sync"'
            wh.response.out.write("Unauthorized")
        else:
            wh.request.profile = Profile.get_by_user_name(user_arg)
            return func(wh, *args, **kwargs)