public CeresSettings EnsureDefaultCeresSettings(string userID) { var key = CeresSettings.GetKey(userID); CeresSettings ceresSettings; try { ceresSettings = this.redis.Get <CeresSettings>(key); } catch (System.Runtime.Serialization.SerializationException) { this.redis.Delete(key); ceresSettings = null; } if (ceresSettings == null) { ceresSettings = new CeresSettings { ceresConfiguration = new Common.Models.CeresConfiguration { ceresEnabled = false, numberOfSecondsToGuess = 45, staticRewards = new List <Common.Models.CeresConfiguration.StaticReward> { new Common.Models.CeresConfiguration.StaticReward(0, 0, 1000), new Common.Models.CeresConfiguration.StaticReward(1, 2, 500), new Common.Models.CeresConfiguration.StaticReward(3, 4, 100), }, closestRewards = new List <Common.Models.CeresConfiguration.ClosestReward> { new Common.Models.CeresConfiguration.ClosestReward(1, 100, false), new Common.Models.CeresConfiguration.ClosestReward(2, 50, false), new Common.Models.CeresConfiguration.ClosestReward(3, 10, false), }, magicTimes = new List <Common.Models.CeresConfiguration.MagicTime> { new Common.Models.CeresConfiguration.MagicTime { ceresTime = 4700, pointsAwarded = 10000, }, new Common.Models.CeresConfiguration.MagicTime { ceresTime = 4600, pointsAwarded = 1000, }, } }, userID = userID, }; this.redis.Set(key, ceresSettings); } return(ceresSettings); }
public ActionResult Update( [FromBody] CeresSettings settings ) { try { if (settings == null) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, $"{nameof(settings)} is null")); } if (string.IsNullOrWhiteSpace(settings.userID)) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, $"{nameof(settings.userID)} is null")); } var userInfo = this.authenticationProvider.Authenticate(this.HttpContext); if (userInfo.Result != Constants.AuthenticationResult.Success) { return(StatusCode((int)System.Net.HttpStatusCode.Unauthorized, $"Could not authenticate")); } if (this.appSettings.TwitchClientID != userInfo.GetClientID()) { return(StatusCode((int)System.Net.HttpStatusCode.Unauthorized, $"{nameof(this.appSettings.TwitchClientID)} does not match")); } if (settings.userID != userInfo.GetUserID()) { return(StatusCode((int)System.Net.HttpStatusCode.Unauthorized, $"{nameof(settings.userID)} is not yours")); } var validationResult = settings.validate(); if (validationResult != System.ComponentModel.DataAnnotations.ValidationResult.Success) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, new { message = validationResult.ErrorMessage })); } this.userHelper.SaveSettings(settings); Startup.chatBotManager.UpdateConnection(userInfo.GetUserID(), settings.ceresConfiguration); return(Json(settings)); } catch (Exception exc) { this._logger.LogError(ExceptionFormatter.FormatException(exc, $"Exception in {this.GetType().Name} - {System.Reflection.MethodBase.GetCurrentMethod().Name}")); return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError)); } }
public void SaveSettings(CeresSettings toSave) { this.redis.Set(toSave.GetKey(), toSave); }