예제 #1
0
        private async Task <SaveWizardResult> SaveWizardUser(CreateUserWizardModel user, OmbiUser userToCreate, bool completeWizard)
        {
            IdentityResult result;
            var            retVal = new SaveWizardResult();

            // When creating the admin as the plex user, we do not pass in the password.
            if (user.Password.HasValue())
            {
                result = await UserManager.CreateAsync(userToCreate, user.Password);
            }
            else
            {
                result = await UserManager.CreateAsync(userToCreate);
            }
            if (result.Succeeded)
            {
                _log.LogInformation("Created User {0}", userToCreate.UserName);
                await CreateRoles();

                _log.LogInformation("Created the roles");
                var roleResult = await UserManager.AddToRoleAsync(userToCreate, OmbiRoles.Admin);

                if (!roleResult.Succeeded)
                {
                    LogErrors(roleResult);
                }
                else
                {
                    _log.LogInformation("Added the Admin role");
                }

                if (completeWizard)
                {
                    // Update the wizard flag
                    var settings = await OmbiSettings.GetSettingsAsync();

                    settings.Wizard = true;
                    await OmbiSettings.SaveSettingsAsync(settings);
                }
            }
            if (!result.Succeeded)
            {
                LogErrors(result);
                retVal.Errors.AddRange(result.Errors.Select(x => x.Description));
            }

            retVal.Result = result.Succeeded;
            return(retVal);
        }