fix/whatervberve ()

add subjects

fix normal student login

Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
maxchil 2020-11-08 00:05:48 +01:00
parent 05fde36f41
commit 42e3cb01f4
5 changed files with 53 additions and 12 deletions

View File

@ -44,6 +44,7 @@ namespace InternshipSystem.Api.Controllers
.Include(i => i.InternshipRegistration.Company) .Include(i => i.InternshipRegistration.Company)
.Include(i => i.InternshipRegistration.BranchAddress) .Include(i => i.InternshipRegistration.BranchAddress)
.Include(i => i.InternshipRegistration.Type) .Include(i => i.InternshipRegistration.Type)
.Include(i => i.InternshipRegistration.Subjects)
.Include(i => i.Report) .Include(i => i.Report)
.Include(i => i.Documentation) .Include(i => i.Documentation)
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); .SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace InternshipSystem.Api.Converters
{
public class StringArrayConverter<TItem> : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var token = JToken.Load(reader);
if (token.Type == JTokenType.Array)
{
return token.ToObject<List<TItem>>();
}
return new List<TItem>
{
token.ToObject<TItem>()
};
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(List<TItem>);
}
public override bool CanWrite => false;
}
}

View File

@ -1,11 +1,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using InternshipSystem.Api.Options; using InternshipSystem.Api.Options;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using JsonConverter = System.Text.Json.Serialization.JsonConverter;
namespace InternshipSystem.Api.Controllers namespace InternshipSystem.Api.Controllers
{ {
@ -39,9 +41,9 @@ namespace InternshipSystem.Api.Controllers
}; };
var response = await _client.SendAsync(request, cancellationToken); var response = await _client.SendAsync(request, cancellationToken);
await using var stream = await response.Content.ReadAsStreamAsync(); var content = await response.Content.ReadAsStringAsync();
var value = await JsonSerializer.DeserializeAsync<Dictionary<string, object>>(stream); var value = JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
return value["access_token"].ToString(); return value["access_token"].ToString();
} }
@ -60,15 +62,10 @@ namespace InternshipSystem.Api.Controllers
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await _client.SendAsync(request, cancellationToken); var response = await _client.SendAsync(request, cancellationToken);
await using var stream = await response.Content.ReadAsStreamAsync(); var content = await response.Content.ReadAsStringAsync();
var result = await JsonSerializer.DeserializeAsync<CasUserProfile>(
stream,
new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
var result = JsonConvert.DeserializeObject<CasUserProfile>(content);
return result.Attributes; return result.Attributes;
} }
} }

View File

@ -18,7 +18,7 @@
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" /> <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.6.3"/> <PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.6.3" />
<PackageReference Include="IdentityServer4" Version="3.1.4" /> <PackageReference Include="IdentityServer4" Version="3.1.4" />
</ItemGroup> </ItemGroup>

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using InternshipSystem.Api.Converters;
using Newtonsoft.Json;
namespace InternshipSystem.Api.Controllers namespace InternshipSystem.Api.Controllers
{ {
@ -7,8 +9,12 @@ namespace InternshipSystem.Api.Controllers
public string AlbumNumber { get; set; } public string AlbumNumber { get; set; }
public string FirstName { get; set; } public string FirstName { get; set; }
public string LastName { get; set; } public string LastName { get; set; }
[JsonConverter(typeof(StringArrayConverter<string>))]
public List<string> Mail { get; set; } public List<string> Mail { get; set; }
public string PersonNumber { get; set; } public string PersonNumber { get; set; }
[JsonConverter(typeof(StringArrayConverter<string>))]
public List<string> Pg_Cui_Portalroles { get; set; } public List<string> Pg_Cui_Portalroles { get; set; }
} }
} }