コード例 #1
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In UpdateUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        request_args = set(self.request.arguments())

        # Update encrypted fields
        for property in ('email', 'phone'):
            if property in request_args:
                user.set_value(property, encrypt(self.request.get(property)))

        # Update rest of fields
        for property in ('wins', 'losses', 'credits', 
                         'level', 'experience', 'blob'):

            if property in request_args:
                user.set_value(property, self.request.get(property))

        user.modify_date = datetime.now()
        user.put()

        write_response(self.response, "0", {})
コード例 #2
0
    def post(self):
        logging.debug("In UpdateUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        request_args = set(self.request.arguments())

        # Update encrypted fields
        for property in ('email', 'phone'):
            if property in request_args:
                user.set_value(property, encrypt(self.request.get(property)))

        # Update rest of fields
        for property in ('wins', 'losses', 'credits', 'level', 'experience',
                         'blob'):

            if property in request_args:
                user.set_value(property, self.request.get(property))

        user.modify_date = datetime.now()
        user.put()

        write_response(self.response, "0", {})
コード例 #3
0
    def post(self):
        logging.debug("In CreateUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None,
                           "gameid is invalid: %s" % gameid)
            return

        # Verify that this user name is unique
        name = self.request.get('name')
        game = GAMES[gameid]['name']
        logging.debug("Email is: " + self.request.get('email'))
        if not GameUser.name_is_available(name, game):
            write_response(self.response, "2", None,
                           "User name %s already exists for this game." % name)
            return

        # Verify that this email is unique
        if GAMES[gameid]['emailVerification']:
            email = self.request.get('email')
            if email == None or email == '':
                write_response(self.response, "1", None,
                               "Required fields are missing: %s." % email)

            game = GAMES[gameid]['name']
            email = encrypt(email.lower())
            if not GameUser.email_is_available(email, game):
                write_response(
                    self.response, "13", None,
                    "Email address %s already exists for this game." % email)
                return
        else:
            email = encrypt(self.request.get('email').lower())

        user = GameUser()
        user.password, user.salt = saltedhash_hex(self.request.get('password'))
        user.name = name.lower()
        user.game = game
        logging.debug("Email NOW is: " + email)
        user.email = email
        user.phone = encrypt(self.request.get('phone'))
        user.blob = self.request.get('blob')

        # Perform email verification for those games that require it.
        # Otherwise, just mark the user as verified.

        if GAMES[gameid]['emailVerification']:
            user.status = USER_UNVERIFIED
            send_email(user, GAMES[gameid]['name'])
        else:
            user.status = USER_VERIFIED

        user.put()
        write_response(self.response, "0", {})
コード例 #4
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In CreateUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None, "gameid is invalid: %s" % gameid)
            return

        # Verify that this user name is unique
        name = self.request.get('name')
        game = GAMES[gameid]['name']
        logging.debug("Email is: " + self.request.get('email'))
        if not GameUser.name_is_available(name, game):
            write_response(self.response, "2", None, 
                           "User name %s already exists for this game." % name)
            return
           
        # Verify that this email is unique
        if GAMES[gameid]['emailVerification']:
            email = self.request.get('email')
            if email == None or email == '':
                write_response(self.response, "1", None, 
                               "Required fields are missing: %s." % email)

            game = GAMES[gameid]['name']
            email = encrypt(email.lower())
            if not GameUser.email_is_available(email, game):
                write_response(self.response, "13", None, 
                               "Email address %s already exists for this game." % email)
                return
        else:
            email = encrypt(self.request.get('email').lower())
            
        user = GameUser()
        user.password, user.salt = saltedhash_hex(self.request.get('password'))
        user.name = name.lower()
        user.game = game
        logging.debug("Email NOW is: " + email)
        user.email = email
        user.phone = encrypt(self.request.get('phone'))
        user.blob = self.request.get('blob')

        # Perform email verification for those games that require it.
        # Otherwise, just mark the user as verified.

        if GAMES[gameid]['emailVerification']:
            user.status = USER_UNVERIFIED
            send_email(user, GAMES[gameid]['name'])
        else:
            user.status = USER_VERIFIED

        user.put()
        write_response(self.response, "0", {})
