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);
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
        }
Example #4
0
 public AccountController(MonitoryContext context)
 {
     _context = context;
 }
 public LoginController(MonitoryContext context)
 {
     _context = context;
 }
Example #6
0
 public WebCheckController(MonitoryContext context)
 {
     _context = context;
 }