public async Task <IActionResult> PostDataAsync(string id, string key, ValueFromBody <string> value)
        {
            if (String.IsNullOrWhiteSpace(key) || String.IsNullOrWhiteSpace(value?.Value) || key.StartsWith("-"))
            {
                return(BadRequest());
            }

            var project = await GetModelAsync(id, false);

            if (project == null)
            {
                return(NotFound());
            }

            project.Data[key.Trim()] = value.Value.Trim();
            await _repository.SaveAsync(project, o => o.Cache());

            return(Ok());
        }
        public async Task <IActionResult> SetConfigAsync(string id, string key, ValueFromBody <string> value)
        {
            if (String.IsNullOrWhiteSpace(key) || String.IsNullOrWhiteSpace(value?.Value))
            {
                return(BadRequest());
            }

            var project = await GetModelAsync(id, false);

            if (project == null)
            {
                return(NotFound());
            }

            project.Configuration.Settings[key.Trim()] = value.Value.Trim();
            project.Configuration.IncrementVersion();
            await _repository.SaveAsync(project, o => o.Cache());

            return(Ok());
        }
示例#3
0
    public async Task <IActionResult> RemoveLinkAsync(string id, ValueFromBody <string> url)
    {
        if (String.IsNullOrWhiteSpace(url?.Value))
        {
            return(BadRequest());
        }

        var stack = await GetModelAsync(id, false);

        if (stack == null)
        {
            return(NotFound());
        }

        if (stack.References.Contains(url.Value.Trim()))
        {
            stack.References.Remove(url.Value.Trim());
            await _stackRepository.SaveAsync(stack);
        }

        return(StatusCode(StatusCodes.Status204NoContent));
    }
        public async Task <ActionResult <SystemNotification> > PostSystemNotificationAsync(ValueFromBody <string> message)
        {
            if (String.IsNullOrWhiteSpace(message?.Value))
            {
                return(NotFound());
            }

            var notification = new SystemNotification {
                Date = SystemClock.UtcNow, Message = message.Value
            };
            await _cacheClient.SetAsync("system-notification", notification);

            await _messagePublisher.PublishAsync(notification);

            return(Ok(notification));
        }
        public async Task <ActionResult <ReleaseNotification> > PostReleaseNotificationAsync(ValueFromBody <string> message, bool critical = false)
        {
            var notification = new ReleaseNotification {
                Critical = critical, Date = SystemClock.UtcNow, Message = message?.Value
            };
            await _messagePublisher.PublishAsync(notification);

            return(Ok(notification));
        }
        public async Task <ActionResult <TokenResult> > RemoveExternalLoginAsync(string providerName, ValueFromBody <string> providerUserId)
        {
            using (_logger.BeginScope(new ExceptionlessState().Tag("External Login").Tag(providerName).Identity(CurrentUser.EmailAddress).Property("User", CurrentUser).Property("Provider User Id", providerUserId?.Value).SetHttpContext(HttpContext))) {
                if (String.IsNullOrWhiteSpace(providerName) || String.IsNullOrWhiteSpace(providerUserId?.Value))
                {
                    _logger.LogError("Remove external login failed for {EmailAddress}: Invalid Provider Name or Provider User Id.", CurrentUser.EmailAddress);
                    return(BadRequest("Invalid Provider Name or Provider User Id."));
                }

                if (CurrentUser.OAuthAccounts.Count <= 1 && String.IsNullOrEmpty(CurrentUser.Password))
                {
                    _logger.LogError("Remove external login failed for {EmailAddress}: You must set a local password before removing your external login.", CurrentUser.EmailAddress);
                    return(BadRequest("You must set a local password before removing your external login."));
                }

                try {
                    if (CurrentUser.RemoveOAuthAccount(providerName, providerUserId.Value))
                    {
                        await _userRepository.SaveAsync(CurrentUser, o => o.Cache());
                    }
                } catch (Exception ex) {
                    _logger.LogCritical(ex, "Error removing external login for {EmailAddress}: {Message}", CurrentUser.EmailAddress, ex.Message);
                    throw;
                }

                await ResetUserTokensAsync(CurrentUser, nameof(RemoveExternalLoginAsync));

                _logger.LogInformation("{EmailAddress} removed an external login: {ProviderName}", CurrentUser.EmailAddress, providerName);
                return(Ok(new TokenResult {
                    Token = await GetOrCreateAccessTokenAsync(CurrentUser)
                }));
            }
        }