Improve the validation around the Application URL

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

@ -279,4 +279,7 @@ export class SettingsService extends ServiceHelpers {
return this.http
.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() {
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");
this.settingsService.verifyUrl(this.settings.applicationUrl).subscribe(x => {
if(this.settings.applicationUrl) {
if(!x) {
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 {

@ -39,16 +39,6 @@ namespace Ombi.Controllers
[Produces("application/json")]
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,
IMapper mapper,
INotificationTemplatesRepository templateRepo,
@ -228,6 +218,13 @@ namespace Ombi.Controllers
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>
/// Get's the preset themes available
/// </summary>

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