/// <summary> /// Checks if the given details validate /// </summary> /// <param name="auth"></param> /// <param name="db"></param> /// <returns>User obj if allowed, otherwise null</returns> protected async Task<User> AuthenticateUser(AuthenticationModel auth, CrowdContext db) { if (auth == null) return null; User found = await db.Users.FindAsync(auth.Email); if (found != null && found.Key == auth.Key) { User.AppType app; if (Enum.TryParse(auth.App, true, out app)) { if (app != found.App) { found.App = app; await db.SaveChangesAsync(); } } return found; } return null; }
protected async Task<ServiceUser> AuthenticateServiceUser(AuthenticationModel auth, CrowdContext db) { User rawUser = await AuthenticateUser(auth, db); return rawUser == null ? null : new ServiceUser(rawUser); }