public virtual bool IsTokenValidityKeyValid(
     TUser user,
     string tokenValidityKey,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(AbpUserStore.IsTokenValidityKeyValid(user, tokenValidityKey, cancellationToken));
 }
        // Microsoft.AspNetCore.Identity.UserManager doesn't have required sync version for method calls in this function
        //public override IdentityResult Delete(TUser user)
        //{
        //    if (user.UserName == AbpUserBase.AdminUserName)
        //    {
        //        throw new UserFriendlyException(string.Format(L("CanNotDeleteAdminUser"), AbpUserBase.AdminUserName));
        //    }

        //    return base.Delete(user);
        //}

        public virtual async Task <IdentityResult> ChangePasswordAsync(TUser user, string newPassword)
        {
            var errors = new List <IdentityError>();

            foreach (var validator in PasswordValidators)
            {
                var validationResult = await validator.ValidateAsync(this, user, newPassword);

                if (!validationResult.Succeeded)
                {
                    errors.AddRange(validationResult.Errors);
                }
            }

            if (errors.Any())
            {
                return(IdentityResult.Failed(errors.ToArray()));
            }

            await AbpUserStore.SetPasswordHashAsync(user, PasswordHasher.HashPassword(user, newPassword));

            await UpdateSecurityStampAsync(user);

            return(IdentityResult.Success);
        }
 public virtual void RemoveTokenValidityKey(
     TUser user,
     string tokenValidityKey,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     AbpUserStore.RemoveTokenValidityKey(user, tokenValidityKey, cancellationToken);
 }
        private UserPermissionCacheItem GetUserPermissionCacheItem(long userId)
        {
            var cacheKey = userId + "@" + (GetCurrentTenantId() ?? 0);

            return(_cacheManager.GetUserPermissionCache().Get(cacheKey, () =>
            {
                var user = AbpUserStore.FindById(userId.ToString());
                if (user == null)
                {
                    return null;
                }

                var newCacheItem = new UserPermissionCacheItem(userId);

                foreach (var roleName in AbpUserStore.GetRoles(user))
                {
                    newCacheItem.RoleIds.Add((RoleManager.GetRoleByName(roleName)).Id);
                }

                foreach (var permissionInfo in UserPermissionStore.GetPermissions(userId))
                {
                    if (permissionInfo.IsGranted)
                    {
                        newCacheItem.GrantedPermissions.Add(permissionInfo.Name);
                    }
                    else
                    {
                        newCacheItem.ProhibitedPermissions.Add(permissionInfo.Name);
                    }
                }

                return newCacheItem;
            }));
        }
Пример #5
0
 public virtual async Task <bool> IsTokenValidityKeyValidAsync(
     TUser user,
     string tokenValidityKey,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await AbpUserStore.IsTokenValidityKeyValidAsync(user, tokenValidityKey, cancellationToken));
 }
Пример #6
0
 public virtual async Task RemoveTokenValidityKeyAsync(
     TUser user,
     string tokenValidityKey,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     await AbpUserStore.RemoveTokenValidityKeyAsync(user, tokenValidityKey, cancellationToken);
 }
Пример #7
0
        protected AbpUserManager(
            AbpUserStore <TRole, TUser> userStore,
            AbpRoleManager <TRole, TUser> roleManager,
            IRepository <TTenant> tenantRepository,
            IMultiTenancyConfig multiTenancyConfig,
            IPermissionManager permissionManager,
            IUnitOfWorkManager unitOfWorkManager,
            ISettingManager settingManager,
            IUserManagementConfig userManagementConfig,
            IIocResolver iocResolver,
            ICacheManager cacheManager,
            IRepository <OrganizationUnit, long> organizationUnitRepository,
            IRepository <UserOrganizationUnit, long> userOrganizationUnitRepository,
            IOrganizationUnitSettings organizationUnitSettings,
            IRepository <UserLoginAttempt, long> userLoginAttemptRepository)
            : base(userStore)
        {
            AbpStore                        = userStore;
            RoleManager                     = roleManager;
            SettingManager                  = settingManager;
            _tenantRepository               = tenantRepository;
            _multiTenancyConfig             = multiTenancyConfig;
            _permissionManager              = permissionManager;
            _unitOfWorkManager              = unitOfWorkManager;
            _userManagementConfig           = userManagementConfig;
            _iocResolver                    = iocResolver;
            _cacheManager                   = cacheManager;
            _organizationUnitRepository     = organizationUnitRepository;
            _userOrganizationUnitRepository = userOrganizationUnitRepository;
            _organizationUnitSettings       = organizationUnitSettings;
            _userLoginAttemptRepository     = userLoginAttemptRepository;

            LocalizationManager = NullLocalizationManager.Instance;
            AbpSession          = NullAbpSession.Instance;
        }
