public async System.Threading.Tasks.Task <bool> AuthorizeAsync(MonitoryContext context, HttpContext httpContext) { string username = httpContext.User.Identity.Name; var user = await context.Accounts.FirstOrDefaultAsync(u => u.Username == username); if (user.Role == "Administrator") { return(true); } return(false); }
public async Task <Account> UserAccountAsync(MonitoryContext context, HttpContext httpContext) { try { string username = httpContext.User.Identity.Name; var user = await context.Accounts.FirstOrDefaultAsync(u => u.Username == username); return(user); } catch (Exception e) { Console.WriteLine("Exception: " + e); return(null); } }
public static async Task <string> GetCurrentUserRoleAsync(string username) { string role = ""; using (var context = new MonitoryContext()) { account = await context.Accounts .FirstOrDefaultAsync(m => m.Username == username); } if (account != null) { role = account.Role; } return(role); }
public AccountController(MonitoryContext context) { _context = context; }
public LoginController(MonitoryContext context) { _context = context; }
public WebCheckController(MonitoryContext context) { _context = context; }