public async Task WhenTheUserWithIdHasValidPasswordResetTokenAsync(string userId)
        {
            await SaveDbKeysToRepositoryAsync();

            var userEntity = new UserEntity {
                Id = userId
            };
            var userInDb = await userEntity.GetAsync(_settings.ConnectionString);

            var identityUser = new IdentityUser(userId)
            {
                Email         = userInDb.EmailAddress,
                Id            = userId,
                SecurityStamp = userInDb.SecurityStamp,
            };

            var userManager = new UserManager <IdentityUser>(
                new UserStore(identityUser),
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null);

            userManager.RegisterTokenProvider(TokenOptions.DefaultProvider, _dataProtectionProvider);

            _context.Set(identityUser);
            _context[ScenarioContextKeys.PasswordResetToken] = await userManager.GeneratePasswordResetTokenAsync(identityUser);

            await DataProtectionKeys.SaveToDbAsync(_settings.ConnectionString, Keys);
        }
示例#2
0
 public AccountController(IOptions <AppSettings> appSettings, ApplicationDbContext db,
                          IAuthenticateSvc authenticateSvc, ICookieSvc cookieSvc, IServiceProvider provider, IOptions <DataProtectionKeys> dataProtectionKey)
 {
     _appSettings        = appSettings.Value;
     _db                 = db;
     _provider           = provider;
     _authenticateSvc    = authenticateSvc;
     _dataProtectionKeys = dataProtectionKey.Value;
     _cookieSvc          = cookieSvc;
 }
示例#3
0
 AdminAuthenticationHandler(IOptionsMonitor <AdminAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock,
                            UserManager <ApplicationUser> userManager, IOptions <AppSettings> appSettings, IOptions <DataProtectionKeys> dataProtectionKeys, IServiceProvider provider,
                            IOptions <IdentityDefaultOptions> identityDefaultOptions) : base(options, logger, encoder, clock)
 {
     _userManager            = userManager;
     _appSettings            = appSettings.Value;
     _identityDefaultOptions = identityDefaultOptions.Value;
     _provider           = provider;
     _dataProtectionKeys = dataProtectionKeys.Value;
 }
示例#4
0
        //private readonly IActivitySvc activitySvc;
        //private readonly ApplicationDbContext db;
        //private readonly IHostingEnvironment env;
        //private readonly UserManager<ApplicationUser> userManager;

        public ProfileController(IServiceProvider provider, IOptions <AppSettings> appSettings,
                                 IOptions <DataProtectionKeys> dataProtectionKeys, ICookieSvc cookieSvc, IUserSvc userSvc)
        {
            _provider           = provider;
            _appSettings        = appSettings.Value;
            _dataProtectionKeys = dataProtectionKeys.Value;
            _cookieSvc          = cookieSvc;
            //_userSvc = new UserSvc(provider, activitySvc, cookieSvc, db, dataProtectionKeys, ev,userManager);
            _userSvc = userSvc;
        }
 public UserController(IUserSvc userSvc, ICookieSvc cookieSvc, IServiceProvider provider,
                       IOptions <DataProtectionKeys> dataProtectionKeys, IOptions <AppSettings> appSettings, IWritebleSettingSvc <SiteWideSettings> writableSiteWideSettings)
 {
     _userSvc            = userSvc;
     _cookieSvc          = cookieSvc;
     _provider           = provider;
     _dataProtectionKeys = dataProtectionKeys.Value;
     _appSettings        = appSettings.Value;
     _writebleSettingSvc = writableSiteWideSettings;
 }
        private async Task SaveDbKeysToRepositoryAsync()
        {
            var dbKeys = await DataProtectionKeys.GetFromDbAsync(_settings.ConnectionString);

            var newKeys = dbKeys.Except(Keys);

            foreach (var key in newKeys)
            {
                _keyRepository.StoreElement(key.Element, key.FriendlyName);
            }
        }
 public AuthenticateSvc(ApplicationDbContext db, UserManager <ApplicationUser> userManager,
                        IOptions <AppSettings> appsettingOptions, IOptions <DataProtectionKeys> dataprotectionKeyOption,
                        ICookieSvc cookieSvc, IActivitySvc activitySvc, IServiceProvider provider)
 {
     _userManager        = userManager;
     _dbContext          = db;
     _appSettings        = appsettingOptions.Value;
     _dataProtectionKeys = dataprotectionKeyOption.Value;
     _cookieSvc          = cookieSvc;
     _activitySvc        = activitySvc;
     _provider           = provider;
 }
