Fixed the user management #865

pull/1425/head
Jamie.Rees 7 years ago
parent 3879fc04de
commit 5ac0e4c68a

@ -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<UserDto> CreateUser(UserDto userDto)
{
var user = Mapper.Map<User>(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;

@ -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("}")));
}
}
}

@ -21,7 +21,7 @@ namespace Ombi.Mapping.Profiles
CreateMap<UserDto, UserViewModel>().ForMember(x => x.Password, opt => opt.Ignore());
CreateMap<ClaimCheckboxes, Claim>()
.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<string> claims => UserDto List<claim>
CreateMap<UserViewModel, UserDto>();

@ -108,4 +108,8 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\app\settings\NewFolder\" />
</ItemGroup>
</Project>

@ -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,

@ -109,8 +109,8 @@
<div *ngFor="let c of selectedUser.claims">
<div class="form-group">
<div class="checkbox">
<label for="claim{{c.value}}">{{c.value}}</label>
<input type="checkbox" [(ngModel)]="c.enabled" [value]="c.value" [checked]="c.value" id="claim{{c.value}}" name="claim{{c.value}}" ng-checked="c.enabled">
<input type="checkbox" [(ngModel)]="c.enabled" [value]="c.value" id="create{{c.value}}" [attr.name]="'create' + c.value" ng-checked="c.enabled">
<label for="create{{c.value}}">{{c.value}}</label>
</div>
</div>
@ -127,6 +127,8 @@
</div>
</div>
<div>
<div class="modal fade in " *ngIf="showCreateDialogue" style="display: block;">
<div class="modal-dialog">
@ -167,9 +169,8 @@
<div *ngFor="let c of availableClaims">
<div class="form-group">
<div class="checkbox">
<input type="checkbox" [(ngModel)]="c.enabled" [value]="c.value" id="create{{c.value}}" [attr.name]="'create' + c.value" ng-checked="c.enabled">
<label for="create{{c.value}}">{{c.value}}</label>
<input type="checkbox" [(ngModel)]="c.enabled" [value]="c.value" [checked]="c.value" id="create{{c.value}}" name="create{{c.value}}" ng-checked="c.enabled">
</div>
</div>
</div>

Loading…
Cancel
Save