Browse Source

Merge pull request #15667 from abpframework/cli-move-check-multiple-org

Cli: Move CheckMultipleOrganizationsAsync to AuthService
pull/15699/head
Yunus Emre Kalkan 4 years ago
committed by GitHub
parent
commit
879f07cfba
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs
  2. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/IAuthService.cs
  3. 30
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs

20
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

@ -127,6 +127,26 @@ public class AuthService : IAuthService, ITransientDependency
}
}
public async Task<bool> CheckMultipleOrganizationsAsync(string username)
{
var url = $"{CliUrls.WwwAbpIo}api/license/check-multiple-organizations?username={username}";
var client = CliHttpClientFactory.CreateClient();
using (var response = await client.GetHttpResponseMessageWithRetryAsync(url, CancellationTokenProvider.Token, Logger))
{
if (!response.IsSuccessStatusCode)
{
throw new Exception($"ERROR: Remote server returns '{response.StatusCode}'");
}
await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);
var responseContent = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<bool>(responseContent);
}
}
private async Task LogoutAsync(string accessToken)
{
try

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/IAuthService.cs

@ -9,4 +9,6 @@ public interface IAuthService
Task LoginAsync(string userName, string password, string organizationName = null);
Task LogoutAsync();
Task<bool> CheckMultipleOrganizationsAsync(string username);
}

30
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs

@ -2,13 +2,11 @@
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Auth;
using Volo.Abp.Cli.Http;
using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
@ -26,17 +24,13 @@ public class LoginCommand : IConsoleCommand, ITransientDependency
public ICancellationTokenProvider CancellationTokenProvider { get; }
public IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; }
private readonly CliHttpClientFactory _cliHttpClientFactory;
public LoginCommand(AuthService authService,
ICancellationTokenProvider cancellationTokenProvider,
IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
CliHttpClientFactory cliHttpClientFactory)
IRemoteServiceExceptionHandler remoteServiceExceptionHandler)
{
AuthService = authService;
CancellationTokenProvider = cancellationTokenProvider;
RemoteServiceExceptionHandler = remoteServiceExceptionHandler;
_cliHttpClientFactory = cliHttpClientFactory;
Logger = NullLogger<LoginCommand>.Instance;
}
@ -111,7 +105,7 @@ public class LoginCommand : IConsoleCommand, ITransientDependency
private async Task<bool> HasMultipleOrganizationAndThisNotSpecified(CommandLineArgs commandLineArgs, string organization)
{
if (string.IsNullOrWhiteSpace(organization) &&
await CheckMultipleOrganizationsAsync(commandLineArgs.Target))
await AuthService.CheckMultipleOrganizationsAsync(commandLineArgs.Target))
{
Logger.LogError($"You have multiple organizations, please specify your organization with `--organization` parameter.");
return true;
@ -168,26 +162,6 @@ public class LoginCommand : IConsoleCommand, ITransientDependency
return false;
}
private async Task<bool> CheckMultipleOrganizationsAsync(string username)
{
var url = $"{CliUrls.WwwAbpIo}api/license/check-multiple-organizations?username={username}";
var client = _cliHttpClientFactory.CreateClient();
using (var response = await client.GetHttpResponseMessageWithRetryAsync(url, CancellationTokenProvider.Token, Logger))
{
if (!response.IsSuccessStatusCode)
{
throw new Exception($"ERROR: Remote server returns '{response.StatusCode}'");
}
await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);
var responseContent = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<bool>(responseContent);
}
}
public string GetUsageInfo()
{
var sb = new StringBuilder();

Loading…
Cancel
Save