Exemplo n.º 1
0
    def get(self):

        isPlayer = login.isPlayer()
        isAdmin = login.isAdmin()

        if not isAdmin and not isPlayer:
            self.response.set_status(500, message='You must log in')
            self.response.out.write('You must log in')
            return

        logging.info(self.request)

        if self.request.get('currentUser'):
            user = users.get_current_user()
            player = Player.all()
            player = player.filter('email =', user.email()).get()
            if player:
                self.response.out.write(playerToJSON(player, isAdmin))
            else:
                self.response.set_status(500, message='You\'re not a player')
                self.response.out.write('You\'re not a player')
                return

        else:
            players = Player.all()
            self.response.out.write(playersToJSON(players, isAdmin))
Exemplo n.º 2
0
 def role(self):
     if login.isPlayer():
         if login.isAdmin():
             return 'admin'
         else:
             return 'player'
     elif login.isViewer(self.request.get('key')):
         return 'viewer'
Exemplo n.º 3
0
 def get(self):
     if login.isAdmin():
         self.response.out.write('admin')
     elif login.isPlayer():
         self.response.out.write('player')
     elif login.isViewer(self.request.get('key')):
         self.response.out.write('viewer')
     else:
         self.response.out.write('none')
Exemplo n.º 4
0
    def get(self):

        #elif user.nickname() != 'zilianimarco':
            #self.redirect(user.nickname());
        #user = users.get_current_user()

        isAdmin = False
        isPlayer = False
        isViewer = False
        if login.isPlayer():
            isAdmin = True if login.isAdmin() else False
            isPlayer = True if not isAdmin else False
        elif login.isViewer(self.request.get('key')):
            isViewer = True

        if isAdmin or isPlayer or isViewer:
            self.redirect('app/index.html#/home')

        else:
            #providers = {
                #'Google'   : 'www.google.com/accounts/o8/id',
                #'Yahoo'    : 'yahoo.com',
                #'MySpace'  : 'myspace.com',
                ##'AOL'      : 'aol.com',
                #'MyOpenID' : 'myopenid.com'
                ## add more here
            #}
            #urls = []
            #for name, uri in providers.items():
                #urls.append({
                    #'name': name,
                    #'url': users.create_login_url(federated_identity=uri)
                    #})
            template_values = {
                #'user': user,
                #'urls': urls,
                #'sendStatus': self.request.get('send'),
                #'sendLink': 'authMail',
                'name': 'Google',
                'url': users.create_login_url()
            }
            template = jinja_environment.get_template('login.html')
            self.response.out.write(template.render(template_values))
Exemplo n.º 5
0
    def put(self, id):
        isActive = Configuration.all().filter('name', 'checkin').get()
        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer() and not isAdmin
        user = users.get_current_user()
        if not isAdmin and not isPlayer:
            self.response.out.write('not_logged_in')
        else:
            request = json.loads(self.request.body)
            status = request['status']
            n_presents = Player.all().filter('status =', 'present').count()

            if status != 'present' or n_presents < 10:
                player = None
                if isAdmin:
                    id = long(id)
                    player = Player.get_by_id(id)
                    logging.info('Admin set status to \'' + status + '\' for ' +
                                 str(player.email))
                elif isPlayer and (isActive is None or isActive.value):
                    player = Player.all()
                    player = player.filter('email =', user.email()).get()
                    logging.info(str(player.email) + ' set status to \'' +
                                 status + '\'')

                if player:
                    player.status = status
                    player.put()
                    #self.response.out.write('ok')
                else:
                    logging.info(user.nickname() + ' (' + user.email() +
                                 ') tried to set status to \'' +
                                 status + '\' but it was inactive')
                    self.response.set_status(401, 'La lista &egrave; bloccata o \
                            non sei pi&ugrave; loggato')

            else:
                logging.info(user.nickname() + ' (' + user.email() +
                             ') tried to set status to \'' + status +
                             '\' but it was full')
                self.response.set_status(500, 'La lista &egrave; piena')
Exemplo n.º 6
0
    def post(self):
        #email = users.get_current_user().email()
        isActive = Configuration.all().filter('name', 'checkin').get()
        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer() and not isAdmin
        user = users.get_current_user()
        if not isAdmin and not isPlayer:
            self.response.out.write('not_logged_in')
        else:
            n_presents = Player.all().filter('status =', 'present').count()
            status = self.request.get('status')
            if status != 'present' or n_presents < 10:
                player = None
                id = self.request.get('id')
                if isAdmin and id:
                    id = long(id)
                    player = Player.get_by_id(id)
                    logging.info('Admin set status to \'' + 
                            status + '\' for ' + str(player.email))
                elif isActive == None or isActive.value:
                    player = Player.all()
                    player = player.filter('email =', user.email()).get()
                    logging.info(str(player.email) + ' set status to \'' + 
                            status + '\'')

                if player:
                    player.status = status
                    player.put()
                    self.response.out.write('ok')
                else:
                    logging.info(user.nickname() + ' (' + user.email() + 
                            ') tried to set status to \'' + status + 
                            '\' but it was inactive')
                    self.response.out.write('inactive')

            else:
                logging.info(user.nickname() + ' (' + user.email() + 
                        ') tried to set status to \'' + status + 
                        '\' but it was full')
                self.response.out.write('full')
