def METHOD_NAME(self, attrs):
    login_id = attrs.get('username')
    password = attrs.get('password')
    platform = attrs.get('platform', None)
    device_id = attrs.get('device_id', None)
    device_name = attrs.get('device_name', None)
    client_version = attrs.get('client_version', None)
    platform_version = attrs.get('platform_version', None)
    v2_fields = (platform, device_id, device_name)
    # Decide the version of token we need
    if all_none(v2_fields):
        v2 = False
    elif all_not_none(v2_fields):
        v2 = True
    else:
        raise serializers.ValidationError('invalid params')
    if login_id and password:
        user = authenticate(username=login_id, password=password)
        if user:
            if not user.is_active:
                raise serializers.ValidationError('User account is disabled.')
        else:
            """try login id/contact email/primary id"""
            # convert login id or contact email to username if any
            username = Profile.objects.convert_login_str_to_username(login_id)
            # convert username to primary id if any
            p_id = ccnet_api.get_primary_id(username)
            if p_id is not None:
                username = p_id
            user = authenticate(username=username, password=password)
            if user is None:
                raise serializers.ValidationError('Unable to login with provided credentials.')
            elif not user.is_active:
                raise serializers.ValidationError('User account is disabled.')
    else:
        raise serializers.ValidationError('Must include "username" and "password"')
    self._two_factor_auth(self.context['request'], user)
    # Now user is authenticated
    if v2:
        if platform in DESKTOP_PLATFORMS:
            if not user.permissions.can_connect_with_desktop_clients():
                raise serializers.ValidationError('Not allowed to connect to desktop client.')
        elif platform == 'android':
            if not user.permissions.can_connect_with_android_clients():
                raise serializers.ValidationError('Not allowed to connect to android client.')
        elif platform == 'ios':
            if not user.permissions.can_connect_with_ios_clients():
                raise serializers.ValidationError('Not allowed to connect to ios client.')
        else:
            logger.info('%s: unrecognized device' % login_id)
        token = get_token_v2(self.context['request'], user.username, platform,
                             device_id, device_name, client_version, platform_version)
    else:
        token = get_token_v1(user.username)
    return token.key