Exemplo n.º 1
0
    def login(self):
        db = self.environ.dbm.session
        users = dict(((user.username, user.password) \
                for user in db.query(schema.User).all()))
        realm = self.environ.config.get("name")

        if not check_auth(self.request, self.response, realm, users):
            return basic_auth(self.request, self.response, realm, users)

        if not self.request.login in users:
            return basic_auth(self.request, self.response, realm, users)

        self.request.session["login"] = self.request.login

        referer = self.request.headers.get("Referer", None)
        if referer:
            base = urlparse(self.uri.utf8())
            link = urlparse(referer)
            if all([base[i] == link[i] for i in range(2)]):
                return self.redirect(referer)

        data = {
            "title": "Login",
            "html": Markup("Login successful.")
        }

        return self.render("view.html", **data)
Exemplo n.º 2
0
    def index(self):
        realm = "Test"
        users = {"admin": "admin"}
        encrypt = str

        if check_auth(self.request, self.response, realm, users, encrypt):
            return "Hello World!"

        return basic_auth(self.request, self.response, realm, users, encrypt)
Exemplo n.º 3
0
    def on_request(self, event, request, response):
        """Filter Requests applying Basic Authentication

        Filter any incoming requests at a higher priority than the
        default dispatcher and apply Basic Authentication returning
        a 403 Forbidden response if Authentication failed.
        """

        if not check_auth(request, response, self.realm, self.users):
            event.stop()
            return basic_auth(request, response, self.realm, self.users)
Exemplo n.º 4
0
    def on_request(self, event, request, response):
        """Filter Requests applying Basic Authentication

        Filter any incoming requests at a higher priority than the
        default dispatcher and apply Basic Authentication returning
        a 403 Forbidden response if Authentication failed.
        """

        if not check_auth(request, response, self.realm, self.users):
            event.stop()
            return basic_auth(request, response, self.realm, self.users)
Exemplo n.º 5
0
    def logout(self):
        db = self.environ.dbm.session
        users = dict(((user.username, user.password) \
                for user in db.query(schema.User).all()))
        realm = self.environ.config.get("name")

        if "login" in self.request.session:
            del self.request.session["login"]

        if "Authorization" in self.request.headers:
            del self.request.headers["Authorization"]

        return basic_auth(self.request, self.response, realm, users)
Exemplo n.º 6
0
    def logout(self):
        db = self.environ.dbm.session
        users = dict(((user.username, user.password) \
                for user in db.query(schema.User).all()))
        realm = self.environ.config.get("name")

        if "login" in self.request.session:
            del self.request.session["login"]

        if "Authorization" in self.request.headers:
            del self.request.headers["Authorization"]

        return basic_auth(self.request, self.response, realm, users)
Exemplo n.º 7
0
    def login(self):
        db = self.environ.dbm.session
        users = dict(((user.username, user.password) \
                for user in db.query(schema.User).all()))
        realm = self.environ.config.get("name")

        if not check_auth(self.request, self.response, realm, users):
            return basic_auth(self.request, self.response, realm, users)

        if not self.request.login in users:
            return basic_auth(self.request, self.response, realm, users)

        self.request.session["login"] = self.request.login

        referer = self.request.headers.get("Referer", None)
        if referer:
            base = urlparse(self.uri.utf8())
            link = urlparse(referer)
            if all([base[i] == link[i] for i in range(2)]):
                return self.redirect(referer)

        data = {"title": "Login", "html": Markup("Login successful.")}

        return self.render("view.html", **data)
Exemplo n.º 8
0
    def xhr(self, *args, **kwargs):
        realm = "pidart"
        encrypt = str

        if not check_auth(self.request, self.response, realm, users, encrypt):
            return basic_auth(self.request, self.response, realm, users, encrypt)

        if self.request.method != 'POST':
            return simplejson.dumps({'error':"Only method POST is allowed."})
            
        data = simplejson.loads(b64decode(self.request.body.read()))
        cmd = data['command']
        if cmd == 'skip-player':
            self.fireEvent(SkipPlayer(int(data['player'])))
        elif cmd == 'new-game':
            players = data['players']
            start = int(data['startvalue'])
            testgame = data['testgame']
            self.fireEvent(StartGame(players, start, testgame))
        elif cmd == 'update-players':
            players = data['players']
            self.fireEvent(UpdatePlayers(players))
        elif cmd == 'change-last-round':
            player = int(data['player'])
            oldDarts = map(sanitize_input_dart, data['old_darts'])
            newDarts = map(sanitize_input_dart, data['new_darts'])
            self.fireEvent(ChangeLastRound(player, oldDarts, newDarts))
        elif cmd == 'apply-settings':
            self.fireEvent(UpdateSettings(data['settings']))
        elif cmd == 'debug-throw-dart':
            dart = sanitize_input_dart(data['dart'])
            self.fireEvent(ReceiveInput('code', dart))
        elif cmd == 'debug-next-player':
            self.fireEvent(ReceiveInput('generic', 'next_player'))
        elif cmd == 'perform-self-update':
            self.fire(PerformSelfUpdate())
        elif cmd == 'cancel-game':
            self.fireEvent(ReceiveInput('generic', 'cancel_game'))
        elif cmd == 'undo-last-frame':
            player = int(data['player'])
            self.fireEvent(UndoLastFrame(player))
        

        return simplejson.dumps({'success': True})
Exemplo n.º 9
0
 def on_request(self, event, req, res):
     if not check_auth(req, res, self.realm, self.users):
         event.stop()
         return basic_auth(req, res, self.realm, self.users)