/// <summary> /// Returns a planetuser given the user and planet id /// </summary> public async Task <TaskResult <PlanetUser> > GetPlanetUser(ulong userid, ulong planet_id, string auth) { // Retrieve planet ServerPlanet planet = ServerPlanet.FromBase(await Context.Planets.FindAsync(planet_id), Mapper); if (planet == null) { return(new TaskResult <PlanetUser>(false, "The planet could not be found.", null)); } // Authentication flow AuthToken token = await Context.AuthTokens.FindAsync(auth); // If authorizor is not a member of the planet, they do not have authority to get member info if (token == null || !(await planet.IsMemberAsync(token.User_Id))) { return(new TaskResult <PlanetUser>(false, "Failed to authorize.", null)); } // At this point the request is authorized // Retrieve server data for user User user = await Context.Users.FindAsync(userid); // Null check if (user == null) { return(new TaskResult <PlanetUser>(false, "The user could not be found.", null)); } // Ensure the user is a member of the planet if (!(await planet.IsMemberAsync(user))) { return(new TaskResult <PlanetUser>(false, "The target user is not a member of the planet.", null)); } PlanetUser planetUser = await ServerPlanetUser.CreateAsync(userid, planet_id, Mapper); if (planetUser == null) { return(new TaskResult <PlanetUser>(false, "Could not create planet user: Fatal error.", null)); } return(new TaskResult <PlanetUser>(true, "Successfully retrieved planet user.", planetUser)); }
/// <summary> /// Returns the client version from the base /// </summary> public static ClientPlanetUser FromBase(PlanetUser planetuser, IMapper mapper) { return(mapper.Map <ClientPlanetUser>(planetuser)); }
/// <summary> /// Creates a PlanetUser instance using a user and planet /// </summary> public static async Task <ServerPlanetUser> CreateAsync(User user, PlanetUser planet, IMapper mapper) { return(await CreateAsync(user.Id, planet.Id, mapper)); }
/// <summary> /// Returns a ServerPlanet using a Planet as a base /// </summary> public static ServerPlanetUser FromBase(PlanetUser planetuser, IMapper mapper) { return(mapper.Map <ServerPlanetUser>(planetuser)); }