private async Task CacheAccessInfoAsync(ILoginUow loginUow, int userId) { var userRoles = loginUow.Repository <UserRole>().FindBy(t => t.UserId == userId); var rolePermissions = new List <RolePermission>(); foreach (var userRole in userRoles) { var permissions = await loginUow.Repository <RolePermission>().FindByAsync(t => t.RoleId == userRole.RoleId); rolePermissions.AddRange(permissions); } var userAccess = rolePermissions.OrderBy(t => t.PermissionPriority); var moduleAccess = new Dictionary <int, Dictionary <string, bool> >(); foreach (var access in userAccess) { var actionAccess = new Dictionary <string, bool>(); actionAccess.Add(GET, access.CanView == true); actionAccess.Add(POST, access.CanAdd == true); actionAccess.Add(PUT, access.CanEdit == true); actionAccess.Add(PATCH, access.CanEdit == true); actionAccess.Add(DELETE, access.CanDelete == true); moduleAccess.Add(access.ApplicationModuleId, actionAccess); } this.SaveAccessInfo(userId, moduleAccess); }
public async Task RemoveTokenAsync(int userId, string audience, ILoginUow loginUow) { var applicationUserTokens = await loginUow.Repository <ApplicationUserToken>().FindByAsync(t => t.UserId == userId && t.AudienceType == audience); foreach (var applicationUserToken in applicationUserTokens) { await loginUow.RegisterDeletedAsync <ApplicationUserToken>(applicationUserToken); string token; this.Tokens.TryRemove(applicationUserToken.SecurityKey, out token); } await loginUow.CommitAsync(); }
public async Task <string> GetTokenAsync(string securityKey, ILoginUow loginUow) { string token; if (!this.Tokens.TryGetValue(securityKey, out token)) { var applicationUserToken = await loginUow.Repository <ApplicationUserToken>().SingleOrDefaultAsync(t => t.SecurityKey == securityKey); if (applicationUserToken != null) { this.Tokens.AddOrUpdate(applicationUserToken.SecurityKey, applicationUserToken.JwtToken, (x, y) => applicationUserToken.JwtToken); } return(applicationUserToken == null ? string.Empty : applicationUserToken.JwtToken); } return(token); }