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

Commit 4cb57d3

Browse files
committed
Merge branch 'dev'
2 parents c9176a5 + a020ba1 commit 4cb57d3

File tree

52 files changed

+545
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+545
-170
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# v1.2.2
22

33
Added ENV for Default User and Pass, to autofill Login Page. Specially made for Dev and Docker environments
4+
Changed all Configurations to respect inheritance from IConfiguration
5+
When a registered user login through another external provider, eg google or facebook, then add new login instead try to register it again.
46

57
# v1.2.1
68

build/docker-compose.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ services:
2727
depends_on:
2828
- jpdatabase
2929
environment:
30-
DATABASE_TYPE: "MySql"
31-
CUSTOMCONNSTR_DATABASE_CONNECTION: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
32-
ASPNETCORE_ENVIRONMENT: "Development"
30+
ASPNETCORE_ENVIRONMENT: Development
3331
ASPNETCORE_URLS: http://+:5000
34-
DEFAULT_USER: bruno
35-
DEFAULT_PASS: Pa$$word123
36-
DEFAULT_EMAIL: [email protected]
32+
CUSTOMCONNSTR_SSOConnection: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
33+
ApplicationSettings:EnableExternalProviders: "false" # Because Auth url is http://jpproject (modified by host to point to 127.0.0.1), then Google and Facebook reject it.
34+
ApplicationSettings:DatabaseType: MySql
35+
ApplicationSettings:DefaultUser: bruno
36+
ApplicationSettings:DefaultPass: Pa$$word123
37+
ApplicationSettings:DefaultEmail: [email protected]
38+
ApplicationSettings:UserManagementURL: http://localhost:4200
39+
ApplicationSettings:IS4AdminUi: http://localhost:4300
3740

3841
# #############################
3942
# # Management API
@@ -45,11 +48,11 @@ services:
4548
depends_on:
4649
- jpdatabase
4750
environment:
48-
DATABASE_TYPE: "MySql"
49-
CUSTOMCONNSTR_DATABASE_CONNECTION: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
5051
ASPNETCORE_ENVIRONMENT: "Development"
51-
AUTHORITY: "http://jpproject:5000"
5252
ASPNETCORE_URLS: http://+
53+
CUSTOMCONNSTR_SSOConnection: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
54+
ApplicationSettings:Authority: "http://jpproject:5000"
55+
ApplicationSettings:DatabaseType: MySql
5356

5457
#############################
5558
# User management UI

build/jpproject-docker-windows.zip

148 Bytes
Binary file not shown.

docker-compose.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ services:
3030
depends_on:
3131
- jpdatabase
3232
environment:
33-
DATABASE_TYPE: "MySql"
34-
CUSTOMCONNSTR_DATABASE_CONNECTION: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
35-
ASPNETCORE_ENVIRONMENT: "Development"
33+
ASPNETCORE_ENVIRONMENT: Development
3634
ASPNETCORE_URLS: http://+:5000
37-
DEFAULT_USER: bruno
38-
DEFAULT_PASS: Pa$$word123
39-
DEFAULT_EMAIL: [email protected]
35+
CUSTOMCONNSTR_SSOConnection: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
36+
ApplicationSettings:EnableExternalProviders: "false" # Because Auth url is http://jpproject (modified by host to point to 127.0.0.1), then Google and Facebook reject it.
37+
ApplicationSettings:DatabaseType: MySql
38+
ApplicationSettings:DefaultUser: bruno
39+
ApplicationSettings:DefaultPass: Pa$$word123
40+
ApplicationSettings:DefaultEmail: [email protected]
41+
ApplicationSettings:UserManagementURL: http://localhost:4200
42+
ApplicationSettings:IS4AdminUi: http://localhost:4300
43+
CertificateOptions:Type: Temporary
4044

4145
# #############################
4246
# # Management API
@@ -51,11 +55,11 @@ services:
5155
depends_on:
5256
- jpdatabase
5357
environment:
54-
DATABASE_TYPE: "MySql"
55-
CUSTOMCONNSTR_DATABASE_CONNECTION: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
5658
ASPNETCORE_ENVIRONMENT: "Development"
57-
AUTHORITY: "http://jpproject:5000"
5859
ASPNETCORE_URLS: http://+
60+
CUSTOMCONNSTR_SSOConnection: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
61+
ApplicationSettings:Authority: "http://jpproject:5000"
62+
ApplicationSettings:DatabaseType: MySql
5963

6064
#############################
6165
# User management UI

src/Backend/Jp.Application/AutoMapper/ViewModelToDomainMappingProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public ViewModelToDomainMappingProfile()
3434
CreateMap<ForgotPasswordViewModel, SendResetLinkCommand>().ConstructUsing(c => new SendResetLinkCommand(c.UsernameOrEmail, c.UsernameOrEmail));
3535
CreateMap<ResetPasswordViewModel, ResetPasswordCommand>().ConstructUsing(c => new ResetPasswordCommand(c.Password, c.ConfirmPassword, c.Code, c.Email));
3636
CreateMap<ConfirmEmailViewModel, ConfirmEmailCommand>().ConstructUsing(c => new ConfirmEmailCommand(c.Code, c.Email));
37+
CreateMap<SocialViewModel, AddLoginCommand>().ConstructUsing(c => new AddLoginCommand(c.Email, c.Provider, c.ProviderId));
3738

