protected virtual async Task <CodeZeroLoginResult <TTenant, TUser> > CreateLoginResultAsync(TUser user, TTenant tenant = null)
        {
            if (!user.IsActive)
            {
                return(new CodeZeroLoginResult <TTenant, TUser>(CodeZeroLoginResultType.UserIsNotActive));
            }

            if (await IsEmailConfirmationRequiredForLoginAsync(user.TenantId) && !user.IsEmailConfirmed)
            {
                return(new CodeZeroLoginResult <TTenant, TUser>(CodeZeroLoginResultType.UserEmailIsNotConfirmed));
            }

            if (await IsPhoneConfirmationRequiredForLoginAsync(user.TenantId) && !user.IsPhoneNumberConfirmed)
            {
                return(new CodeZeroLoginResult <TTenant, TUser>(CodeZeroLoginResultType.UserPhoneNumberIsNotConfirmed));
            }

            user.LastLoginTime = Clock.Now;

            await UserManager.UpdateAsync(user);

            await UnitOfWorkManager.Current.SaveChangesAsync();

            var principal = await _claimsPrincipalFactory.CreateAsync(user);

            return(new CodeZeroLoginResult <TTenant, TUser>(
                       tenant,
                       user,
                       principal.Identity as ClaimsIdentity
                       ));
        }