def new_user(data):
    u = User(id=data['id'])
    u.about = data.get('about', '')
    u.affiliations = [data.get('affiliation', '')]
    u.badges = []
    u.comments = []
    u.display_name = data['displayName']
    u.email = data['email']
    u.location_id = data.get('locationId', '')
    u.photo_gcs_path = data.get('photo_path', None)
    u.pubs = []
    u.reputation = 1
    u.role = Roles.USER
    u.tags = []
    u.votes = []
    u.put()
    return u.as_dict(verbose=True, api_prefix=doc_api_path())
Пример #2
0
def edit_user():
    # Edit user about section
    print
    print("############################################")
    print("################ EDIT USER #################")
    print("############################################")

    username_one = "user1"
    password_one = "user1"

    # user1 logins successfuly
    user_one = User(username_one, password_one)
    if not user_one.valid:
        print("User1 did not authenticate!!")
        exit()
    else:
        print("User1 authenticated!")

    # Show current user1 about
    print("Old user1 about: "+user_one.about)

    # Update user1 about
    user_one.about = "This is the new user1 about [" + \
        str(rng.randint(0, 1000))+"]"

    # Save user state
    ps.save_user(user_one.to_json())

    # Delete user and re-login
    del user_one

    user_one = User(username_one, password_one)
    if not user_one.valid:
        print("User1 did not authenticate!!")
        exit()
    else:
        print("User1 authenticated!")

    # Show new user1 about
    print("New user1 about: "+user_one.about)

    # Logout
    del user_one