Пример #8
0
        public async Task <UserPermissionCacheItem> GetUserPermissionCacheItemAsync(long userId, long?branchId)
        {
            var cacheKey = userId + "@" + (GetCurrentTenantId() ?? 0) + "@" + (branchId ?? 0);

            return(await _cacheManager.GetUserPermissionCache().GetAsync(cacheKey, async() =>
            {
                var user = await FindByIdAsync(userId.ToString());
                if (user == null)
                {
                    return null;
                }

                var newCacheItem = new UserPermissionCacheItem(userId, branchId);

                foreach (var roleName in await AbpUserStore.GetRolesAsync(user, branchId))
                {
                    newCacheItem.RoleIds.Add((await RoleManager.GetRoleByNameAsync(roleName)).Id);
                }

                foreach (var permissionInfo in await UserPermissionStore.GetPermissionsAsync(userId, branchId))
                {
                    if (permissionInfo.IsGranted)
                    {
                        newCacheItem.GrantedPermissions.Add(permissionInfo.Name);
                    }
                    else
                    {
                        newCacheItem.ProhibitedPermissions.Add(permissionInfo.Name);
                    }
                }

                return newCacheItem;
            }));
        }
Пример #9
0
        protected AbpUserManager(
            AbpUserStore <TTenant, TRole, TUser> userStore,
            AbpRoleManager <TTenant, TRole, TUser> roleManager,
            IRepository <TTenant> tenantRepository,
            IMultiTenancyConfig multiTenancyConfig,
            IPermissionManager permissionManager,
            IUnitOfWorkManager unitOfWorkManager,
            ISettingManager settingManager,
            IUserManagementConfig userManagementConfig,
            IIocResolver iocResolver,
            ICacheManager cacheManager)
            : base(userStore)
        {
            AbpStore              = userStore;
            RoleManager           = roleManager;
            SettingManager        = settingManager;
            _tenantRepository     = tenantRepository;
            _multiTenancyConfig   = multiTenancyConfig;
            _permissionManager    = permissionManager;
            _unitOfWorkManager    = unitOfWorkManager;
            _userManagementConfig = userManagementConfig;
            _iocResolver          = iocResolver;
            _cacheManager         = cacheManager;

            LocalizationManager = NullLocalizationManager.Instance;
        }
Пример #10
0
 public virtual void AddTokenValidityKey(
     TUser user,
     string tokenValidityKey,
     DateTime expireDate,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     AbpUserStore.AddTokenValidityKey(user, tokenValidityKey, expireDate, cancellationToken);
 }
Пример #11
0
 public virtual async Task AddTokenValidityKeyAsync(
     TUser user,
     string tokenValidityKey,
     DateTime expireDate,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     await AbpUserStore.AddTokenValidityKeyAsync(user, tokenValidityKey, expireDate, cancellationToken);
 }
Пример #12
0
        /// <summary>
        /// Gets a user by given id.
        /// Throws exception if no user found with given id.
        /// </summary>
        /// <param name="userId">User id</param>
        /// <returns>User</returns>
        /// <exception cref="AbpException">Throws exception if no user found with given id</exception>
        public virtual TUser GetUserById(long userId)
        {
            var user = AbpUserStore.FindById(userId.ToString());

            if (user == null)
            {
                throw new AbpException("There is no user with id: " + userId);
            }

            return(user);
        }
