Skip to content

Commit

Permalink
Merge pull request #674 from aspnetboilerplate/upgrade-to-abp-10.0-an…
Browse files Browse the repository at this point in the history
…d-dotnet-9

Upgrade to ABP 10.0 and .NET 9
  • Loading branch information
ismcagdas authored Nov 21, 2024
2 parents 17d03f1 + 2eb26d7 commit 3e23d22
Show file tree
Hide file tree
Showing 204 changed files with 6,631 additions and 6,873 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.0.0.0</VersionPrefix>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<AssemblyName>AbpCompanyName.AbpProjectName.Application</AssemblyName>
<PackageId>AbpCompanyName.AbpProjectName.Application</PackageId>
Expand All @@ -12,9 +11,7 @@
<RootNamespace>AbpCompanyName.AbpProjectName</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AbpCompanyName.AbpProjectName.Core\AbpCompanyName.AbpProjectName.Core.csproj" />
</ItemGroup>

</Project>
</Project>
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
using Abp.Reflection.Extensions;
using AbpCompanyName.AbpProjectName.Authorization;

namespace AbpCompanyName.AbpProjectName
namespace AbpCompanyName.AbpProjectName;

[DependsOn(
typeof(AbpProjectNameCoreModule),
typeof(AbpAutoMapperModule))]
public class AbpProjectNameApplicationModule : AbpModule
{
[DependsOn(
typeof(AbpProjectNameCoreModule),
typeof(AbpAutoMapperModule))]
public class AbpProjectNameApplicationModule : AbpModule
public override void PreInitialize()
{
public override void PreInitialize()
{
Configuration.Authorization.Providers.Add<AbpProjectNameAuthorizationProvider>();
}
Configuration.Authorization.Providers.Add<AbpProjectNameAuthorizationProvider>();
}

public override void Initialize()
{
var thisAssembly = typeof(AbpProjectNameApplicationModule).GetAssembly();
public override void Initialize()
{
var thisAssembly = typeof(AbpProjectNameApplicationModule).GetAssembly();

IocManager.RegisterAssemblyByConvention(thisAssembly);
IocManager.RegisterAssemblyByConvention(thisAssembly);

Configuration.Modules.AbpAutoMapper().Configurators.Add(
// Scan the assembly for classes which inherit from AutoMapper.Profile
cfg => cfg.AddMaps(thisAssembly)
);
}
Configuration.Modules.AbpAutoMapper().Configurators.Add(
// Scan the assembly for classes which inherit from AutoMapper.Profile
cfg => cfg.AddMaps(thisAssembly)
);
}
}
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");
}
}
}
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)
};
}
}
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; }
}
Loading

0 comments on commit 3e23d22

Please sign in to comment.