Пример #1
0
        public async Task <IActionResult> Set([FromBody] GeneralSettingsPostModel model)
        {
            var isNew    = false;
            var settings = Db.GeneralSettings.FirstOrDefault();

            if (settings == null)
            {
                settings = new GeneralSettingsModel();
                isNew    = true;
            }

            if (!model.Password.IsEmpty())
            {
                if (model.CurrentPassword.IsEmpty() || !Hashing.CompareStringToHash(model.CurrentPassword, settings.PasswordHash))
                {
                    return(BadRequest(ErrorModel.BadRequest("invalid current password")));
                }

                settings.PasswordHash = Hashing.CreatePasswordHash(model.Password);
            }

            if (!model.DefaultRedirect.IsEmpty())
            {
                if (model.DefaultRedirect.Equals("__RESET__"))
                {
                    settings.DefaultRedirect = null;
                }
                else
                {
                    if (!await URIValidation.Validate(model.DefaultRedirect))
                    {
                        return(BadRequest(ErrorModel.BadRequest("invalid defautl redirect url")));
                    }
                    settings.DefaultRedirect = model.DefaultRedirect;
                }
            }

            if (isNew)
            {
                Db.GeneralSettings.Add(settings);
            }
            else
            {
                Db.GeneralSettings.Update(settings);
            }

            await Db.SaveChangesAsync();

            return(Ok(settings));
        }
Пример #2
0
 /// <summary>
 ///
 /// Returns if the set <i>RootURL</i> is
 /// a valid HTTP URI and requests to it
 /// returns a valid success response code.
 ///
 /// </summary>
 /// <returns>is valid state</returns>
 public async Task <bool> ValidateURI() =>
 await URIValidation.Validate(RootURL);