public static void Index() { RSS_DB_EF db = new RSS_DB_EF(); List <UserPlanModel> users = db.UserPlans.Where(p => p.expiryTime.Month == DateTime.Now.Month && p.expiryTime.Day == DateTime.Now.Day).ToList(); if (users != null) { db.UserPlans.RemoveRange(users); db.SaveChanges(); } List <FileModel> files = db.Files.Where(f => (f.sharingDuration.Month == DateTime.Now.Month && f.sharingDuration.Day == DateTime.Now.Day) || (f.fileDuration.Month == DateTime.Now.Month && f.fileDuration.Day == DateTime.Now.Day)).ToList(); if (files != null) { db.Files.RemoveRange(files); db.SaveChanges(); } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var identity = new ClaimsIdentity(context.Options.AuthenticationType); RSS_DB_EF db = new RSS_DB_EF(); string uname = context.Request.Headers.Get("Username"); string pass = context.Request.Headers.Get("Password"); if (uname == null || pass == null) { context.SetError("invalid_grant", "Sorry...Credentials are incorrect"); return; } TokenUserModel user = db.Tokens.Find(uname); if (user != null && pass == user.password) { if (user.type == "admin") { identity.AddClaim(new Claim(ClaimTypes.Role, "admin")); } else { identity.AddClaim(new Claim(ClaimTypes.Role, "user")); } identity.AddClaim(new Claim("username", user.username)); identity.AddClaim(new Claim(ClaimTypes.Name, user.name)); context.Validated(identity); } /*if(context.UserName=="mmr"&&context.Password=="MMR") * { * identity.AddClaim(new Claim(ClaimTypes.Role, "user")); * identity.AddClaim(new Claim("username", "mmr")); * identity.AddClaim(new Claim(ClaimTypes.Name, "Mayank")); * context.Validated(identity); * }*/ else { context.SetError("invalid_grant", "Sorry...Credentials are incorrect"); return; } }