def get_user_doc(db, name):
    """Get the document for the account given by name (email or username).
    Raise ValueError if no such account."""
    # 'name' is the email address for the account
    if '@' in name:
        viewname = 'user/email'
    # else 'name' is the username for the account
    else:
        viewname = 'user/username'
    result = list(db.view(viewname, include_docs=True)[name])
    if len(result) != 1:
        raise ValueError("no such user account '{0}'".format(name))
    return result[0].doc