mirror of https://github.com/abpframework/abp.git
37 changed files with 236 additions and 38 deletions
@ -0,0 +1,19 @@ |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public static class IdentityUserExtensions |
|||
{ |
|||
public static IUserInfo ToUserInfo(this IdentityUser user) |
|||
{ |
|||
return new UserInfo( |
|||
user.Id, |
|||
user.UserName, |
|||
user.Email, |
|||
user.EmailConfirmed, |
|||
user.PhoneNumber, |
|||
user.PhoneNumberConfirmed |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public class IdentityUserLookupService : IUserLookupService, ITransientDependency |
|||
{ |
|||
private readonly IIdentityUserRepository _userRepository; |
|||
private readonly ILookupNormalizer _lookupNormalizer; |
|||
|
|||
public IdentityUserLookupService(IIdentityUserRepository userRepository, ILookupNormalizer lookupNormalizer) |
|||
{ |
|||
_userRepository = userRepository; |
|||
_lookupNormalizer = lookupNormalizer; |
|||
} |
|||
|
|||
public async Task<IUserInfo> FindUserByIdAsync(Guid id) |
|||
{ |
|||
return (await _userRepository.FindAsync(id)).ToUserInfo(); |
|||
} |
|||
|
|||
public async Task<IUserInfo> FindUserByUserNameAsync(string userName) |
|||
{ |
|||
return (await _userRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.Normalize(userName))).ToUserInfo(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public class HttpClientIdentityUserLookupService : IUserLookupService, ITransientDependency |
|||
{ |
|||
private readonly IIdentityUserAppService _userAppService; |
|||
|
|||
public HttpClientIdentityUserLookupService(IIdentityUserAppService userAppService) |
|||
{ |
|||
_userAppService = userAppService; |
|||
} |
|||
|
|||
public async Task<IUserInfo> FindUserByIdAsync(Guid id) |
|||
{ |
|||
//TODO: Should return null if not found!
|
|||
return (await _userAppService.GetAsync(id)).ToUserInfo(); |
|||
} |
|||
|
|||
public async Task<IUserInfo> FindUserByUserNameAsync(string userName) |
|||
{ |
|||
//TODO: Should return null if not found!
|
|||
//TODO: Search by UserName, not by a general filter!
|
|||
return (await _userAppService.GetListAsync(new GetIdentityUsersInput { Filter = userName })).Items.FirstOrDefault()?.ToUserInfo(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public static class IdentityUserDtoExtensions |
|||
{ |
|||
public static IUserInfo ToUserInfo(this IdentityUserDto user) |
|||
{ |
|||
return new UserInfo( |
|||
user.Id, |
|||
user.UserName, |
|||
user.Email, |
|||
user.EmailConfirmed, |
|||
user.PhoneNumber, |
|||
user.PhoneNumberConfirmed |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
|||
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary> |
|||
@ -1,7 +1,7 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.Session |
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public static class CurrentUserExtensions |
|||
{ |
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public interface IUserInfo |
|||
{ |
|||
Guid Id { get; } |
|||
|
|||
string UserName { get; } |
|||
|
|||
[CanBeNull] |
|||
string Email { get; } |
|||
|
|||
bool EmailConfirmed { get; } |
|||
|
|||
[CanBeNull] |
|||
string PhoneNumber { get; } |
|||
|
|||
bool PhoneNumberConfirmed { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public interface IUserLookupService |
|||
{ |
|||
Task<IUserInfo> FindUserByIdAsync(Guid id); |
|||
|
|||
Task<IUserInfo> FindUserByUserNameAsync(string userName); |
|||
|
|||
//TODO: Searching users...
|
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public class NullUserLookupService : IUserLookupService, ISingletonDependency |
|||
{ |
|||
private static readonly Task<IUserInfo> NullUserResult = Task.FromResult((IUserInfo) null); |
|||
|
|||
public Task<IUserInfo> FindUserByIdAsync(Guid id) |
|||
{ |
|||
return NullUserResult; |
|||
} |
|||
|
|||
public Task<IUserInfo> FindUserByUserNameAsync(string userName) |
|||
{ |
|||
return NullUserResult; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public class UserInfo : IUserInfo |
|||
{ |
|||
public Guid Id { get; } |
|||
|
|||
public string UserName { get; } |
|||
|
|||
public string Email { get; } |
|||
|
|||
public bool EmailConfirmed { get; } |
|||
|
|||
public string PhoneNumber { get; } |
|||
|
|||
public bool PhoneNumberConfirmed { get; } |
|||
|
|||
public UserInfo( |
|||
Guid id, |
|||
[NotNull] string userName, |
|||
[CanBeNull] string email = null, |
|||
bool emailConfirmed = false, |
|||
[CanBeNull] string phoneNumber = null, |
|||
bool phoneNumberConfirmed = false) |
|||
{ |
|||
Check.NotNull(userName, nameof(userName)); |
|||
|
|||
Id = id; |
|||
UserName = userName; |
|||
Email = email; |
|||
EmailConfirmed = emailConfirmed; |
|||
PhoneNumber = phoneNumber; |
|||
PhoneNumberConfirmed = phoneNumberConfirmed; |
|||
} |
|||
} |
|||
} |
|||
@ -1,7 +1,7 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace Volo.Abp.Session |
|||
namespace Volo.Abp.Users |
|||
{ |
|||
//TODO: Optimization: Get all settings and cache it!
|
|||
|
|||
Loading…
Reference in new issue