3839
/*
3940
* User Management commands

src/Backend/Jp.Application/Interfaces/IUserAppService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ public interface IUserAppService : IDisposable
1919
Task<UserViewModel> FindByNameAsync(string username);
2020
Task<UserViewModel> FindByEmailAsync(string username);
2121
Task<UserViewModel> FindByProviderAsync(string provider, string providerUserId);
22+
Task AddLogin(SocialViewModel user);
2223
}
2324
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public async Task<UserViewModel> FindByProviderAsync(string provider, string pro
8282
return _mapper.Map<UserViewModel>(user);
8383
}
8484

85+
public Task AddLogin(SocialViewModel model)
86+
{
87+
var registerCommand = _mapper.Map<AddLoginCommand>(model);
88+
return Bus.SendCommand(registerCommand);
89+
}
90+
8591
public Task<bool> CheckUsername(string userName)
8692
{
8793
return _userService.UsernameExist(userName);
@@ -98,8 +104,6 @@ public async Task<RegisterUserViewModel> FindByLoginAsync(string provider, strin
98104
return _mapper.Map<RegisterUserViewModel>(model);
99105
}
100106

101-
102-
103107
public void Dispose()
104108
{
105109
GC.SuppressFinalize(this);

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class UserCommandHandler : CommandHandler,
1717
IRequestHandler<RegisterNewUserWithProviderCommand, bool>,
1818
IRequestHandler<SendResetLinkCommand, bool>,
1919
IRequestHandler<ResetPasswordCommand, bool>,
20-
IRequestHandler<ConfirmEmailCommand, bool>
20+
IRequestHandler<ConfirmEmailCommand, bool>,
21+
IRequestHandler<AddLoginCommand, bool>
2122
{
2223
private readonly IUserService _userService;
2324

@@ -47,6 +48,21 @@ public async Task<bool> Handle(RegisterNewUserCommand request, CancellationToken
4748
phoneNumber: request.PhoneNumber,
4849
picture: request.Picture
4950
);
51+
52+
var emailAlreadyExist = await _userService.FindByEmailAsync(user.Email);
53+
if (emailAlreadyExist != null)
54+
{
55+
await Bus.RaiseEvent(new DomainNotification("1001", "E-mail already exist. If you don't remember your passwork, reset it."));
56+
return false;
57+
}
58+
var usernameAlreadyExist = await _userService.FindByNameAsync(user.UserName);
59+
60+
if (usernameAlreadyExist != null)
61+
{
62+
await Bus.RaiseEvent(new DomainNotification("1002", "Username already exist. If you don't remember your passwork, reset it."));
63+
return false;
64+
}
65+
5066
var id = await _userService.CreateUserWithPass(user, request.Password);
5167
if (id.HasValue)
5268
{
@@ -72,6 +88,21 @@ public async Task<bool> Handle(RegisterNewUserWithoutPassCommand request, Cancel
7288
phoneNumber: request.PhoneNumber,
7389
picture: request.Picture
7490
);
91+
92+
var emailAlreadyExist = await _userService.FindByEmailAsync(user.Email);
93+
if (emailAlreadyExist != null)
94+
{
95+
await Bus.RaiseEvent(new DomainNotification("1001", "E-mail already exist. If you don't remember your passwork, reset it."));
96+
return false;
97+
}
98+
var usernameAlreadyExist = await _userService.FindByNameAsync(user.UserName);
99+
100+
if (usernameAlreadyExist != null)
101+
{
102+
await Bus.RaiseEvent(new DomainNotification("1002", "Username already exist. If you don't remember your passwork, reset it."));
103+
return false;
104+
}
105+
75106
var id = await _userService.CreateUserWithProvider(user, request.Provider, request.ProviderId);
76107
if (id.HasValue)
77108
{
@@ -159,6 +190,22 @@ public async Task<bool> Handle(ConfirmEmailCommand request, CancellationToken ca
159190
return false;
160191
}
161192

193+
public async Task<bool> Handle(AddLoginCommand request, CancellationToken cancellationToken)
194+
{
195+
if (!request.IsValid())
196+
{
197+
NotifyValidationErrors(request);
198+
return false; ;
199+
}
200+
201+
var result = await _userService.AddLoginAsync(request.Email, request.Provider, request.ProviderId);
202+
if (result.HasValue)
203+
{
204+
await Bus.RaiseEvent(new NewLoginAddedEvent(result.Value, request.Email, request.Provider, request.ProviderId));
205+
return true;
206+
}
207+
return false;
208+
}
162209
}
163210

164211

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Jp.Domain.Validations.User;
2+
3+
namespace Jp.Domain.Commands.User
4+
{
5+
public class AddLoginCommand : UserCommand
6+
{
7+
8+
public AddLoginCommand(string email, string provider, string providerId)
9+
{
10+
Provider = provider;
11+
ProviderId = providerId;
12+
Email = email;
13+
}
14+
15+
public override bool IsValid()
16+
{
17+
ValidationResult = new AddLoginCommandValidation().Validate(this);
18+
return ValidationResult.IsValid;
19+
}
20+
}
21+
}

src/Backend/Jp.Domain/Commands/User/ConfirmEmailCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace Jp.Domain.Commands.User
44
{
55
public class ConfirmEmailCommand : UserCommand
66
{
7-
public string Code { get; }
87

98
public ConfirmEmailCommand(string code, string email)
109
{

0 commit comments

Comments
 (0)