Ejemplo n.º 1
0
        public static void SeedClients(MigrationBuilder builder)
        {
            var clients = new[, ]
            {
                { "Ghost Admin", "d72bd484-af5f-46c0-8b0a-a9bc4943f141" },
                { "Ghost Frontend", "7d6afc6e-ff56-402b-9889-7d5a9542d3ce" },
                { "Ghost Scheduler", "3a7ceafa-bd95-4c05-a4fe-b54f13675d17" },
                { "Ghost Backup", "43e16bee-a378-4c66-9092-03ed538085ca" }
            };
            var clientsO = new object[4, 5];

            for (var i = 0; i < 4; i++)
            {
                clientsO[i, 0] = Guid.NewGuid().ToString("N");
                clientsO[i, 1] = clients[i, 0];
                clientsO[i, 2] = clients[i, 1];
                clientsO[i, 3] = Guid.NewGuid().ToString("N");
                clientsO[i, 4] = Slug.Slugify(clients[i, 0]);
            }
            builder.InsertData(
                "Clients",
                new[] { "Id", "Name", "Uuid", "Secret", "Slug" },
                clientsO
                );
        }
Ejemplo n.º 2
0
        public override void HandlebarsHelper(TextWriter output, dynamic context, params object[] arguments)
        {
            var navigationData = _dataContext.Settings.GetNavigationsAsync().Result;

            if (navigationData.Count == 0)
            {
                output.WriteSafeString(string.Empty);
            }
            else
            {
                var viewData = new
                {
                    navigation = navigationData.Cast(o => new NavigationViewModelItem()
                    {
                        current = IsCurrentUrl(o.Url),
                        label   = o.Label,
                        secure  = false,
                        slug    = Slug.Slugify(o.Url)
                    })
                };

                var viewHtml = _viewEngine.Value.RenderViewWithDataAsync(_template, viewData).Result;

                output.WriteSafeString(viewHtml);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Setup([FromBody] SetupPost setupDetails)
        {
            async Task <IActionResult> AssertSetupCompletedAsync(bool status)
            {
                var isSetup = await CheckSetupAsync();

                if (isSetup == status)
                {
                    return(Ok());
                }

                if (isSetup)
                {
                    return(new NoPermissionErrorResult(I18NService.Errors.Api.Authentication.SetupAlreadyCompleted));
                }
                else
                {
                    return(new NoPermissionErrorResult(I18NService.Errors.Api.Authentication.SetupMustBeCompleted));
                }
            }

            async Task <IActionResult> SetupTasksAsync(SetupPostItem setupData)
            {
                if (setupData.Password.Length < 10)
                {
                    return(new ValidationErrorResult(I18NService.Errors.Models.User.PasswordDoesNotComplyLength,
                                                     new Dictionary <string, string>()
                    {
                        { "minLength", "10" }
                    }));
                }

                _dataContext.Users.RemoveRange(_dataContext.Users);

                var ownerRole = await _dataContext.Roles.FirstAsync(r => r.Name == "Owner");

                var owner = new User()
                {
                    Name        = setupData.Name,
                    Slug        = Slug.Slugify(setupData.Name),
                    Email       = setupData.Email,
                    Status      = UserStatus.Active,
                    CreatedTime = DateTime.Now,
                    LastSeen    = DateTime.Now,
                    Password    = _passwordHasher.HashPassword(null, setupData.Password),
                };

                owner.UsersRoles.Add(new UserRole()
                {
                    Role = ownerRole, User = owner
                });

                var blogUpdate = new List <object>()
                {
                    new SettingItem()
                    {
                        Id    = Key.Title,
                        Value = setupData.BlogTitle.Trim()
                    },
                    new SettingItem()
                    {
                        Id    = Key.Description,
                        Value = I18NService.Common.Api.Authentication.SampleBlogDescription
                    }
                };

                await _dataContext.Users.AddAsync(owner);

                _dataContext.UpdateRange(blogUpdate);

                await _dataContext.SaveChangesAsync();

                return(Ok());
            }

            async Task <IActionResult> DoSettingsAsync()
            {
                var json = JObject.FromObject(await _dataContext.Users.FirstAsync(r => true), new JsonSerializer()
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });

                json.Remove("roles");

                return(new JsonResult(json));
            }

            var data = setupDetails.Setup[0];

            var tResult = await AssertSetupCompletedAsync(false);

            if (!(tResult is OkResult))
            {
                return(tResult);
            }

            tResult = await SetupTasksAsync(data);

            if (!(tResult is OkResult))
            {
                return(tResult);
            }

            return(await DoSettingsAsync());
        }