Exemplo n.º 1
0
def get_anonymous_id():
    """ Retrieves anonymous user object """
    # try to get anonymous user
    key = db.Key(Uzver, 'anonymous')
    user = db.get(key)

    # or create it if it does not exist
    if None == user:
        user = Uzver(nick_name='anonymous',
                     first_name='unknown',
                     last_name='unknown',
                     email='*****@*****.**',
                     password='******')
        user.put()

    return user.key().id_or_name()
Exemplo n.º 2
0
    def __init__(self, user_data, is_new=True, user_id=None):
        """ Creates new user or loads an existing user data from datastore """
        if (None == user_id) and (None == user_data or None == user_data['nick_name']):
            raise(BadUserData, 'user nickname or id is required')

        if None != user_id:
            # existing user requested, try to get it
            user = db.get(user_id)
            if None == user:
                raise(BadUserData, 'user with the specified nickname does not exist')
        
        elif is_new:
            # create new user but check for duplicates first
            if not self._is_unique(user_data):
                raise(BadUserRequest, 'user with such nickname or email exists')
            

            user = Uzver(user_data)
            user.put()

        else:
            # try to get and update an existing user or raise exception if it's not exist
            key = db.Key(Uzver, user_data['nick_name'])
            user = db.get(key)

            if None == user:
                raise(BadUserRequest, 'user with the specified nickname does not exist')

            # anonymous user is read-only
            if 'anonymous' == user['nick_name'].to_lower():
                raise(BadUserRequest, 'specified user is read-only')

            # update user data
            self._user_ = user
            self.set_user_info(user_data)

        self._user_ = user