コード例 #5
0
    def post(self):
        logging.debug("In GetUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        write_response(self.response, "0", json.dumps(user.to_dict()))
        return
コード例 #6
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In GetUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        write_response(self.response, "0", json.dumps(user.to_dict()))
        return 
コード例 #7
0
ファイル: yaas.py プロジェクト: mikesela/yaas
def get_user_for_update(request, response):
    """ Utility function that does a bunch of the input validation required
    for services that update user information."""
    # Verify the gameid is valid:
    gameid = request.get('gameid')
    if gameid not in GAMES:
        write_response(response, "4", None, "Gameid is invalid: %s" % gameid)
        return None

    # Get the user
    name = request.get('name')
    game = GAMES[gameid]['name']
    user = GameUser.get_by_name(name, game)
    if not user:
        write_response(response, "6", None, 
                       "User %s does not exist" % name)
        return None

    # Ensure token is still valid
    token = request.get('token')
    if token != user.token:
        logging.error(token + " != " + user.token)
        write_response(response, "7", None, "Token %s is invalid" % token)
        return None

    exp_date = user.last_login_date + timedelta(seconds=user.expiration) 
    if exp_date < datetime.now():
        write_response(response, "8", None, "Token has expired.  Log in again.")
        return None

    return user
コード例 #8
0
def get_user_for_update(request, response):
    """ Utility function that does a bunch of the input validation required
    for services that update user information."""
    # Verify the gameid is valid:
    gameid = request.get('gameid')
    if gameid not in GAMES:
        write_response(response, "4", None, "Gameid is invalid: %s" % gameid)
        return None

    # Get the user
    name = request.get('name')
    game = GAMES[gameid]['name']
    user = GameUser.get_by_name(name, game)
    if not user:
        write_response(response, "6", None, "User %s does not exist" % name)
        return None

    # Ensure token is still valid
    token = request.get('token')
    if token != user.token:
        logging.error(token + " != " + user.token)
        write_response(response, "7", None, "Token %s is invalid" % token)
        return None

    exp_date = user.last_login_date + timedelta(seconds=user.expiration)
    if exp_date < datetime.now():
        write_response(response, "8", None,
                       "Token has expired.  Log in again.")
        return None

    return user
コード例 #9
0
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        itemlist = []
        items = GameItem.list(user)
        for item in items:
            itemdict = item.to_dict()
            itemlist.append(itemdict)

        write_response(self.response, "0", json.dumps(itemlist))
コード例 #10
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        itemlist = []
        items = GameItem.list(user)
        for item in items:
            itemdict = item.to_dict()
            itemlist.append(itemdict)

        write_response(self.response, "0", json.dumps(itemlist))
コード例 #11
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In ListUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None, "Gameid is invalid: %s" % gameid)
            return

        userlist = []
        users = GameUser.list(GAMES[gameid]['name'])
        for user in users:
            userdict = user.to_dict()
            userlist.append(userdict)

        write_response(self.response, "0", json.dumps(userlist))
コード例 #12
0
    def post(self):
        logging.debug("In ListUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None,
                           "Gameid is invalid: %s" % gameid)
            return

        userlist = []
        users = GameUser.list(GAMES[gameid]['name'])
        for user in users:
            userdict = user.to_dict()
            userlist.append(userdict)

        write_response(self.response, "0", json.dumps(userlist))
