-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #674 from aspnetboilerplate/upgrade-to-abp-10.0-an…
…d-dotnet-9 Upgrade to ABP 10.0 and .NET 9
- Loading branch information
Showing
204 changed files
with
6,631 additions
and
6,873 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 31 additions & 32 deletions
63
aspnet-core/src/AbpCompanyName.AbpProjectName.Application/AbpProjectNameAppServiceBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,46 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Identity; | ||
using Abp.Application.Services; | ||
using Abp.Application.Services; | ||
using Abp.IdentityFramework; | ||
using Abp.Runtime.Session; | ||
using AbpCompanyName.AbpProjectName.Authorization.Users; | ||
using AbpCompanyName.AbpProjectName.MultiTenancy; | ||
using Microsoft.AspNetCore.Identity; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace AbpCompanyName.AbpProjectName; | ||
|
||
namespace AbpCompanyName.AbpProjectName | ||
/// <summary> | ||
/// Derive your application services from this class. | ||
/// </summary> | ||
public abstract class AbpProjectNameAppServiceBase : ApplicationService | ||
{ | ||
/// <summary> | ||
/// Derive your application services from this class. | ||
/// </summary> | ||
public abstract class AbpProjectNameAppServiceBase : ApplicationService | ||
{ | ||
public TenantManager TenantManager { get; set; } | ||
public TenantManager TenantManager { get; set; } | ||
|
||
public UserManager UserManager { get; set; } | ||
public UserManager UserManager { get; set; } | ||
|
||
protected AbpProjectNameAppServiceBase() | ||
{ | ||
LocalizationSourceName = AbpProjectNameConsts.LocalizationSourceName; | ||
} | ||
protected AbpProjectNameAppServiceBase() | ||
{ | ||
LocalizationSourceName = AbpProjectNameConsts.LocalizationSourceName; | ||
} | ||
|
||
protected virtual async Task<User> GetCurrentUserAsync() | ||
protected virtual async Task<User> GetCurrentUserAsync() | ||
{ | ||
var user = await UserManager.FindByIdAsync(AbpSession.GetUserId().ToString()); | ||
if (user == null) | ||
{ | ||
var user = await UserManager.FindByIdAsync(AbpSession.GetUserId().ToString()); | ||
if (user == null) | ||
{ | ||
throw new Exception("There is no current user!"); | ||
} | ||
|
||
return user; | ||
throw new Exception("There is no current user!"); | ||
} | ||
|
||
protected virtual Task<Tenant> GetCurrentTenantAsync() | ||
{ | ||
return TenantManager.GetByIdAsync(AbpSession.GetTenantId()); | ||
} | ||
return user; | ||
} | ||
|
||
protected virtual void CheckErrors(IdentityResult identityResult) | ||
{ | ||
identityResult.CheckErrors(LocalizationManager); | ||
} | ||
protected virtual Task<Tenant> GetCurrentTenantAsync() | ||
{ | ||
return TenantManager.GetByIdAsync(AbpSession.GetTenantId()); | ||
} | ||
|
||
protected virtual void CheckErrors(IdentityResult identityResult) | ||
{ | ||
identityResult.CheckErrors(LocalizationManager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 49 additions & 50 deletions
99
...e/src/AbpCompanyName.AbpProjectName.Application/Authorization/AbpLoginResultTypeHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,63 @@ | ||
using System; | ||
using Abp; | ||
using Abp; | ||
using Abp.Authorization; | ||
using Abp.Dependency; | ||
using Abp.UI; | ||
using System; | ||
|
||
namespace AbpCompanyName.AbpProjectName.Authorization | ||
namespace AbpCompanyName.AbpProjectName.Authorization; | ||
|
||
public class AbpLoginResultTypeHelper : AbpServiceBase, ITransientDependency | ||
{ | ||
public class AbpLoginResultTypeHelper : AbpServiceBase, ITransientDependency | ||
public AbpLoginResultTypeHelper() | ||
{ | ||
public AbpLoginResultTypeHelper() | ||
{ | ||
LocalizationSourceName = AbpProjectNameConsts.LocalizationSourceName; | ||
} | ||
LocalizationSourceName = AbpProjectNameConsts.LocalizationSourceName; | ||
} | ||
|
||
public Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName) | ||
public Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName) | ||
{ | ||
switch (result) | ||
{ | ||
switch (result) | ||
{ | ||
case AbpLoginResultType.Success: | ||
return new Exception("Don't call this method with a success result!"); | ||
case AbpLoginResultType.InvalidUserNameOrEmailAddress: | ||
case AbpLoginResultType.InvalidPassword: | ||
return new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword")); | ||
case AbpLoginResultType.InvalidTenancyName: | ||
return new UserFriendlyException(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName)); | ||
case AbpLoginResultType.TenantIsNotActive: | ||
return new UserFriendlyException(L("LoginFailed"), L("TenantIsNotActive", tenancyName)); | ||
case AbpLoginResultType.UserIsNotActive: | ||
return new UserFriendlyException(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress)); | ||
case AbpLoginResultType.UserEmailIsNotConfirmed: | ||
return new UserFriendlyException(L("LoginFailed"), L("UserEmailIsNotConfirmedAndCanNotLogin")); | ||
case AbpLoginResultType.LockedOut: | ||
return new UserFriendlyException(L("LoginFailed"), L("UserLockedOutMessage")); | ||
default: // Can not fall to default actually. But other result types can be added in the future and we may forget to handle it | ||
Logger.Warn("Unhandled login fail reason: " + result); | ||
return new UserFriendlyException(L("LoginFailed")); | ||
} | ||
case AbpLoginResultType.Success: | ||
return new Exception("Don't call this method with a success result!"); | ||
case AbpLoginResultType.InvalidUserNameOrEmailAddress: | ||
case AbpLoginResultType.InvalidPassword: | ||
return new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword")); | ||
case AbpLoginResultType.InvalidTenancyName: | ||
return new UserFriendlyException(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName)); | ||
case AbpLoginResultType.TenantIsNotActive: | ||
return new UserFriendlyException(L("LoginFailed"), L("TenantIsNotActive", tenancyName)); | ||
case AbpLoginResultType.UserIsNotActive: | ||
return new UserFriendlyException(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress)); | ||
case AbpLoginResultType.UserEmailIsNotConfirmed: | ||
return new UserFriendlyException(L("LoginFailed"), L("UserEmailIsNotConfirmedAndCanNotLogin")); | ||
case AbpLoginResultType.LockedOut: | ||
return new UserFriendlyException(L("LoginFailed"), L("UserLockedOutMessage")); | ||
default: // Can not fall to default actually. But other result types can be added in the future and we may forget to handle it | ||
Logger.Warn("Unhandled login fail reason: " + result); | ||
return new UserFriendlyException(L("LoginFailed")); | ||
} | ||
} | ||
|
||
public string CreateLocalizedMessageForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName) | ||
public string CreateLocalizedMessageForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName) | ||
{ | ||
switch (result) | ||
{ | ||
switch (result) | ||
{ | ||
case AbpLoginResultType.Success: | ||
throw new Exception("Don't call this method with a success result!"); | ||
case AbpLoginResultType.InvalidUserNameOrEmailAddress: | ||
case AbpLoginResultType.InvalidPassword: | ||
return L("InvalidUserNameOrPassword"); | ||
case AbpLoginResultType.InvalidTenancyName: | ||
return L("ThereIsNoTenantDefinedWithName{0}", tenancyName); | ||
case AbpLoginResultType.TenantIsNotActive: | ||
return L("TenantIsNotActive", tenancyName); | ||
case AbpLoginResultType.UserIsNotActive: | ||
return L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress); | ||
case AbpLoginResultType.UserEmailIsNotConfirmed: | ||
return L("UserEmailIsNotConfirmedAndCanNotLogin"); | ||
default: // Can not fall to default actually. But other result types can be added in the future and we may forget to handle it | ||
Logger.Warn("Unhandled login fail reason: " + result); | ||
return L("LoginFailed"); | ||
} | ||
case AbpLoginResultType.Success: | ||
throw new Exception("Don't call this method with a success result!"); | ||
case AbpLoginResultType.InvalidUserNameOrEmailAddress: | ||
case AbpLoginResultType.InvalidPassword: | ||
return L("InvalidUserNameOrPassword"); | ||
case AbpLoginResultType.InvalidTenancyName: | ||
return L("ThereIsNoTenantDefinedWithName{0}", tenancyName); | ||
case AbpLoginResultType.TenantIsNotActive: | ||
return L("TenantIsNotActive", tenancyName); | ||
case AbpLoginResultType.UserIsNotActive: | ||
return L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress); | ||
case AbpLoginResultType.UserEmailIsNotConfirmed: | ||
return L("UserEmailIsNotConfirmedAndCanNotLogin"); | ||
default: // Can not fall to default actually. But other result types can be added in the future and we may forget to handle it | ||
Logger.Warn("Unhandled login fail reason: " + result); | ||
return L("LoginFailed"); | ||
} | ||
} | ||
} |
79 changes: 39 additions & 40 deletions
79
...src/AbpCompanyName.AbpProjectName.Application/Authorization/Accounts/AccountAppService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,56 @@ | ||
using System.Threading.Tasks; | ||
using Abp.Configuration; | ||
using Abp.Zero.Configuration; | ||
using AbpCompanyName.AbpProjectName.Authorization.Accounts.Dto; | ||
using AbpCompanyName.AbpProjectName.Authorization.Users; | ||
using System.Threading.Tasks; | ||
|
||
namespace AbpCompanyName.AbpProjectName.Authorization.Accounts; | ||
|
||
namespace AbpCompanyName.AbpProjectName.Authorization.Accounts | ||
public class AccountAppService : AbpProjectNameAppServiceBase, IAccountAppService | ||
{ | ||
public class AccountAppService : AbpProjectNameAppServiceBase, IAccountAppService | ||
{ | ||
// from: http://regexlib.com/REDetails.aspx?regexp_id=1923 | ||
public const string PasswordRegex = "(?=^.{8,}$)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\\s)[0-9a-zA-Z!@#$%^&*()]*$"; | ||
// from: http://regexlib.com/REDetails.aspx?regexp_id=1923 | ||
public const string PasswordRegex = "(?=^.{8,}$)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\\s)[0-9a-zA-Z!@#$%^&*()]*$"; | ||
|
||
private readonly UserRegistrationManager _userRegistrationManager; | ||
|
||
private readonly UserRegistrationManager _userRegistrationManager; | ||
public AccountAppService( | ||
UserRegistrationManager userRegistrationManager) | ||
{ | ||
_userRegistrationManager = userRegistrationManager; | ||
} | ||
|
||
public AccountAppService( | ||
UserRegistrationManager userRegistrationManager) | ||
public async Task<IsTenantAvailableOutput> IsTenantAvailable(IsTenantAvailableInput input) | ||
{ | ||
var tenant = await TenantManager.FindByTenancyNameAsync(input.TenancyName); | ||
if (tenant == null) | ||
{ | ||
_userRegistrationManager = userRegistrationManager; | ||
return new IsTenantAvailableOutput(TenantAvailabilityState.NotFound); | ||
} | ||
|
||
public async Task<IsTenantAvailableOutput> IsTenantAvailable(IsTenantAvailableInput input) | ||
if (!tenant.IsActive) | ||
{ | ||
var tenant = await TenantManager.FindByTenancyNameAsync(input.TenancyName); | ||
if (tenant == null) | ||
{ | ||
return new IsTenantAvailableOutput(TenantAvailabilityState.NotFound); | ||
} | ||
|
||
if (!tenant.IsActive) | ||
{ | ||
return new IsTenantAvailableOutput(TenantAvailabilityState.InActive); | ||
} | ||
|
||
return new IsTenantAvailableOutput(TenantAvailabilityState.Available, tenant.Id); | ||
return new IsTenantAvailableOutput(TenantAvailabilityState.InActive); | ||
} | ||
|
||
public async Task<RegisterOutput> Register(RegisterInput input) | ||
return new IsTenantAvailableOutput(TenantAvailabilityState.Available, tenant.Id); | ||
} | ||
|
||
public async Task<RegisterOutput> Register(RegisterInput input) | ||
{ | ||
var user = await _userRegistrationManager.RegisterAsync( | ||
input.Name, | ||
input.Surname, | ||
input.EmailAddress, | ||
input.UserName, | ||
input.Password, | ||
true // Assumed email address is always confirmed. Change this if you want to implement email confirmation. | ||
); | ||
|
||
var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync<bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin); | ||
|
||
return new RegisterOutput | ||
{ | ||
var user = await _userRegistrationManager.RegisterAsync( | ||
input.Name, | ||
input.Surname, | ||
input.EmailAddress, | ||
input.UserName, | ||
input.Password, | ||
true // Assumed email address is always confirmed. Change this if you want to implement email confirmation. | ||
); | ||
|
||
var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync<bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin); | ||
|
||
return new RegisterOutput | ||
{ | ||
CanLogin = user.IsActive && (user.IsEmailConfirmed || !isEmailConfirmationRequiredForLogin) | ||
}; | ||
} | ||
CanLogin = user.IsActive && (user.IsEmailConfirmed || !isEmailConfirmationRequiredForLogin) | ||
}; | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
...mpanyName.AbpProjectName.Application/Authorization/Accounts/Dto/IsTenantAvailableInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Abp.MultiTenancy; | ||
using Abp.MultiTenancy; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace AbpCompanyName.AbpProjectName.Authorization.Accounts.Dto | ||
namespace AbpCompanyName.AbpProjectName.Authorization.Accounts.Dto; | ||
|
||
public class IsTenantAvailableInput | ||
{ | ||
public class IsTenantAvailableInput | ||
{ | ||
[Required] | ||
[StringLength(AbpTenantBase.MaxTenancyNameLength)] | ||
public string TenancyName { get; set; } | ||
} | ||
[Required] | ||
[StringLength(AbpTenantBase.MaxTenancyNameLength)] | ||
public string TenancyName { get; set; } | ||
} |
Oops, something went wrong.