fix register user

This commit is contained in:
Przemysław Stawujak 2018-12-29 16:52:21 +01:00
parent b8d56680a5
commit 2fc97f469c
2 changed files with 28 additions and 1 deletions

View File

@ -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<User, long> _userRepository;
public AccountAppService(
UserRegistrationManager userRegistrationManager)
UserRegistrationManager userRegistrationManager,
IRepository<User, long> userRepository)
{
_userRegistrationManager = userRegistrationManager;
_userRepository = userRepository;
}
public async Task<IsTenantAvailableOutput> IsTenantAvailable(IsTenantAvailableInput input)
@ -34,6 +40,26 @@ namespace SystemKonkursow.Authorization.Accounts
public async Task<RegisterOutput> 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,

View File

@ -34,6 +34,7 @@
<text name="DefaultPasswordIs" value="Default password is {0}" />
<text name="CanBeEmptyToLoginAsHost" value="Can be empty to login as host." />
<text name="Register" value="Register" />
<text name="RegisterFailed" value="Błąd rejestracji!" />
<text name="OrLoginWith" value="Or login with" />
<text name="WaitingForActivationMessage" value="Your account is waiting to be activated by system admin." />
<text name="TenantSelection" value="Tenant Selection" />