Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit c44b855

Browse files
committed
small changes
# Conflicts: # src/Backend/Jp.Infra.CrossCutting.Database/DbSettingsConfig.cs # src/Backend/Jp.UserManagement/Jp.Management.csproj # src/Backend/Jp.UserManagement/appsettings.json # src/Frontend/Jp.UI.SSO/Controllers/Account/LegacyController.cs # src/Frontend/Jp.UI.SSO/appsettings.json
1 parent 21df418 commit c44b855

14 files changed

Lines changed: 63 additions & 21 deletions

File tree

src/Backend/Jp.Application/Services/UserManagerAppService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
using Jp.Domain.Commands.User;
88
using Jp.Domain.Commands.UserManagement;
99
using Jp.Domain.Core.Bus;
10+
using Jp.Domain.Core.ViewModels;
1011
using Jp.Domain.Interfaces;
1112
using System;
1213
using System.Collections.Generic;
1314
using System.Linq;
1415
using System.Threading.Tasks;
15-
using Jp.Domain.Core.ViewModels;
1616

1717
namespace Jp.Application.Services
1818
{

src/Backend/Jp.Application/ViewModels/UserViewModels/UserViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.ComponentModel.DataAnnotations;
34

45
namespace Jp.Application.ViewModels.UserViewModels
@@ -27,6 +28,8 @@ public class UserViewModel
2728
public string Company { get; set; }
2829
public string Bio { get; set; }
2930
public string JobTitle { get; set; }
31+
32+
[JsonIgnore]
3033
public Guid Id { get; set; }
3134
public bool EmailConfirmed { get; set; }
3235
public bool PhoneNumberConfirmed { get; set; }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace Jp.Domain.Core.StringUtils
4+
{
5+
public static class StringExtensions
6+
{
7+
public static bool IsEmail(this string username)
8+
{
9+
// Return true if strIn is in valid e-mail format.
10+
return Regex.IsMatch(username, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
11+
}
12+
13+
}
14+
}

src/Backend/Jp.Domain/CommandHandlers/UserCommandHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public async Task<bool> Handle(RegisterNewUserWithoutPassCommand request, Cancel
7777
if (!request.IsValid())
7878
{
7979
NotifyValidationErrors(request);
80-
return false; ;
80+
return false;
8181
}
8282

8383
var user = new User(
@@ -142,7 +142,7 @@ public async Task<bool> Handle(SendResetLinkCommand request, CancellationToken c
142142
if (!request.IsValid())
143143
{
144144
NotifyValidationErrors(request);
145-
return false; ;
145+
return false;
146146
}
147147

148148
var emailSent = await _userService.SendResetLink(request.Email, request.Username);
@@ -160,7 +160,7 @@ public async Task<bool> Handle(ResetPasswordCommand request, CancellationToken c
160160
if (!request.IsValid())
161161
{
162162
NotifyValidationErrors(request);
163-
return false; ;
163+
return false;
164164
}
165165

166166
var emailSent = await _userService.ResetPassword(request);
@@ -178,7 +178,7 @@ public async Task<bool> Handle(ConfirmEmailCommand request, CancellationToken ca
178178
if (!request.IsValid())
179179
{
180180
NotifyValidationErrors(request);
181-
return false; ;
181+
return false;
182182
}
183183

184184
var result = await _userService.ConfirmEmailAsync(request.Email, request.Code);
@@ -195,7 +195,7 @@ public async Task<bool> Handle(AddLoginCommand request, CancellationToken cancel
195195
if (!request.IsValid())
196196
{
197197
NotifyValidationErrors(request);
198-
return false; ;
198+
return false;
199199
}
200200

201201
var result = await _userService.AddLoginAsync(request.Email, request.Provider, request.ProviderId);

src/Backend/Jp.Infra.CrossCutting.Database/DbSettingsConfig.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public static void AddIdentityConfiguration(this IServiceCollection services, IC
3838
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Name;
3939
options.SignIn.RequireConfirmedAccount = true;
4040
options.User.RequireUniqueEmail = true;
41-
42-
// NIST Password best practices: https://pages.nist.gov/800-63-3/sp800-63b.html#appA
41+
42+
// NIST Password best practices: https://pages.nist.gov/800-63-3/sp800-63b.html#appA
4343
options.Lockout.MaxFailedAccessAttempts = 10;
4444
options.Password.RequiredLength = 8;
4545
options.Password.RequireDigit = false;
@@ -50,6 +50,8 @@ public static void AddIdentityConfiguration(this IServiceCollection services, IC
5050
options.Password.RequiredUniqueChars = 0;
5151

5252
})
53+
54+
5355
.AddEntityFrameworkStores<ApplicationIdentityContext>();
5456
}
5557

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace Jp.Infra.CrossCutting.Tools.StringUtils
4+
{
5+
public static class StringExtensions
6+
{
7+
public static bool IsEmail(this string username)
8+
{
9+
// Return true if strIn is in valid e-mail format.
10+
return Regex.IsMatch(username, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
11+
}
12+
13+
}
14+
}

src/Backend/Jp.UserManagement/Controllers/UserAdminController.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
using Jp.Application.ViewModels.UserViewModels;
66
using Jp.Domain.Core.Bus;
77
using Jp.Domain.Core.Notifications;
8+
using Jp.Domain.Core.ViewModels;
89
using Jp.Domain.Interfaces;
910
using Jp.Infra.CrossCutting.Tools.Model;
1011
using MediatR;
1112
using Microsoft.AspNetCore.Authorization;
13+
using Microsoft.AspNetCore.JsonPatch;
1214
using Microsoft.AspNetCore.Mvc;
1315
using System.Collections.Generic;
1416
using System.ComponentModel.DataAnnotations;
1517
using System.Threading.Tasks;
16-
using Jp.Domain.Core.ViewModels;
1718

1819
namespace Jp.Management.Controllers
1920
{
@@ -22,17 +23,19 @@ public class UserAdminController : ApiController
2223
{
2324
private readonly IUserManageAppService _userManageAppService;
2425
private readonly ISystemUser _user;
26+
private readonly IUserAppService _userAppService;
2527

2628
public UserAdminController(
2729
INotificationHandler<DomainNotification> notifications,
2830
IMediatorHandler mediator,
2931
IUserManageAppService userManageAppService,
3032
ISystemUser user,
31-
IRoleManagerAppService roleManagerAppService) : base(notifications, mediator)
33+
IUserAppService userAppService) : base(notifications, mediator)
3234
{
3335

3436
_userManageAppService = userManageAppService;
3537
_user = user;
38+
_userAppService = userAppService;
3639
}
3740

3841
/// <summary>
@@ -56,15 +59,18 @@ public async Task<ActionResult<DefaultResponse<UserViewModel>>> Details(string u
5659
}
5760

5861

59-
[HttpPut, Route("update"), Authorize(Policy = "Admin")]
60-
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] UserViewModel model)
62+
[HttpPatch, Route("{username}/update"), Authorize(Policy = "Admin")]
63+
public async Task<ActionResult<DefaultResponse<bool>>> Update(string username, [FromBody] JsonPatchDocument<UserViewModel> model)
6164
{
6265
if (!ModelState.IsValid)
6366
{
6467
NotifyModelStateErrors();
6568
return ModelStateErrorResponseError();
6669
}
67-
await _userManageAppService.UpdateUser(model);
70+
71+
var actualUser = await _userAppService.FindByNameAsync(username);
72+
model.ApplyTo(actualUser);
73+
await _userManageAppService.UpdateUser(actualUser);
6874
return Response(true);
6975
}
7076

src/Backend/Jp.UserManagement/Jp.Management.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
1616
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
1717
<PackageReference Include="Serilog.AspNetCore" Version="3.0.1-dev-00116" />
18+
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="3.0.0" />
1819
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.0.4" />
1920
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
2021
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />

src/Frontend/Jp.AdminUI/src/app/shared/services/user.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ export class UserService {
3939

4040
return this.http.put<DefaultResponse<boolean>>(environment.ResourceServer + "UserAdmin/update", updateCommand);
4141
}
42-
public save(model: UserProfile): Observable<DefaultResponse<boolean>> {
42+
43+
public patch(updateCommand: UserProfile): Observable<DefaultResponse<boolean>> {
44+
return this.http.patch<DefaultResponse<boolean>>(environment.ResourceServer + "UserAdmin/update", updateCommand);
45+
}
4346

47+
public save(model: UserProfile): Observable<DefaultResponse<boolean>> {
4448
return this.http.post<DefaultResponse<boolean>>(environment.ResourceServer + "User/register", model);
4549
}
4650

src/Frontend/Jp.UI.SSO/Models/LoginInputModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44

5+
using Jp.Infra.CrossCutting.Tools.StringUtils;
56
using System.ComponentModel.DataAnnotations;
6-
using System.Text.RegularExpressions;
77

88
namespace Jp.UI.SSO.Models
99
{
@@ -19,7 +19,7 @@ public class LoginInputModel
1919
public bool IsUsernameEmail()
2020
{
2121
// Return true if strIn is in valid e-mail format.
22-
return Regex.IsMatch(Username, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
22+
return Username.IsEmail();
2323
}
2424
}
2525
}

0 commit comments

Comments
 (0)