コード例 #13
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        """ Removes an item from a user """
        logging.debug("In GetItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item == None:
            write_response(self.response, "12", None, "Item type %s with name %s does not exist for user %s." % (itemtype, name, self.request.get('name')))
        else:
            write_response(self.response, "0", json.dumps(item.to_dict()))
        return 
コード例 #14
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        """ Just updates the item quantity """
        logging.debug("In UpdateItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)

        if item == None:
            write_response(self.response, "12", None, "Item type %s with name %s does not exist for user %s." % (itemtype, name, self.request.get('name')))
            return

        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(self.response, "9", None, 
                           "quantity %s must be an integer" % self.request.get('quantity'))
            return None

        item.blob = self.request.get('blob')
        item.put()
        write_response(self.response, "0", {})
コード例 #15
0
    def post(self):
        """ Just updates the item quantity """
        logging.debug("In UpdateItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)

        if item == None:
            write_response(
                self.response, "12", None,
                "Item type %s with name %s does not exist for user %s." %
                (itemtype, name, self.request.get('name')))
            return

        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(
                self.response, "9", None, "quantity %s must be an integer" %
                self.request.get('quantity'))
            return None

        item.blob = self.request.get('blob')
        item.put()
        write_response(self.response, "0", {})
コード例 #16
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Ensure this item does not already exist for this user
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item != None:
            write_response(self.response, "11", None, 
                           "Item with name %s and type %s already exists for user %s" %
                           (name, itemtype, user.name))
            return

        # Add item to user
        item = GameItem()
        item.itemtype = itemtype
        item.name = name
        item.user = user
        item.blob = self.request.get('blob')
        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(self.response, "9", None, 
                           "quantity %s must be an integer" % self.request.get('quantity'))
            return None

        item.put()
        write_response(self.response, "0", {})
コード例 #17
0
    def post(self):
        """ Removes an item from a user """
        logging.debug("In GetItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item == None:
            write_response(
                self.response, "12", None,
                "Item type %s with name %s does not exist for user %s." %
                (itemtype, name, self.request.get('name')))
        else:
            write_response(self.response, "0", json.dumps(item.to_dict()))
        return
コード例 #18
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In DeleteUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None, "gameid is invalid: %s" % gameid)
            return

        # Get the user
        name = self.request.get('name')
        game = GAMES[self.request.get('gameid')]['name']
        user = GameUser.get_by_name(name, game)
        if not user:
            write_response(self.response, "6", None, "User %s does not exist" % name)
            return

        user.delete()
        write_response(self.response, "0", {})
コード例 #19
0
    def post(self):
        logging.debug("In DeleteUserHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None,
                           "gameid is invalid: %s" % gameid)
            return

        # Get the user
        name = self.request.get('name')
        game = GAMES[self.request.get('gameid')]['name']
        user = GameUser.get_by_name(name, game)
        if not user:
            write_response(self.response, "6", None,
                           "User %s does not exist" % name)
            return

        user.delete()
        write_response(self.response, "0", {})
コード例 #20
0
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Ensure this item does not already exist for this user
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item != None:
            write_response(
                self.response, "11", None,
                "Item with name %s and type %s already exists for user %s" %
                (name, itemtype, user.name))
            return

        # Add item to user
        item = GameItem()
        item.itemtype = itemtype
        item.name = name
        item.user = user
        item.blob = self.request.get('blob')
        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(
                self.response, "9", None, "quantity %s must be an integer" %
                self.request.get('quantity'))
            return None

        item.put()
        write_response(self.response, "0", {})
コード例 #21
0
 def get(self):
     if GET_ENABLED:
         return self.post()
     else:
         write_response(self.response, "10", None, "GET not enabled")
コード例 #22
0
    def post(self):
        logging.debug("In LoginHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None, "Gameid is invalid.")
            return

        # Ensure name is valid
        name = self.request.get('name')
        user = GameUser.get_by_name(name, GAMES[gameid]['name'])
        if not user:
            write_response(self.response, "3", None,
                           "User name or password is invalid.")
            return

        # Ensure password matches one in DB
        password = self.request.get('password')
        encrypted_password, salt = saltedhash_hex(password, user.salt)
        if encrypted_password != user.password:
            write_response(self.response, "3", None,
                           "User name or Password is incorrect.")
            return

        # Ensure game matches one in DB
        game = GAMES[gameid]['name']
        if game != user.game:
            write_response(self.response, "5", None,
                           "Gameid incorrect for this user %s." % name)
            return

        # Ensure user is verified
        if user.status == USER_UNVERIFIED:
            write_response(self.response, "14", None,
                           "User %s is unverified." % name)
            return

        #Generate token
        token = get_token_str()
        expiration = get_token_expiration(
            int(self.request.get('expiration', 0)))
        user.last_login_date = datetime.now()
        user.token = token
        user.expiration = expiration
        user.put()

        write_response(self.response, "0", json.dumps(dict(token=token)))
コード例 #23
0
ファイル: yaas.py プロジェクト: mikesela/yaas
    def post(self):
        logging.debug("In LoginHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Verify the gameid is valid:
        gameid = self.request.get('gameid')
        if gameid not in GAMES:
            write_response(self.response, "4", None, "Gameid is invalid.")
            return

        # Ensure name is valid
        name = self.request.get('name')
        user = GameUser.get_by_name(name, GAMES[gameid]['name'])
        if not user:
            write_response(self.response, "3", None, 
                           "User name or password is invalid.")
            return

        # Ensure password matches one in DB
        password = self.request.get('password')
        encrypted_password,  salt = saltedhash_hex(password, user.salt)
        if encrypted_password != user.password:
            write_response(self.response, "3", None, 
                           "User name or Password is incorrect.")
            return

        # Ensure game matches one in DB
        game = GAMES[gameid]['name']
        if game != user.game:
            write_response(self.response, "5", None, 
                           "Gameid incorrect for this user %s." % name)
            return

        # Ensure user is verified
        if user.status == USER_UNVERIFIED:
            write_response(self.response, "14", None, 
                           "User %s is unverified." % name)
            return

        #Generate token
        token = get_token_str()
        expiration = get_token_expiration(int(self.request.get('expiration', 0)))
        user.last_login_date = datetime.now()
        user.token = token
        user.expiration = expiration
        user.put()

        write_response(self.response, "0", json.dumps(dict(token=token)))
コード例 #24
0
ファイル: yaas.py プロジェクト: mikesela/yaas
 def get(self):
     if GET_ENABLED:
         return self.post()
     else:
         write_response(self.response, "10", None, "GET not enabled")