From 2fc97f469c0a2f39fd769db65d999b32ec4000d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Stawujak?= Date: Sat, 29 Dec 2018 16:52:21 +0100 Subject: [PATCH] fix register user --- .../Accounts/AccountAppService.cs | 28 ++++++++++++++++++- .../SourceFiles/SystemKonkursow.xml | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Authorization/Accounts/AccountAppService.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Authorization/Accounts/AccountAppService.cs index c3b2582..50ff768 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Authorization/Accounts/AccountAppService.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Authorization/Accounts/AccountAppService.cs @@ -1,5 +1,8 @@ +using System.Linq; using System.Threading.Tasks; using Abp.Configuration; +using Abp.Domain.Repositories; +using Abp.UI; using Abp.Zero.Configuration; using SystemKonkursow.Authorization.Accounts.Dto; using SystemKonkursow.Authorization.Users; @@ -9,11 +12,14 @@ namespace SystemKonkursow.Authorization.Accounts public class AccountAppService : SystemKonkursowAppServiceBase, IAccountAppService { private readonly UserRegistrationManager _userRegistrationManager; + private readonly IRepository _userRepository; public AccountAppService( - UserRegistrationManager userRegistrationManager) + UserRegistrationManager userRegistrationManager, + IRepository userRepository) { _userRegistrationManager = userRegistrationManager; + _userRepository = userRepository; } public async Task IsTenantAvailable(IsTenantAvailableInput input) @@ -34,6 +40,26 @@ namespace SystemKonkursow.Authorization.Accounts public async Task Register(RegisterInput input) { + + var checkUserEmail = _userRepository.GetAll().Where(t => t.EmailAddress == input.EmailAddress).FirstOrDefault(); + + var checkUserName = _userRepository.GetAll().Where(t => t.UserName == input.UserName).FirstOrDefault(); + + if (null != checkUserEmail && null != checkUserName) + { + throw new UserFriendlyException(L("RegisterFailed"), string.Format("Użytkownik o adresie email: {0} i nazwie użytkownika: {1} już istnieje", input.EmailAddress, input.UserName)); + } + + if (null != checkUserEmail) + { + throw new UserFriendlyException(L("RegisterFailed"), string.Format("Użytkownik o adresie email: {0} już istnieje", input.EmailAddress)); + } + + if (null != checkUserName) + { + throw new UserFriendlyException(L("RegisterFailed"), string.Format("Użytkownik o nazwie użytkownika: {0} już istnieje", input.UserName)); + } + var user = await _userRegistrationManager.RegisterAsync( input.Name, input.Surname, diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Localization/SourceFiles/SystemKonkursow.xml b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Localization/SourceFiles/SystemKonkursow.xml index 3907e00..3ee589a 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Localization/SourceFiles/SystemKonkursow.xml +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Localization/SourceFiles/SystemKonkursow.xml @@ -34,6 +34,7 @@ +