示例#1
0
def register_new_user(name):
    ''' register a Profile for the current user as long as the name hasn't been used and the user doesn't already have a Profile '''
    if name is None:
        raise ActionException('Name is required')
    if len(Profile.query(Profile.name_order == name.upper()).fetch(1)) > 0:
        raise ActionException('Name has been used by someone else')
    profile, userid = _get_profile()
    if profile is None:
        sm = _get_site_master()
        if sm is None:
            profile = SiteMasterProfile(id=userid)
            profile.free_games = 1
            profile.free_places = 2
        else:
            profile = Profile(id=userid)
    else:
        raise ActionException('User already has a profile')
    profile.name = name
    profile.name_order = name.upper()
    profile.updated = datetime.now()
    profile.playing = profile.key
    profile.put()
    return profile.key.urlsafe()