2017-06-29 18:22:06 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Models.Api;
|
|
|
|
|
using Plugin.Connectivity.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Repositories
|
|
|
|
|
{
|
|
|
|
|
public class TwoFactorApiRepository : BaseApiRepository, ITwoFactorApiRepository
|
|
|
|
|
{
|
|
|
|
|
public TwoFactorApiRepository(
|
|
|
|
|
IConnectivity connectivity,
|
|
|
|
|
IHttpService httpService,
|
|
|
|
|
ITokenService tokenService)
|
|
|
|
|
: base(connectivity, httpService, tokenService)
|
|
|
|
|
{ }
|
|
|
|
|
|
2017-08-11 21:24:32 +03:00
|
|
|
|
protected override string ApiRoute => "/two-factor";
|
2017-06-29 18:22:06 +03:00
|
|
|
|
|
|
|
|
|
public virtual async Task<ApiResult> PostSendEmailLoginAsync(TwoFactorEmailRequest requestObj)
|
|
|
|
|
{
|
|
|
|
|
if(!Connectivity.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
return HandledNotConnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using(var client = HttpService.ApiClient)
|
|
|
|
|
{
|
|
|
|
|
var requestMessage = new TokenHttpRequestMessage(requestObj)
|
|
|
|
|
{
|
|
|
|
|
Method = HttpMethod.Post,
|
2017-08-11 21:24:32 +03:00
|
|
|
|
RequestUri = new Uri(string.Concat(client.BaseAddress, ApiRoute, "/send-email-login")),
|
2017-06-29 18:22:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
|
|
|
|
|
if(!response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
return await HandleErrorAsync(response).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ApiResult.Success(response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return HandledWebException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|