Browse Source

get profile api

pull/1/head
Kyle Spearrin 9 years ago
parent
commit
dac8b4c476
  1. 4
      src/Core/Core.csproj
  2. 15
      src/Core/Enums/OrganizationUserStatusType.cs
  3. 15
      src/Core/Enums/OrganizationUserType.cs
  4. 20
      src/Core/Models/ProfileOrganizationResponse.cs
  5. 20
      src/Core/Models/ProfileResponse.cs
  6. 36
      src/Core/Services/ApiService.cs

4
src/Core/Core.csproj

@ -49,15 +49,19 @@ @@ -49,15 +49,19 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Enums\OrganizationUserType.cs" />
<Compile Include="Enums\OrganizationUserStatusType.cs" />
<Compile Include="Models\ApiError.cs" />
<Compile Include="Models\ApiResult.cs" />
<Compile Include="Models\Entry.cs" />
<Compile Include="Models\ImportRequest.cs" />
<Compile Include="Models\ProfileOrganizationResponse.cs" />
<Compile Include="Models\ServerConfiguration.cs" />
<Compile Include="Models\LoginResult.cs" />
<Compile Include="Models\ErrorResponse.cs" />
<Compile Include="Models\EncryptedData.cs" />
<Compile Include="Models\TokenRequest.cs" />
<Compile Include="Models\ProfileResponse.cs" />
<Compile Include="Models\TokenResponse.cs" />
<Compile Include="Services\ApiService.cs" />
<Compile Include="Services\SettingsService.cs" />

15
src/Core/Enums/OrganizationUserStatusType.cs

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Core.Enums
{
public enum OrganizationUserStatusType : byte
{
Invited = 0,
Accepted = 1,
Confirmed = 2
}
}

15
src/Core/Enums/OrganizationUserType.cs

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Core.Enums
{
public enum OrganizationUserType : byte
{
Owner = 0,
Admin = 1,
User = 2
}
}

20
src/Core/Models/ProfileOrganizationResponse.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
using Bit.Core.Enums;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Core.Models
{
public class ProfileOrganizationResponseModel
{
public string Id { get; set; }
public string Name { get; set; }
public string Key { get; set; }
public OrganizationUserStatusType Status { get; set; }
public OrganizationUserType Type { get; set; }
public bool Enabled { get; set; }
}
}

20
src/Core/Models/ProfileResponse.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Core.Models
{
public class ProfileResponse
{
public string Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string MasterPasswordHint { get; set; }
public string Culture { get; set; }
public bool TwoFactorEnabled { get; set; }
public IEnumerable<ProfileOrganizationResponseModel> Organizations { get; set; }
}
}

36
src/Core/Services/ApiService.cs

@ -111,7 +111,7 @@ namespace Bit.Core.Services @@ -111,7 +111,7 @@ namespace Bit.Core.Services
{
return await HandleErrorAsync(response).ConfigureAwait(false);
}
return ApiResult.Success(response.StatusCode);
}
catch
@ -120,6 +120,40 @@ namespace Bit.Core.Services @@ -120,6 +120,40 @@ namespace Bit.Core.Services
}
}
public virtual async Task<ApiResult<ProfileResponse>> GetProfileAsync()
{
var tokenStateResponse = await HandleTokenStateAsync<ProfileResponse>();
if(!tokenStateResponse.Succeeded)
{
return tokenStateResponse;
}
var requestMessage = new HttpRequestMessage()
{
Method = HttpMethod.Get,
RequestUri = new Uri(ApiClient.BaseAddress, "accounts/profile"),
};
requestMessage.Headers.Add("Authorization", $"Bearer3 {TokenService.Instance.AccessToken}");
try
{
var response = await ApiClient.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<ProfileResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<ProfileResponse>(responseContent);
return ApiResult<ProfileResponse>.Success(responseObj, response.StatusCode);
}
catch
{
return HandledWebException<ProfileResponse>();
}
}
protected ApiResult HandledWebException()
{
return ApiResult.Failed(HttpStatusCode.BadGateway,

Loading…
Cancel
Save