public static async Task SetUserActiveAsync(SGContext context, LoginToken token, string email, bool active) { var role = new UserRole(token.User.RawRole); if (role.IsAdmin) { var user = await QuickGetUserNoAuthCheckAsync(context, email); if (user != null) { user.Active = active; context.users.Update(user); await context.SaveChangesAsync(); if (!active) { await LoginTokenTasks.RemoveExistingTokenForUser(context, user.Id); } } else { throw new Exception($"User {email} not found"); } } else { throw new Exception("Unauthorised"); } }
public async static Task <bool> IsAdmin(this LoginToken token, SGContext context) { if (context == null || token.Expires < DateTime.UtcNow) { return(false); } token = await LoginTokenTasks.GetLoginTokenAsync(context, token.Id); if (token != null) { var role = new UserRole(token.User.RawRole); return(role.IsAdmin); } return(false); }