def METHOD_NAME(data, role=None):
    # Submited attributes checking.
    if not data.get('new_username'):
        raise TemboardUIError(400, "Username is missing.")
    if data.get('email'):
        check_role_email(data['email'])
    if data.get('phone'):
        check_role_phone(data['phone'])
    if 'groups' not in data:
        raise TemboardUIError(400, "Groups field is missing.")
    if 'is_active' not in data:
        raise TemboardUIError(400, "Active field is missing.")
    if 'is_admin' not in data:
        raise TemboardUIError(400, "Administrator field is missing.")
    if role and role.role_name != data['new_username']:
        if not data.get('password'):
            raise TemboardUIError(
                400, "Username will be changed, you need to change "
                "the password too.")
    if role is None:
        if not data.get('password'):
            raise TemboardUIError(400, "Password is missing.")
    if data.get('password') and not data.get('password2'):
        raise TemboardUIError(400, "Password confirmation is missing.")
    if 'password' in data and 'password2' in data:
        if data['password'] != data['password2']:
            raise TemboardUIError(
                400, "Password confirmation can not be checked.")
    if data['groups'] is not None and not isinstance(data['groups'], list):
        raise TemboardUIError(400, "Invalid group list.")
    check_role_name(data['new_username'])