Пример #13
0
        public bool IsLockedOut(string userId)
        {
            var user = AbpUserStore.FindById(userId);

            if (user == null)
            {
                throw new AbpException("There is no user with id: " + userId);
            }

            var lockoutEndDateUtc = AbpUserStore.GetLockoutEndDate(user);

            return(lockoutEndDateUtc > DateTimeOffset.UtcNow);
        }
        public AbpUserManager(
            AbpRoleManager <TRole, TUser> roleManager,
            AbpUserStore <TRole, TUser> userStore,
            IOptions <IdentityOptions> optionsAccessor,
            IPasswordHasher <TUser> passwordHasher,
            IEnumerable <IUserValidator <TUser> > userValidators,
            IEnumerable <IPasswordValidator <TUser> > passwordValidators,
            ILookupNormalizer keyNormalizer,
            IdentityErrorDescriber errors,
            IServiceProvider services,
            ILogger <UserManager <TUser> > logger,
            IPermissionManager permissionManager,
            IUnitOfWorkManager unitOfWorkManager,
            ICacheManager cacheManager,
            IRepository <OrganizationUnit, long> organizationUnitRepository,
            IRepository <UserOrganizationUnit, long> userOrganizationUnitRepository,
            IOrganizationUnitSettings organizationUnitSettings,
            ISettingManager settingManager,
            IRepository <UserLogin, long> userLoginRepository)
            : base(
                userStore,
                optionsAccessor,
                passwordHasher,
                userValidators,
                passwordValidators,
                keyNormalizer,
                errors,
                services,
                logger)
        {
            _permissionManager              = permissionManager;
            _unitOfWorkManager              = unitOfWorkManager;
            _cacheManager                   = cacheManager;
            _organizationUnitRepository     = organizationUnitRepository;
            _userOrganizationUnitRepository = userOrganizationUnitRepository;
            _organizationUnitSettings       = organizationUnitSettings;
            _settingManager                 = settingManager;
            _userLoginRepository            = userLoginRepository;
            _optionsAccessor                = optionsAccessor;

            AbpUserStore           = userStore;
            RoleManager            = roleManager;
            LocalizationManager    = NullLocalizationManager.Instance;
            LocalizationSourceName = AbpZeroConsts.LocalizationSourceName;
        }
Пример #15
0
        protected AbpUserManager(
            AbpRoleManager <TRole, TUser> roleManager,
            AbpUserStore <TRole, TUser> store,
            IOptions <IdentityOptions> optionsAccessor,
            IPasswordHasher <TUser> passwordHasher,
            IEnumerable <IUserValidator <TUser> > userValidators,
            IEnumerable <IPasswordValidator <TUser> > passwordValidators,
            ILookupNormalizer keyNormalizer,
            IdentityErrorDescriber errors,
            IServiceProvider services,
            ILogger <UserManager <TUser> > logger,
            IPermissionManager permissionManager,
            IUnitOfWorkManager unitOfWorkManager,
            ICacheManager cacheManager,
            IRepository <OrganizationUnit, long> organizationUnitRepository,
            IRepository <UserOrganizationUnit, long> userOrganizationUnitRepository,
            IOrganizationUnitSettings organizationUnitSettings,
            ISettingManager settingManager)
            : base(
                store,
                optionsAccessor,
                passwordHasher,
                userValidators,
                passwordValidators,
                keyNormalizer,
                errors,
                services,
                logger)
        {
            _permissionManager              = permissionManager;
            _unitOfWorkManager              = unitOfWorkManager;
            _cacheManager                   = cacheManager;
            _organizationUnitRepository     = organizationUnitRepository;
            _userOrganizationUnitRepository = userOrganizationUnitRepository;
            _organizationUnitSettings       = organizationUnitSettings;
            _settingManager                 = settingManager;

            AbpStore    = store;
            RoleManager = roleManager;
        }
Пример #16
0
        protected AbpUserManager(
            AbpUserStore <TRole, TUser> userStore,
            AbpRoleManager <TRole, TUser> roleManager,
            IPermissionManager permissionManager,
            IUnitOfWorkManager unitOfWorkManager,
            ICacheManager cacheManager,
            IRepository <OrganizationUnit, long> organizationUnitRepository,
            IRepository <UserOrganizationUnit, long> userOrganizationUnitRepository,
            IOrganizationUnitSettings organizationUnitSettings,
            ILocalizationManager localizationManager,
            IdentityEmailMessageService emailService,
            ISettingManager settingManager,
            IUserTokenProviderAccessor userTokenProviderAccessor,
            IRepository <UserLogin, long> userLoginRepository)
            : base(userStore)
        {
            AbpStore               = userStore;
            RoleManager            = roleManager;
            LocalizationManager    = localizationManager;
            LocalizationSourceName = AbpZeroConsts.LocalizationSourceName;
            _settingManager        = settingManager;
            _userLoginRepository   = userLoginRepository;

            _permissionManager              = permissionManager;
            _unitOfWorkManager              = unitOfWorkManager;
            _cacheManager                   = cacheManager;
            _organizationUnitRepository     = organizationUnitRepository;
            _userOrganizationUnitRepository = userOrganizationUnitRepository;
            _organizationUnitSettings       = organizationUnitSettings;

            AbpSession = NullAbpSession.Instance;

            UserLockoutEnabledByDefault          = true;
            DefaultAccountLockoutTimeSpan        = TimeSpan.FromMinutes(5);
            MaxFailedAccessAttemptsBeforeLockout = 5;

            EmailService = emailService;

            UserTokenProvider = userTokenProviderAccessor.GetUserTokenProviderOrNull <TUser>();
        }
