From 5ac0e4c68a005102e53495f8e9e998b8d5cd76c8 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Mon, 15 May 2017 16:14:37 +0100 Subject: [PATCH] Fixed the user management #865 --- .../IdentityResolver/UserIdentityManager.cs | 2 ++ Ombi/Ombi.Helpers/ClaimConverter.cs | 25 ++++++++++++++----- Ombi/Ombi.Mapping/Profiles/OmbiProfile.cs | 2 +- Ombi/Ombi/Ombi.csproj | 4 +++ Ombi/Ombi/wwwroot/app/app.module.ts | 6 +++-- .../usermanagement.component.html | 9 ++++--- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Ombi/Ombi.Core/IdentityResolver/UserIdentityManager.cs b/Ombi/Ombi.Core/IdentityResolver/UserIdentityManager.cs index 46197ab27..fa3220e15 100644 --- a/Ombi/Ombi.Core/IdentityResolver/UserIdentityManager.cs +++ b/Ombi/Ombi.Core/IdentityResolver/UserIdentityManager.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Security.Claims; using System.Security.Cryptography; using System.Threading.Tasks; using AutoMapper; @@ -71,6 +72,7 @@ namespace Ombi.Core.IdentityResolver public async Task CreateUser(UserDto userDto) { var user = Mapper.Map(userDto); + user.Claims.RemoveAll(x => x.Type == ClaimTypes.Country); // This is a hack around the Mapping Profile var result = HashPassword(user.Password); user.Password = result.HashedPass; user.Salt = result.Salt; diff --git a/Ombi/Ombi.Helpers/ClaimConverter.cs b/Ombi/Ombi.Helpers/ClaimConverter.cs index d8603b9a4..09237c8ce 100644 --- a/Ombi/Ombi.Helpers/ClaimConverter.cs +++ b/Ombi/Ombi.Helpers/ClaimConverter.cs @@ -9,25 +9,38 @@ namespace Ombi.Helpers { public override bool CanConvert(Type objectType) { - return (objectType == typeof(Claim)); + return (objectType == typeof(System.Security.Claims.Claim)); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var claim = (System.Security.Claims.Claim)value; + JObject jo = new JObject(); + jo.Add("Type", claim.Type); + jo.Add("Value", IsJson(claim.Value) ? new JRaw(claim.Value) : new JValue(claim.Value)); + jo.Add("ValueType", claim.ValueType); + jo.Add("Issuer", claim.Issuer); + jo.Add("OriginalIssuer", claim.OriginalIssuer); + jo.WriteTo(writer); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jo = JObject.Load(reader); string type = (string)jo["Type"]; - string value = (string)jo["Value"]; + JToken token = jo["Value"]; + string value = token.Type == JTokenType.String ? (string)token : token.ToString(Formatting.None); string valueType = (string)jo["ValueType"]; string issuer = (string)jo["Issuer"]; string originalIssuer = (string)jo["OriginalIssuer"]; return new Claim(type, value, valueType, issuer, originalIssuer); } - public override bool CanWrite => false; - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + private bool IsJson(string val) { - throw new NotImplementedException(); + return (val != null && + (val.StartsWith("[") && val.EndsWith("]")) || + (val.StartsWith("{") && val.EndsWith("}"))); } } } \ No newline at end of file diff --git a/Ombi/Ombi.Mapping/Profiles/OmbiProfile.cs b/Ombi/Ombi.Mapping/Profiles/OmbiProfile.cs index c64e61587..8b6d4f058 100644 --- a/Ombi/Ombi.Mapping/Profiles/OmbiProfile.cs +++ b/Ombi/Ombi.Mapping/Profiles/OmbiProfile.cs @@ -21,7 +21,7 @@ namespace Ombi.Mapping.Profiles CreateMap().ForMember(x => x.Password, opt => opt.Ignore()); CreateMap() - .ConstructUsing(checkbox => checkbox.Enabled ? new Claim(ClaimTypes.Role, checkbox.Value) : null); + .ConstructUsing(checkbox => checkbox.Enabled ? new Claim(ClaimTypes.Role, checkbox.Value) : new Claim(ClaimTypes.Country, "")); // This is used for the UserViewModel List claims => UserDto List CreateMap(); diff --git a/Ombi/Ombi/Ombi.csproj b/Ombi/Ombi/Ombi.csproj index ceadebd0e..2a9ef2471 100644 --- a/Ombi/Ombi/Ombi.csproj +++ b/Ombi/Ombi/Ombi.csproj @@ -108,4 +108,8 @@ PreserveNewest + + + + diff --git a/Ombi/Ombi/wwwroot/app/app.module.ts b/Ombi/Ombi/wwwroot/app/app.module.ts index c3c05128b..372ef173a 100644 --- a/Ombi/Ombi/wwwroot/app/app.module.ts +++ b/Ombi/Ombi/wwwroot/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule } from '@angular/core'; +import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { FormsModule } from '@angular/forms'; @@ -28,6 +28,7 @@ import { LoginComponent } from './login/login.component'; import { LandingPageComponent } from './landingpage/landingpage.component'; import { UserManagementComponent } from './usermanagement/usermanagement.component'; import { PageNotFoundComponent } from './errors/not-found.component'; +import { UserModalComponent } from './usermanagement/usermodal.component'; // Services import { SearchService } from './services/search.service'; @@ -91,7 +92,8 @@ const routes: Routes = [ UserManagementComponent, MovieRequestsComponent, TvRequestsComponent, - SeriesInformationComponent + SeriesInformationComponent, + UserModalComponent, ], providers: [ SearchService, diff --git a/Ombi/Ombi/wwwroot/app/usermanagement/usermanagement.component.html b/Ombi/Ombi/wwwroot/app/usermanagement/usermanagement.component.html index 8afc22723..e2bc635a2 100644 --- a/Ombi/Ombi/wwwroot/app/usermanagement/usermanagement.component.html +++ b/Ombi/Ombi/wwwroot/app/usermanagement/usermanagement.component.html @@ -109,8 +109,8 @@
- - + +
@@ -127,6 +127,8 @@
+ +