public UserAccountManager( IUserStore <ApplicationUser> store, IOptions <IdentityOptions> optionsAccessor, IPasswordHasher <ApplicationUser> passwordHasher, IEnumerable <IUserValidator <ApplicationUser> > userValidators, IEnumerable <IPasswordValidator <ApplicationUser> > passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, IUnitOfWorkAsync unitOfWork, IOptions <IdentityOptions> identityOptions, IOptions <AppSettings> settings, ILogger <UserAccountManager> logger) : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger) { _identityOptions = identityOptions.Value; _logger = logger; _settings = settings.Value; Repository = unitOfWork.RepositoryAsync <ApplicationUser>(); Settings = settings.Value.Auth; EventsHandler = new EventsHandler(); AddEventHandler(new MultiUserAccountEventsHandler(services)); var accountValidators = new UserAccountValidators(); _usernameValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser>(); if (!_settings.Auth.EmailIsUsername) { val.Add(UserAccountValidation.UsernameDoesNotContainAtSign); val.Add(UserAccountValidation.UsernameCanOnlyStartOrEndWithLetterOrDigit); val.Add(UserAccountValidation.UsernameOnlyContainsValidCharacters); val.Add(UserAccountValidation.UsernameOnlySingleInstanceOfSpecialCharacters); } val.Add(UserAccountValidation.UsernameMustNotAlreadyExist); val.Add(accountValidators.UsernameValidator); return(val); }); _emailValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser> { UserAccountValidation.EmailIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.EmailIsValidFormat, UserAccountValidation.EmailMustNotAlreadyExist, accountValidators.EmailValidator }; return(val); }); _phoneNumberValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser> { UserAccountValidation.PhoneNumberIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.PhoneNumberMustNotAlreadyExist, accountValidators.PhoneNumberValidator }; return(val); }); _passwordValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser> { UserAccountValidation.PasswordMustBeDifferentThanCurrent, accountValidators.PasswordValidator }; return(val); }); }
public UserAccountService(IServiceProvider serviceProvider, IUnitOfWorkAsync unitOfWork) : base(unitOfWork) { _crypto = (ICrypto)serviceProvider.GetService(typeof(ICrypto)); var settings = (IOptions <AppSettings>)serviceProvider.GetService(typeof(IOptions <AppSettings>)); _settings = settings.Value; _logger = (ILogger <UserAccountService>)serviceProvider.GetService(typeof(ILogger <UserAccountService>)); Settings = settings.Value.Auth; AddEventHandler(new EmailUserAccountEventsHandler(serviceProvider)); var accountvalidators = new UserAccountValidators(); _usernameValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount>(); if (!_settings.Auth.EmailIsUsername) { val.Add(UserAccountValidation.UsernameDoesNotContainAtSign); val.Add(UserAccountValidation.UsernameCanOnlyStartOrEndWithLetterOrDigit); val.Add(UserAccountValidation.UsernameOnlyContainsValidCharacters); val.Add(UserAccountValidation.UsernameOnlySingleInstanceOfSpecialCharacters); } val.Add(UserAccountValidation.UsernameMustNotAlreadyExist); val.Add(accountvalidators.UsernameValidator); return(val); }); _emailValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount> { UserAccountValidation.EmailIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.EmailIsValidFormat, UserAccountValidation.EmailMustNotAlreadyExist, accountvalidators.EmailValidator }; return(val); }); _phoneNumberValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount> { UserAccountValidation.PhoneNumberIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.PhoneNumberMustNotAlreadyExist, accountvalidators.PhoneNumberValidator }; return(val); }); _passwordValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount> { UserAccountValidation.PasswordMustBeDifferentThanCurrent, accountvalidators.PasswordValidator }; return(val); }); }