Beispiel #1
0
        public static async Task CookieSignin(CookieSigningInContext context)
        {
            UserManager <Models.ApplicationUser>   userManager   = context.HttpContext.RequestServices.GetRequiredService <UserManager <Models.ApplicationUser> >();
            SignInManager <Models.ApplicationUser> signinManager = context.HttpContext.RequestServices.GetRequiredService <SignInManager <Models.ApplicationUser> >();
            RoleManager <IdentityRole>             roleManager   = context.HttpContext.RequestServices.GetRequiredService <RoleManager <IdentityRole> >();
            ILoggerFactory logger = context.HttpContext.RequestServices.GetRequiredService <ILoggerFactory>();
            IMemoryCache   cache  = context.HttpContext.RequestServices.GetRequiredService <IMemoryCache>();

            Utilities.IAuthUtils authutils = context.HttpContext.RequestServices.GetRequiredService <Utilities.IAuthUtils>();
            RedditSharp.RefreshTokenWebAgentPool agentPool = context.HttpContext.RequestServices.GetRequiredService <RedditSharp.RefreshTokenWebAgentPool>();
            await agentPool.RemoveWebAgentAsync(context.Principal.Identity.Name);

            var user = await userManager.FindByNameAsync(context.Principal.Identity.Name);

            await authutils.UpdateModeratedSubredditsAsync(user);

            user = await userManager.FindByNameAsync(context.Principal.Identity.Name);

            var newPrincipal = await signinManager.CreateUserPrincipalAsync(user);

            if (user.HasWiki)
            {
                ((ClaimsIdentity)newPrincipal.Identity).AddClaim(new Claim("uri:snoonotes:haswiki", "true"));
            }
            if (user.HasConfig)
            {
                ((ClaimsIdentity)newPrincipal.Identity).AddClaim(new Claim("uri:snoonotes:hasconfig", "true"));
            }

            ((ClaimsIdentity)newPrincipal.Identity).AddClaim(new Claim("lastupdated", DateTime.UtcNow.ToString()));

            context.Principal = newPrincipal;
        }
 public ToolBoxNotesController(UserManager <ApplicationUser> userManager, DAL.INoteTypesDAL noteTypesDAL, Utilities.IAuthUtils authUtils, RedditSharp.RefreshTokenWebAgentPool agentPool, BLL.IToolBoxNotesBLL tbNotesBLL)
 {
     this.userManager  = userManager;
     this.authUtils    = authUtils;
     this.agentPool    = agentPool;
     this.noteTypesDAL = noteTypesDAL;
     this.tbNotesBLL   = tbNotesBLL;
 }
Beispiel #3
0
 public BotBanBLL(DAL.IBotBanDAL botBanDAL, UserManager <ApplicationUser> userManager, Utilities.IAuthUtils authUtils, DAL.IYouTubeDAL youtubeDAL, RedditSharp.RefreshTokenWebAgentPool agentPool)
 {
     bbDAL            = botBanDAL;
     this.userManager = userManager;
     this.authUtils   = authUtils;
     ytDAL            = youtubeDAL;
     this.agentPool   = agentPool;
 }
Beispiel #4
0
 //private Utilities.AuthUtils authUtils;
 public SubredditBLL(IMemoryCache memoryCache, DAL.ISubredditDAL subredditDAL, UserManager <ApplicationUser> userManager,
                     DAL.INoteTypesDAL noteTypesDAL, RoleManager <IdentityRole> roleManager, Utilities.IAuthUtils authUtils)
 {
     subDAL         = subredditDAL;
     cache          = memoryCache;
     ntDAL          = noteTypesDAL;
     _roleManager   = roleManager;
     this.authUtils = authUtils;
 }
 public AccountController(UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager,
                          ILoggerFactory loggerFactory, BLL.ISubredditBLL subredditBLL, Utilities.IAuthUtils authUtils,
                          IMemoryCache memoryCache, RoleManager <IdentityRole> roleManager, RedditSharp.RefreshTokenWebAgentPool agentPool, RedditSharp.WebAgentPool <string, RedditSharp.BotWebAgent> serviceAgentPool, IConfigurationRoot configRoot)
 {
     subBLL                = subredditBLL;
     _userManager          = userManager;
     _signInManager        = signInManager;
     _logger               = loggerFactory.CreateLogger <AccountController>();
     this.authUtils        = authUtils;
     this.agentPool        = agentPool;
     this.serviceAgentPool = serviceAgentPool;
     Configuration         = configRoot;
 }
Beispiel #6
0
        public static async Task ValidateAsync(CookieValidatePrincipalContext context)
        {
            string lastUpdated = context.Principal.Claims.FirstOrDefault(c => c.Type == "lastupdated")?.Value;

            if (lastUpdated == null)
            {
                ((ClaimsIdentity)context.Principal.Identity).AddClaim(new Claim("lastupdated", DateTime.UtcNow.ToString()));
                context.ShouldRenew = true;
            }
            else if (DateTime.Parse(lastUpdated).AddHours(1) < DateTime.UtcNow)
            {
                //IConfigurationRoot config = context.HttpContext.RequestServices.GetRequiredService<IConfigurationRoot>();
                UserManager <Models.ApplicationUser>   userManager   = context.HttpContext.RequestServices.GetRequiredService <UserManager <Models.ApplicationUser> >();
                SignInManager <Models.ApplicationUser> signinManager = context.HttpContext.RequestServices.GetRequiredService <SignInManager <Models.ApplicationUser> >();
                RoleManager <IdentityRole>             roleManager   = context.HttpContext.RequestServices.GetRequiredService <RoleManager <IdentityRole> >();
                ILoggerFactory       logger    = context.HttpContext.RequestServices.GetRequiredService <ILoggerFactory>();
                IMemoryCache         cache     = context.HttpContext.RequestServices.GetRequiredService <IMemoryCache>();
                Utilities.IAuthUtils authutils = context.HttpContext.RequestServices.GetRequiredService <Utilities.IAuthUtils>();
                var user = await userManager.FindByNameAsync(context.Principal.Identity.Name);

                await authutils.UpdateModeratedSubredditsAsync(user);

                user = await userManager.FindByNameAsync(context.Principal.Identity.Name);

                var newPrincipal = await signinManager.CreateUserPrincipalAsync(user);

                if (user.HasWiki)
                {
                    ((ClaimsIdentity)newPrincipal.Identity).AddClaim(new Claim("uri:snoonotes:haswiki", "true"));
                }
                if (user.HasConfig)
                {
                    ((ClaimsIdentity)newPrincipal.Identity).AddClaim(new Claim("uri:snoonotes:hasconfig", "true"));
                }
                ((ClaimsIdentity)newPrincipal.Identity).AddClaim(new Claim("lastupdated", DateTime.UtcNow.ToString()));
                context.ReplacePrincipal(newPrincipal);
                context.ShouldRenew = true;
            }
        }