Пример #17
0
        // Microsoft.AspNetCore.Identity doesn't have a sync version of FindByName(...), FindByEmail(...)
        //public virtual IdentityResult CheckDuplicateUsernameOrEmailAddress(long? expectedUserId, string userName, string emailAddress)
        //{
        //    var user = (FindByName(userName));
        //    if (user != null && user.Id != expectedUserId)
        //    {
        //        throw new UserFriendlyException(string.Format(L("Identity.DuplicateUserName"), userName));
        //    }

        //    user = (FindByEmail(emailAddress));
        //    if (user != null && user.Id != expectedUserId)
        //    {
        //        throw new UserFriendlyException(string.Format(L("Identity.DuplicateEmail"), emailAddress));
        //    }

        //    return IdentityResult.Success;
        //}

        public virtual async Task <IdentityResult> SetRolesAsync(TUser user, string[] roleNames, long?branchId)
        {
            await AbpUserStore.UserRepository.EnsureCollectionLoadedAsync(user, u => u.Roles);

            //Remove from removed roles
            foreach (var userRole in user.Roles.Where(e => e.BranchId == branchId).ToList())
            {
                var role = await RoleManager.FindByIdAsync(userRole.RoleId.ToString());

                if (role != null && roleNames.All(roleName => role.NormalizedName != roleName))
                {
                    //var result = await RemoveFromRoleAsync(user, role.Name);
                    //if (!result.Succeeded)
                    //{
                    //    return result;
                    //}

                    await AbpUserStore.RemoveFromRoleAsync(user, role.NormalizedName, branchId);
                }
            }

            //Add to added roles
            foreach (var roleName in roleNames)
            {
                var roleByName = await RoleManager.GetRoleByNameAsync(roleName);

                if (user.Roles.Where(e => e.BranchId == branchId).All(ur => ur.RoleId != roleByName.Id))
                {
                    //var result = await AddToRoleAsync(user, roleName);
                    //if (!result.Succeeded)
                    //{
                    //    return result;
                    //}
                    await AbpUserStore.AddToRoleAsync(user, roleName, branchId);
                }
            }

            return(IdentityResult.Success);
        }
Пример #18
0
 public virtual List <TUser> FindAll(UserLoginInfo login)
 {
     return(AbpUserStore.FindAll(login));
 }
Пример #19
0
 public virtual TUser FindByNameOrEmail(long?tenantId, string userNameOrEmailAddress)
 {
     return(AbpUserStore.FindByNameOrEmail(tenantId, userNameOrEmailAddress));
 }
Пример #20
0
 protected virtual string GetOldUserName(long userId)
 {
     return(AbpUserStore.GetUserNameFromDatabase(userId));
 }
Пример #21
0
 protected AbpUserManager(AbpUserStore <TTenant, TRole, TUser> store)
     : base(store)
 {
 }
Пример #22
0
 public virtual Task <TUser> FindByNameOrEmailAsync(int?tenantId, string userNameOrEmailAddress)
 {
     return(AbpUserStore.FindByNameOrEmailAsync(tenantId, userNameOrEmailAddress));
 }
Пример #23
0
 protected virtual Task <string> GetOldUserNameAsync(long userId)
 {
     return(AbpUserStore.GetUserNameFromDatabaseAsync(userId));
 }
Пример #24
0
 public virtual Task <List <TUser> > FindAllAsync(UserLoginInfo login)
 {
     return(AbpUserStore.FindAllAsync(login));
 }
Пример #25
0
 public virtual Task <TUser> FindAsync(int?tenantId, UserLoginInfo login)
 {
     return(AbpUserStore.FindAsync(tenantId, login));
 }
Пример #26
0
 public virtual Task <TUser> FindByNameOrEmailAsync(string userNameOrEmailAddress)
 {
     return(AbpUserStore.FindByNameOrEmailAsync(userNameOrEmailAddress));
 }
Пример #27
0
        public bool IsLockedOut(TUser user)
        {
            var lockoutEndDateUtc = AbpUserStore.GetLockoutEndDate(user);

            return(lockoutEndDateUtc > DateTimeOffset.UtcNow);
        }
Пример #28
0
 public void ResetAccessFailedCount(TUser user)
 {
     AbpUserStore.ResetAccessFailedCount(user);
 }
Пример #29
0
 public virtual TUser Find(int?tenantId, UserLoginInfo login)
 {
     return(AbpUserStore.Find(tenantId, login));
 }
Пример #30
0
 public virtual TUser FindByNameOrEmail(string userNameOrEmailAddress)
 {
     return(AbpUserStore.FindByNameOrEmail(userNameOrEmailAddress));
 }