public async Task <bool> SaveSettings(Models.DirtbagSettings settings, string subName) { await subDAL.UpdateBotSettings(settings, subName); cache.Set(CACHE_PREFIX + subName, settings, DateTimeOffset.Now.AddMinutes(30)); return(true); }
public async Task <bool> TestConnection(Models.DirtbagSettings settings, string subname) { if (!User.HasClaim("uri:snoonotes:admin", subname.ToLower())) { throw new UnauthorizedAccessException("You are not an admin of this subreddit!"); } if (!settings.DirtbagUrl.EndsWith("/")) { settings.DirtbagUrl = settings.DirtbagUrl + "/"; } return(await dirtbag.TestConnection(settings, subname)); }
public async Task <Models.DirtbagSettings> Update(Models.DirtbagSettings settings, string subname) { if (!ClaimsPrincipal.Current.HasClaim($"urn:snoonotes:subreddits:{subname.ToLower()}:admin", "true")) { throw new UnauthorizedAccessException("You are not an admin of this subreddit!"); } if (!settings.DirtbagUrl.EndsWith("/")) { settings.DirtbagUrl = settings.DirtbagUrl + "/"; } BLL.DirtbagBLL dirtbag = new BLL.DirtbagBLL(); await dirtbag.SaveSettings(settings, subname); return(settings); }
public async Task <bool> TestConnection(Models.DirtbagSettings settings, string subname) { if (!ClaimsPrincipal.Current.HasClaim($"urn:snoonotes:subreddits:{subname.ToLower()}:admin", "true")) { throw new UnauthorizedAccessException("You are not an admin of this subreddit!"); } if (!settings.DirtbagUrl.EndsWith("/")) { settings.DirtbagUrl = settings.DirtbagUrl + "/"; } BLL.DirtbagBLL dirtbag = new BLL.DirtbagBLL(); try { return(await dirtbag.TestConnection(settings, subname)); } catch (HttpRequestException ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.GetBaseException().Message)); } }
public async Task <bool> TestConnection(Models.DirtbagSettings newSettings, string subName) { Models.DirtbagSettings curSettings = await GetSettings(subName); if (curSettings == null || curSettings.DirtbagUrl != newSettings.DirtbagUrl) { //no current settings OR url changed, don't allow using saved password. return(await dirtbag.TestConnection(newSettings, subName)); } else if (string.IsNullOrWhiteSpace(newSettings.DirtbagPassword)) { //url did NOT change, and password wasn't updated return(await dirtbag.TestConnection(curSettings.DirtbagUrl, newSettings.DirtbagUsername, curSettings.DirtbagPassword, subName)); } else { return(await dirtbag.TestConnection(newSettings, subName)); } }