public async Task <object> CreateAsync( [FromServices] GoogleRecaptchaService recaptchaService, [FromServices] UserAccountService userAccountService, [FromBody] CreateUserRequest body) { var remoteIp = HttpContext.Connection.RemoteIpAddress.ToString(); if (!await recaptchaService.ValidateAsync(remoteIp, body.Captcha).ConfigureAwait(false)) { return(BadRequest(JResponse.Error("reCAPTCHA validation failed."))); } if (!await userAccountService.IsNameAvailabilityAsync(body.Username)) { return(BadRequest(JResponse.Error("User name already taken."))); } if (!await userAccountService.IsEmailAvailabilityAsync(body.Email)) { return(BadRequest(JResponse.Error("Email address already registered."))); } await userAccountService.CreateAccountAsync(body.Username, body.Email, body.Password); return(JResponse.OK()); }
public async Task <IJResponse> AdvertiseHeartbeatAsync( [FromServices] IServerRepository serverRepository, [FromBody] JAdvertiseHeartbeatRequest body) { if (string.IsNullOrEmpty(body?.Token)) { return(ConvertResponse(JResponse.Error(JErrorMessages.InvalidToken))); } Server server = await serverRepository.GetByTokenAsync(body.Token); if (server == null) { return(ConvertResponse(JResponse.Error(JErrorMessages.ServerNotRegistered))); } server.Players = body.Players; server.GameInfo = body.GameInfo; server.LastHeartbeat = DateTime.Now; await serverRepository.AddOrUpdateAsync(server); return(ConvertResponse(JResponse.OK())); }
public async Task <IJResponse> Logout( [FromServices] IUserSessionRepository userSessionRepository, [FromBody] JLogoutRequest body) { try { Guard.ArgumentNotNull(body); Guard.ArgumentNotNull(body.token); } catch { return(JResponse.Error(JErrorMessages.InvalidRequest)); } if (await userSessionRepository.RevokeToken(body.token)) { return(JResponse.OK()); } else { return(JResponse.Error(JErrorMessages.InvalidToken)); } }
public Task <IJResponse> ProfileUpdate( [FromBody] JProfileUpdateRequest body) { return(Task.FromResult <IJResponse>(JResponse.OK())); }