示例#8
0
 public HomeController(IServiceProvider provider, IOptions <AppSettings> appSettings,
                       IOptions <DataProtectionKeys> dataProtectionKeys, ICookieSvc cookieSvc, IUserSvc userSvc,
                       ApplicationDbContext db)
 {
     _provider           = provider;
     _appSettings        = appSettings.Value;
     _dataProtectionKeys = dataProtectionKeys.Value;
     _cookieSvc          = cookieSvc;
     _userSvc            = userSvc;
     _db        = db;
     _dashBoard = new DashBoardModel();
 }
 public UserAuthenticationHandler(IOptionsMonitor <UserAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock,
                                  UserManager <ApplicationUser> userManager,
                                  IAuthSvc authSvc,
                                  IOptions <AppSettings> appSettings, IOptions <DataProtectionKeys> dataProtectionKeys,
                                  IServiceProvider provider) : base(options, logger, encoder, clock)
 {
     _userManager        = userManager;
     _appSettings        = appSettings.Value;
     _provider           = provider;
     _dataProtectionKeys = dataProtectionKeys.Value;
     _authSvc            = authSvc;
 }
        public ProfileController(
            ICookieService cookieService,
            IUserService userService,
            IServiceProvider provider,
            IOptions <DataProtectionKeys> dataProtectionKeys)

        {
            _userService        = userService;
            _cookieService      = cookieService;
            _provider           = provider;
            _dataProtectionKeys = dataProtectionKeys.Value;
        }
 public AuthService(UserManager <ApplicationUser> userManager,
                    IOptions <AppSettings> appSettings,
                    ApplicationDbContext db,
                    ICookieService cookieSvc, IServiceProvider provider, IOptions <DataProtectionKeys> dataProtectionKeys)
 {
     _userManager        = userManager;
     _appSettings        = appSettings.Value;
     _db                 = db;
     _cookieSvc          = cookieSvc;
     _provider           = provider;
     _dataProtectionKeys = dataProtectionKeys.Value;
 }
 public AccountController(IOptions <AppSettings> appSettings,
                          IServiceProvider provider,
                          ApplicationDbContext db,
                          IAccountService accountService,
                          ICookieService cookieService, IOptions <DataProtectionKeys> dataProtectionKeys)
 {
     _appSettings        = appSettings.Value;
     _provider           = provider;
     _db                 = db;
     _accountService     = accountService;
     _cookieService      = cookieService;
     _dataProtectionKeys = dataProtectionKeys.Value;
 }
        //private IDataProtector _protector;
        //private string[] UserRoles = new[] { "Administrator", "Customer" };
        //private TokenValidationParameters validationParameters;
        //private JwtSecurityTokenHandler handler;
        //private string unProtectedToken;
        //private ClaimsPrincipal validateToken;

        public AccountService(UserManager <ApplicationUserEntities> userManager,
                              IOptions <AppSettings> appSettings, IOptions <DataProtectionKeys> dataProtectionKeys,
                              ApplicationDbContext db,
                              ICookieService cookieService, IServiceProvider provider, IActivityService activityService)
        {
            _userManager        = userManager;
            _appSettings        = appSettings.Value;
            _dataProtectionKeys = dataProtectionKeys.Value;
            _db              = db;
            _cookieService   = cookieService;
            _provider        = provider;
            _activityService = activityService;
        }
示例#14
0
 public AdminSvc(UserManager <ApplicationUser> userManager,
                 IHttpContextAccessor httpContextAccessor,
                 IWebHostEnvironment env,
                 ApplicationDbContext db,
                 ICookieSvc cookieSvc, IActivitySvc activitySvc, IServiceProvider provider, IOptions <DataProtectionKeys> dataProtectionKeys, RoleManager <IdentityRole> roleManager)
 {
     _userManager        = userManager;
     _env                = env;
     _db                 = db;
     _cookieSvc          = cookieSvc;
     _activitySvc        = activitySvc;
     _dataProtectionKeys = dataProtectionKeys.Value;
     _provider           = provider;
     _roleManager        = roleManager;
 }
示例#15
0
 public UserService(UserManager <ApplicationUserEntities> userManager,
                    IHostingEnvironment env,
                    ApplicationDbContext db,
                    ICookieService cookieService,
                    IActivityService activityService,
                    IServiceProvider provider,
                    IOptions <DataProtectionKeys> dataProtectionKeys)
 {
     _userManager        = userManager;
     _env                = env;
     _db                 = db;
     _cookieService      = cookieService;
     _activityService    = activityService;
     _provider           = provider;
     _dataProtectionKeys = dataProtectionKeys.Value;
 }
示例#16
0
 public UserSvc(
     IServiceProvider provider,
     IActivitySvc activitySvc,
     ICookieSvc cookieSvc,
     ApplicationDbContext db,
     IOptions <DataProtectionKeys> dataProtectionKeys,
     IWebHostEnvironment env,
     UserManager <ApplicationUser> userManager)
 {
     _userManager        = userManager;
     _provider           = provider;
     _cookieSvc          = cookieSvc;
     _activitySvc        = activitySvc;
     _env                = env;
     _db                 = db;
     _dataProtectionKeys = dataProtectionKeys.Value;
 }
示例#17
0
 public UserSvc(
     UserManager <ApplicationUser> userManager,
     IHostingEnvironment env,
     ApplicationDbContext db,
     ICookieSvc cookieSvc,
     IActivitySvc activitySvc,
     IServiceProvider provider,
     IOptions <DataProtectionKeys> dataProtectionKeys,
     IHttpContextAccessor httpContextAccessor)
 {
     _userManager         = userManager;
     _env                 = env;
     _db                  = db;
     _cookieSvc           = cookieSvc;
     _activitySvc         = activitySvc;
     _dataProtectionKeys  = dataProtectionKeys.Value;
     _provider            = provider;
     _httpContextAccessor = httpContextAccessor;
 }