Improve the validation around the Application URL

pull/2478/head
Jamie Rees 7 years ago
parent 93b8f14c4d
commit e059b521dd

@ -279,4 +279,7 @@ export class SettingsService extends ServiceHelpers {
return this.http return this.http
.post<boolean>(`${this.url}/notifications/newsletter`, JSON.stringify(settings), {headers: this.headers}); .post<boolean>(`${this.url}/notifications/newsletter`, JSON.stringify(settings), {headers: this.headers});
} }
public verifyUrl(url: string): Observable<boolean> {
return this.http.post<boolean>(`${this.url}/customization/urlverify`, JSON.stringify({url}), {headers: this.headers});
}
} }

@ -43,13 +43,24 @@ export class CustomizationComponent implements OnInit {
} }
public save() { public save() {
this.settingsService.saveCustomization(this.settings).subscribe(x => {
if (x) { this.settingsService.verifyUrl(this.settings.applicationUrl).subscribe(x => {
this.notificationService.success("Successfully saved Ombi settings"); if(this.settings.applicationUrl) {
} else { if(!x) {
this.notificationService.success("There was an error when saving the Ombi settings"); this.notificationService.error(`The URL "${this.settings.applicationUrl}" is not valid. Please format it correctly e.g. http://www.google.com/`);
return;
}
} }
this.settingsService.saveCustomization(this.settings).subscribe(x => {
if (x) {
this.notificationService.success("Successfully saved Ombi settings");
} else {
this.notificationService.success("There was an error when saving the Ombi settings");
}
});
}); });
} }
public dropDownChange(event: any): void { public dropDownChange(event: any): void {

@ -39,16 +39,6 @@ namespace Ombi.Controllers
[Produces("application/json")] [Produces("application/json")]
public class SettingsController : Controller public class SettingsController : Controller
{ {
/// <summary>
/// Initializes a new instance of the <see cref="SettingsController" /> class.
/// </summary>
/// <param name="resolver">The resolver.</param>
/// <param name="mapper">The mapper.</param>
/// <param name="templateRepo">The templateRepo.</param>
/// <param name="embyApi">The embyApi.</param>
/// <param name="radarrSync">The radarrCacher.</param>
/// <param name="memCache">The memory cache.</param>
/// <param name="githubApi">The memory cache.</param>
public SettingsController(ISettingsResolver resolver, public SettingsController(ISettingsResolver resolver,
IMapper mapper, IMapper mapper,
INotificationTemplatesRepository templateRepo, INotificationTemplatesRepository templateRepo,
@ -228,6 +218,13 @@ namespace Ombi.Controllers
return await Save(settings); return await Save(settings);
} }
[ApiExplorerSettings(IgnoreApi = true)]
[HttpPost("customization/urlverify")]
public bool VerifyUrl([FromBody]UrlVerifyModel url)
{
return Uri.TryCreate(url.Url, UriKind.Absolute, out var __);
}
/// <summary> /// <summary>
/// Get's the preset themes available /// Get's the preset themes available
/// </summary> /// </summary>

@ -0,0 +1,7 @@
namespace Ombi.Models
{
public class UrlVerifyModel
{
public string Url { get; set; }
}
}
Loading…
Cancel
Save