Exemplo n.º 7
0
def playersToJsonApp(request):

    isPlayer = login.isPlayer()
    isAdmin = login.isAdmin()
    user = users.get_current_user()
    email = str(user.email()) if user else ''

    #uri = 'www.google.com/accounts/o8/id'
    url = request.referer or '/'
    logging.info(url)
    loginUrl = users.create_login_url(url)
    logoutUrl = users.create_logout_url(url)

    result = []
    result.append('{"isAdmin": "' + str(isAdmin) + '", ')
    result.append('"user": "******", ')
    result.append('"isPlayer": "' + str(isPlayer) + '", ')
    result.append('"loginUrl": "' + loginUrl + '", ')
    result.append('"logoutUrl": "' + logoutUrl + '"')

    if isAdmin or isPlayer:
        players = Player.all()
        result.append(', "players": ' + playersToJSON(players, isAdmin) + '')
        currentId = None
        current_user = users.get_current_user()
        for player in players:
            id = str(player.key().id())
            if current_user and current_user.email() == player.email:
                currentId = id

        if currentId:
            result.append(', "id": "' + currentId + '"')

    result.append('}')

    return ''.join(result)
Exemplo n.º 8
0
    def post(self):

        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer()
        user = users.get_current_user()

        if not isAdmin and not isPlayer:
            self.response.set_status(500, message='You must log in')
            self.response.out.write('You must log in')
            return

        # get player data
        logging.info(self.request.body)
        try:
            player_data = json.loads(self.request.body)
        except ValueError:
            player_data = self.request
        logging.info(player_data)

        if player_data and player_data.get('id'):
            id = int(player_data.get('id'))
            db_player = Player.get_by_id(id)
        elif player_data.get('name'):
            db_player = Player(name=player_data['name'])
        else:
            self.response.set_status(500, message='You have not specified an id or a name')
            self.response.out.write('You have not specified an id or a name')
            return

        if not isAdmin and db_player.email != user.email():
            logging.info(db_player.email)
            logging.info(user.email())
            self.response.set_status(500, message='You are not authorized')
            self.response.out.write('You are not authorized')
            return

        # edit player in db
        if db_player:

            status = player_data.get('status') or 'waiting'
            # check if status is valid
            n_presents = Player.all().filter('status =', 'present').count()
            if db_player.status != 'present' and status == 'present' and n_presents >= 10:
                logging.info(user.nickname() + ' (' + user.email() +
                             ') tried to set status to \'' + status +
                             '\' but it was full')
                self.response.set_status(500, message='La lista e\' piena')
                self.response.out.write('La lista e\' piena')
                return

            db_player.status = status

            if isAdmin:
                isStarred = player_data.get('isStarred') == 'True' or False
                db_player.isStarred = isStarred
                db_player.name = player_data.get('name')
                if player_data.get('email'):
                    db_player.email = player_data.get('email')

            db_player.put()

            #send message to clients
            result = playerToJSON(db_player, isAdmin)
            sendMessage(result)
            self.response.out.write(result)

        else:
            self.response.out.write('emptyName')
Exemplo n.º 9
0
 def email(self):
     if login.isPlayer():
         return users.get_current_user().email()
     else:
         return 'none'
Exemplo n.º 10
0
    def get(self):

        # elif user.nickname() != 'zilianimarco':
        # self.redirect(user.nickname());
        user = users.get_current_user()

        isAdmin = False
        isPlayer = False
        isViewer = False
        if login.isPlayer():
            isAdmin = True if login.isAdmin() else False
            isPlayer = True if not isAdmin else False
        elif login.isViewer(self.request.get("key")):
            isViewer = True

        if isAdmin or isPlayer or isViewer:

            ua = self.request.headers.get("User-Agent")
            forceDesktop = self.request.get("v") == "desktop"
            isMobile = self.isSmart(ua) and not forceDesktop

            if isMobile:

                if isAdmin or isPlayer:
                    logging.info(user.nickname() + " (" + user.email() + ") visited mobile version")
                elif isViewer:
                    logging.info("Anonymous visited mobile version")

                self.redirect("m/index.html")

            else:
                if (self.request.get("dev") != "plain" and not self.isBlackBerry(ua)) or self.request.get(
                    "dev"
                ) == "full":
                    if login.isPlayer():
                        logging.info(user.nickname() + " (" + user.email() + ") visited desktop version")
                    elif login.isViewer(self.request.get("key")):
                        logging.info("Anonymous visited desktop version")

                    self.response.out.write(Desktop().render())

                else:

                    if user:
                        current = Player.all().filter("email", user.email()).get()
                        logging.info(user.nickname() + " (" + user.email() + ") visited desktop simple version")
                    else:
                        current = None
                        logging.info("Anonymous visited desktop simple version")

                    template_values = {
                        "status": current.status if current else None,
                        "id": current.key().id() if current else None,
                        "waiting": Player.all().filter("status =", "waiting"),
                        "present": Player.all().filter("status =", "present"),
                        "absent": Player.all().filter("status =", "absent"),
                    }
                    template = jinja_environment.get_template("desktop/desktop_plain.html")
                    self.response.out.write(template.render(template_values))

        else:
            providers = {
                "Google": "www.google.com/accounts/o8/id",
                "Yahoo": "yahoo.com",
                "MySpace": "myspace.com",
                #'AOL'      : 'aol.com',
                "MyOpenID": "myopenid.com"
                # add more here
            }
            # urls = []
            # for name, uri in providers.items():
            # urls.append({
            #'name': name,
            #'url': users.create_login_url(federated_identity=uri)
            # })
            template_values = {
                #'user': user,
                #'urls': urls,
                #'sendStatus': self.request.get('send'),
                #'sendLink': 'authMail',
                "name": "Google",
                "url": users.create_login_url(),
            }
            template = jinja_environment.get_template("login.html")
            self.response.out.write(template.render(template_values))